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;
}
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());
}
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);
}
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);
}
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);
}
Aggregations