Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ public static void checkPdxPackagePathOperand(
*
* @param locatorHost Locator's host address
* @param locatorPort Locator's port
* @param autoSerializerPackagePath package name of the Domain classes loaded in the regions
* @param autoSerializerPackagePath package name of the Domain classes loaded in the regions,
* or null to register no class pattern
* @return Returns a Geode {@link ClientCache} instance connected to Geode cluster
*/
public static synchronized ClientCache createClientCache(String locatorHost,
int locatorPort, String autoSerializerPackagePath,
int locatorPort, @Nullable String autoSerializerPackagePath,
boolean readSerialized) {
if (locatorPort != currentLocatorPort
|| !equalsIgnoreCase(currentLocatorHost, locatorHost)) {
Expand All @@ -124,7 +125,10 @@ public static synchronized ClientCache createClientCache(String locatorHost,

return new ClientCacheFactory()
.addPoolLocator(locatorHost, locatorPort)
.setPdxSerializer(new ReflectionBasedAutoSerializer(autoSerializerPackagePath))
.setPdxSerializer(
autoSerializerPackagePath == null
? new ReflectionBasedAutoSerializer()
: new ReflectionBasedAutoSerializer(autoSerializerPackagePath))
.setPdxReadSerialized(readSerialized)
.create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.calcite.adapter.geode.rel;

import org.apache.calcite.adapter.geode.simple.GeodeSimpleSchema;
import org.apache.calcite.adapter.geode.simple.GeodeSimpleSchemaFactory;
import org.apache.calcite.adapter.geode.util.GeodeUtils;
import org.apache.calcite.config.CalciteSystemProperty;
Expand All @@ -30,6 +31,7 @@
import java.util.Map;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -40,6 +42,7 @@
* Verifies that the {@code pdxSerializablePackagePath} operand is disabled by
* default in both Geode schema factories, and enabled only when the
* {@code calcite.geode.pdxSerializablePackagePath.allowed} system property is set.
* Without the operand, both factories create the schema.
*
* <p>Marked {@link Isolated} because one test toggles the JVM-wide cached value
* of {@link CalciteSystemProperty#GEODE_PDX_PACKAGE_PATH_ALLOWED}.
Expand Down Expand Up @@ -110,6 +113,34 @@ private static AutoCloseable overrideGeodePdxPackagePathAllowed() {
}
}

/** Returns an operand without {@code pdxSerializablePackagePath}, as the
* default configuration has it. */
private static Map<String, Object> operandWithoutPdxPackagePath() {
final Map<String, Object> operand = operand();
operand.remove(GeodeSchemaFactory.PDX_SERIALIZABLE_PACKAGE_PATH);
return operand;
}

/** A factory creates the schema, with a new client cache, from an operand
* without {@code pdxSerializablePackagePath}, which is how the operand
* arrives unless it is explicitly allowed. Creating the cache used to fail
* with NullPointerException inside Geode's ReflectionBasedAutoSerializer. */
@Test void testPdxPackagePathOperandAbsentCreatesSchema() {
GeodeUtils.closeClientCache();
assertThat(
new GeodeSchemaFactory().create(rootSchema(), "geode",
operandWithoutPdxPackagePath()),
instanceOf(GeodeSchema.class));
}

@Test void testSimpleFactoryPdxPackagePathOperandAbsentCreatesSchema() {
GeodeUtils.closeClientCache();
assertThat(
new GeodeSimpleSchemaFactory().create(rootSchema(), "geode",
operandWithoutPdxPackagePath()),
instanceOf(GeodeSimpleSchema.class));
}

/** A null operand is always accepted, independent of the opt-in property. */
@Test void testPdxPackagePathOperandNullIsAlwaysAccepted() {
assertDoesNotThrow(() -> GeodeUtils.checkPdxPackagePathOperand(null));
Expand Down
Loading