Search in sources :

Example 51 with SerializationConfig

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

the class ClientConfigXmlGeneratorTest method buildSerializationConfig.

private SerializationConfig buildSerializationConfig() {
    SerializationConfig expected = new SerializationConfig();
    expected.setPortableVersion(randomInt()).setUseNativeByteOrder(true).setByteOrder(ByteOrder.LITTLE_ENDIAN).setEnableCompression(true).setEnableSharedObject(false).setAllowUnsafe(true).setAllowOverrideDefaultSerializers(true).setCheckClassDefErrors(false).addDataSerializableFactoryClass(randomInt(), randomString()).addPortableFactoryClass(randomInt(), randomString()).setGlobalSerializerConfig(new GlobalSerializerConfig().setClassName(randomString()).setOverrideJavaSerialization(true));
    return expected;
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig)

Example 52 with SerializationConfig

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

the class TestFullApplicationContext method testSerializationConfig.

@Test
public void testSerializationConfig() {
    SerializationConfig serializationConfig = config.getSerializationConfig();
    assertTrue(serializationConfig.isAllowOverrideDefaultSerializers());
    assertEquals(ByteOrder.BIG_ENDIAN, serializationConfig.getByteOrder());
    assertFalse(serializationConfig.isCheckClassDefErrors());
    assertEquals(13, serializationConfig.getPortableVersion());
    Map<Integer, String> dataSerializableFactoryClasses = serializationConfig.getDataSerializableFactoryClasses();
    assertFalse(dataSerializableFactoryClasses.isEmpty());
    assertEquals(DummyDataSerializableFactory.class.getName(), dataSerializableFactoryClasses.get(1));
    Map<Integer, DataSerializableFactory> dataSerializableFactories = serializationConfig.getDataSerializableFactories();
    assertFalse(dataSerializableFactories.isEmpty());
    assertEquals(DummyDataSerializableFactory.class, dataSerializableFactories.get(2).getClass());
    Map<Integer, String> portableFactoryClasses = serializationConfig.getPortableFactoryClasses();
    assertFalse(portableFactoryClasses.isEmpty());
    assertEquals(DummyPortableFactory.class.getName(), portableFactoryClasses.get(1));
    Map<Integer, PortableFactory> portableFactories = serializationConfig.getPortableFactories();
    assertFalse(portableFactories.isEmpty());
    assertEquals(DummyPortableFactory.class, portableFactories.get(2).getClass());
    Collection<SerializerConfig> serializerConfigs = serializationConfig.getSerializerConfigs();
    assertFalse(serializerConfigs.isEmpty());
    GlobalSerializerConfig globalSerializerConfig = serializationConfig.getGlobalSerializerConfig();
    assertNotNull(globalSerializerConfig);
    assertEquals(dummySerializer, globalSerializerConfig.getImplementation());
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) DummyDataSerializableFactory(com.hazelcast.spring.serialization.DummyDataSerializableFactory) DummyPortableFactory(com.hazelcast.spring.serialization.DummyPortableFactory) DummyDataSerializableFactory(com.hazelcast.spring.serialization.DummyDataSerializableFactory) DummyPortableFactory(com.hazelcast.spring.serialization.DummyPortableFactory) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 53 with SerializationConfig

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

the class CustomSerializationOverrideDefaultTest method testUsageOfEmbeddedSerializer.

private void testUsageOfEmbeddedSerializer(final boolean allowOverride) {
    final SerializationConfig config = new SerializationConfig().setAllowOverrideDefaultSerializers(allowOverride);
    final SerializationService ss = new DefaultSerializationServiceBuilder().setConfig(config).build();
    final Optional<Integer> answer = Optional.of(42);
    final Data d = ss.toData(answer);
    assertEquals(OPTIONAL_INTEGER_SIZE, d.dataSize());
    final Optional<Integer> deserializedAnswer = ss.toObject(d);
    assertEquals(answer, deserializedAnswer);
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data)

Example 54 with SerializationConfig

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

the class CustomSerializationOverrideDefaultTest method testUsageOfCustomSerializer.

private void testUsageOfCustomSerializer(final boolean allowOverrideDefaultSerializers) {
    final SerializationConfig config = new SerializationConfig().setAllowOverrideDefaultSerializers(allowOverrideDefaultSerializers);
    final SerializerConfig sc = new SerializerConfig().setImplementation(new TestOptionalSerializer()).setTypeClass(Optional.class);
    config.addSerializerConfig(sc);
    final SerializationService ss = new DefaultSerializationServiceBuilder().setConfig(config).build();
    final Optional<Integer> answer = Optional.of(42);
    final Data d = ss.toData(answer);
    // string Optional[Integer.MAX_VALUE] from TestOptionalSerializer
    assertNotEquals(OPTIONAL_INTEGER_SIZE, d.dataSize());
    final Optional<Integer> deserializedAnswer = ss.toObject(d);
    assertEquals(Optional.of(Integer.MAX_VALUE), deserializedAnswer);
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data)

Example 55 with SerializationConfig

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

the class CustomSerializationTest method testSerializer.

private void testSerializer(ByteOrder order, boolean allowUnsafe) {
    SerializationConfig config = new SerializationConfig();
    config.setAllowUnsafe(allowUnsafe).setByteOrder(order).setUseNativeByteOrder(false);
    SerializerConfig sc = new SerializerConfig().setImplementation(new FooXmlSerializer()).setTypeClass(Foo.class);
    config.addSerializerConfig(sc);
    SerializationService ss = new DefaultSerializationServiceBuilder().setConfig(config).build();
    Foo foo = new Foo("f");
    Data d = ss.toData(foo);
    Foo newFoo = ss.toObject(d);
    assertEquals(newFoo, foo);
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data)

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