Search in sources :

Example 31 with SerializationConfig

use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.

the class SerializerHookLoaderTest method testLoad_withParametrizedConstructorAndCompatibilitySwitchOn.

@Test
public void testLoad_withParametrizedConstructorAndCompatibilitySwitchOn() {
    String propName = "hazelcast.compat.serializers.use.default.constructor.only";
    String origProperty = System.getProperty(propName);
    try {
        System.setProperty(propName, "true");
        SerializerConfig serializerConfig = new SerializerConfig();
        serializerConfig.setClassName("com.hazelcast.internal.serialization.impl.TestSerializerHook$TestSerializerWithTypeConstructor");
        serializerConfig.setTypeClassName("com.hazelcast.internal.serialization.impl.SampleIdentifiedDataSerializable");
        SerializationConfig serializationConfig = getConfig().getSerializationConfig();
        serializationConfig.addSerializerConfig(serializerConfig);
        SerializerHookLoader hook = new SerializerHookLoader(serializationConfig, classLoader);
        Map<Class, Object> serializers = hook.getSerializers();
        TestSerializerHook.TestSerializerWithTypeConstructor serializer = (TestSerializerHook.TestSerializerWithTypeConstructor) serializers.get(SampleIdentifiedDataSerializable.class);
        assertNull(serializer.getClazz());
    } finally {
        if (origProperty != null) {
            System.setProperty(propName, origProperty);
        } else {
            System.clearProperty(propName);
        }
    }
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 32 with SerializationConfig

use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.

the class AbstractGenericRecordIntegrationTest method testPutWithoutFactory_readAsGenericRecord.

@Test
public void testPutWithoutFactory_readAsGenericRecord() {
    MainPortable expectedPortable = createMainPortable();
    GenericRecord expected = createGenericRecord(expectedPortable);
    assertEquals(expectedPortable.c, expected.getChar("c"));
    assertEquals(expectedPortable.f, expected.getFloat32("f"), 0.1);
    HazelcastInstance[] instances = createCluster();
    IMap<Object, Object> clusterMap = instances[0].getMap("test");
    clusterMap.put(1, expected);
    HazelcastInstance instance = createAccessorInstance(new SerializationConfig());
    IMap<Object, Object> map = instance.getMap("test");
    GenericRecord actual = (GenericRecord) map.get(1);
    assertEquals(expected, actual);
}
Also used : MainPortable(com.hazelcast.internal.serialization.impl.portable.MainPortable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) Test(org.junit.Test)

Example 33 with SerializationConfig

use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.

the class AbstractGenericRecordIntegrationTest method testEntryProcessorReturnsGenericRecord.

@Test
public void testEntryProcessorReturnsGenericRecord() {
    HazelcastInstance[] instances = createCluster();
    HazelcastInstance instance = createAccessorInstance(serializationConfig);
    IMap<Object, Object> map = instance.getMap("test");
    NamedPortable expected = new NamedPortable("foo", 900);
    String key = generateKeyOwnedBy(instances[0]);
    map.put(key, expected);
    Object returnValue = map.executeOnKey(key, (EntryProcessor<Object, Object, Object>) entry -> {
        Object value = entry.getValue();
        GenericRecord genericRecord = (GenericRecord) value;
        GenericRecord modifiedGenericRecord = genericRecord.newBuilder().setString("name", "bar").setInt32("myint", 4).build();
        entry.setValue(modifiedGenericRecord);
        return genericRecord.getInt32("myint");
    });
    assertEquals(expected.myint, returnValue);
    NamedPortable actualPortable = (NamedPortable) map.get(key);
    assertEquals("bar", actualPortable.name);
    assertEquals(4, actualPortable.myint);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) TestSerializationConstants(com.hazelcast.internal.serialization.impl.TestSerializationConstants) LocalDateTime(java.time.LocalDateTime) Callable(java.util.concurrent.Callable) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) SerializationConfig(com.hazelcast.config.SerializationConfig) Json(com.hazelcast.internal.json.Json) BigDecimal(java.math.BigDecimal) Future(java.util.concurrent.Future) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) BiTuple(com.hazelcast.internal.util.BiTuple) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) LocalTime(java.time.LocalTime) Nonnull(javax.annotation.Nonnull) MainPortable(com.hazelcast.internal.serialization.impl.portable.MainPortable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Serializable(java.io.Serializable) OffsetDateTime(java.time.OffsetDateTime) IExecutorService(com.hazelcast.core.IExecutorService) EntryProcessor(com.hazelcast.map.EntryProcessor) LocalDate(java.time.LocalDate) InnerPortable(com.hazelcast.internal.serialization.impl.portable.InnerPortable) GenericRecordBuilder(com.hazelcast.nio.serialization.GenericRecordBuilder) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) Test(org.junit.Test)

Example 34 with SerializationConfig

use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.

the class AbstractGenericRecordIntegrationTest method testInconsistentClassDefinitionOfNestedPortableFields_whenCheckClassDefErrorsIsFalse.

@Test
public void testInconsistentClassDefinitionOfNestedPortableFields_whenCheckClassDefErrorsIsFalse() {
    createCluster();
    SerializationConfig serializationConfig = new SerializationConfig(this.serializationConfig);
    serializationConfig.setCheckClassDefErrors(false);
    HazelcastInstance instance = createAccessorInstance(serializationConfig);
    IMap<Object, Object> map = instance.getMap("test");
    BiTuple<GenericRecord, GenericRecord> records = getInconsistentNestedGenericRecords();
    map.put(1, records.element1);
    map.put(2, records.element2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) Test(org.junit.Test)

Example 35 with SerializationConfig

use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.

the class DefaultPortableReaderQuickTest method reader.

// 
// Utilities
// 
public GenericRecordQueryReader reader(Portable portable) throws IOException {
    SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.addPortableFactory(TestPortableFactory.ID, new TestPortableFactory());
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
    ss.toData(NON_EMPTY_PORSCHE);
    return new GenericRecordQueryReader(ss.readAsInternalGenericRecord(ss.toData(portable)));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationConfig(com.hazelcast.config.SerializationConfig) GenericRecordQueryReader(com.hazelcast.internal.serialization.impl.GenericRecordQueryReader) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService)

Aggregations

SerializationConfig (com.hazelcast.config.SerializationConfig)73 Test (org.junit.Test)45 QuickTest (com.hazelcast.test.annotation.QuickTest)37 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)36 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)23 SerializerConfig (com.hazelcast.config.SerializerConfig)21 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)21 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 Data (com.hazelcast.internal.serialization.Data)18 SerializationService (com.hazelcast.internal.serialization.SerializationService)14 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 ClientConfig (com.hazelcast.client.config.ClientConfig)8 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)7 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)7 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)6 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)6 SerializationService (com.hazelcast.spi.serialization.SerializationService)6 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)6 Config (com.hazelcast.config.Config)5