use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.
the class XmlClientConfigBuilderTest method testSerializationConfig.
@Test
public void testSerializationConfig() {
final SerializationConfig serializationConfig = clientConfig.getSerializationConfig();
assertEquals(3, serializationConfig.getPortableVersion());
final Map<Integer, String> dsClasses = serializationConfig.getDataSerializableFactoryClasses();
assertEquals(1, dsClasses.size());
assertEquals("com.hazelcast.examples.DataSerializableFactory", dsClasses.get(1));
final Map<Integer, String> pfClasses = serializationConfig.getPortableFactoryClasses();
assertEquals(1, pfClasses.size());
assertEquals("com.hazelcast.examples.PortableFactory", pfClasses.get(2));
final Collection<SerializerConfig> serializerConfigs = serializationConfig.getSerializerConfigs();
assertEquals(1, serializerConfigs.size());
final SerializerConfig serializerConfig = serializerConfigs.iterator().next();
assertEquals("com.hazelcast.examples.DummyType", serializerConfig.getTypeClassName());
assertEquals("com.hazelcast.examples.SerializerFactory", serializerConfig.getClassName());
final GlobalSerializerConfig globalSerializerConfig = serializationConfig.getGlobalSerializerConfig();
assertEquals("com.hazelcast.examples.GlobalSerializerFactory", globalSerializerConfig.getClassName());
assertEquals(ByteOrder.BIG_ENDIAN, serializationConfig.getByteOrder());
assertEquals(true, serializationConfig.isCheckClassDefErrors());
assertEquals(false, serializationConfig.isAllowUnsafe());
assertEquals(false, serializationConfig.isEnableCompression());
assertEquals(true, serializationConfig.isEnableSharedObject());
assertEquals(true, serializationConfig.isUseNativeByteOrder());
}
use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.
the class TestClientApplicationContext method testClient.
@Test
public void testClient() {
assertNotNull(client);
assertNotNull(client2);
assertNotNull(client3);
ClientConfig config = client.getClientConfig();
assertEquals("13", config.getProperty("hazelcast.client.retry.count"));
assertEquals(3, config.getNetworkConfig().getConnectionAttemptLimit());
assertEquals(1000, config.getNetworkConfig().getConnectionTimeout());
assertEquals(3000, config.getNetworkConfig().getConnectionAttemptPeriod());
ClientConfig config2 = client2.getClientConfig();
assertEquals(credentials, config2.getSecurityConfig().getCredentials());
client.getMap("default").put("Q", "q");
client2.getMap("default").put("X", "x");
IMap<Object, Object> map = instance.getMap("default");
assertEquals("q", map.get("Q"));
assertEquals("x", map.get("X"));
ClientConfig config3 = client3.getClientConfig();
SerializationConfig serConf = config3.getSerializationConfig();
assertEquals(ByteOrder.BIG_ENDIAN, serConf.getByteOrder());
assertEquals(false, serConf.isAllowUnsafe());
assertEquals(false, serConf.isCheckClassDefErrors());
assertEquals(false, serConf.isEnableCompression());
assertEquals(false, serConf.isEnableSharedObject());
assertEquals(false, serConf.isUseNativeByteOrder());
assertEquals(10, serConf.getPortableVersion());
Map<Integer, String> map1 = serConf.getDataSerializableFactoryClasses();
assertNotNull(map1);
assertTrue(map1.containsKey(1));
assertEquals("com.hazelcast.spring.serialization.DummyDataSerializableFactory", map1.get(1));
Map<Integer, String> portableFactoryClasses = serConf.getPortableFactoryClasses();
assertNotNull(portableFactoryClasses);
assertTrue(portableFactoryClasses.containsKey(2));
assertEquals("com.hazelcast.spring.serialization.DummyPortableFactory", portableFactoryClasses.get(2));
Collection<SerializerConfig> serializerConfigs = serConf.getSerializerConfigs();
assertNotNull(serializerConfigs);
SerializerConfig serializerConfig = serializerConfigs.iterator().next();
assertNotNull(serializerConfig);
assertEquals("com.hazelcast.nio.serialization.CustomSerializationTest$FooXmlSerializer", serializerConfig.getClassName());
assertEquals("com.hazelcast.nio.serialization.CustomSerializationTest$Foo", serializerConfig.getTypeClassName());
List<ProxyFactoryConfig> proxyFactoryConfigs = config3.getProxyFactoryConfigs();
assertNotNull(proxyFactoryConfigs);
ProxyFactoryConfig proxyFactoryConfig = proxyFactoryConfigs.get(0);
assertNotNull(proxyFactoryConfig);
assertEquals("com.hazelcast.spring.DummyProxyFactory", proxyFactoryConfig.getClassName());
assertEquals("MyService", proxyFactoryConfig.getService());
LoadBalancer loadBalancer = config3.getLoadBalancer();
assertNotNull(loadBalancer);
assertTrue(loadBalancer instanceof RoundRobinLB);
NearCacheConfig nearCacheConfig = config3.getNearCacheConfig("default");
assertNotNull(nearCacheConfig);
assertEquals(1, nearCacheConfig.getTimeToLiveSeconds());
assertEquals(70, nearCacheConfig.getMaxIdleSeconds());
assertEquals(EvictionPolicy.LRU, nearCacheConfig.getEvictionConfig().getEvictionPolicy());
assertEquals(4000, nearCacheConfig.getEvictionConfig().getSize());
assertEquals(true, nearCacheConfig.isInvalidateOnChange());
assertEquals(CACHE_ON_UPDATE, nearCacheConfig.getLocalUpdatePolicy());
}
use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.
the class BinaryCompatibilityTest method createSerializationService.
private SerializationService createSerializationService() {
SerializationConfig config = new SerializationConfig();
{
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomByteArraySerializer()).setTypeClass(CustomByteArraySerializable.class);
config.addSerializerConfig(serializerConfig);
}
{
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomStreamSerializer()).setTypeClass(CustomStreamSerializable.class);
config.addSerializerConfig(serializerConfig);
}
config.setAllowUnsafe(allowUnsafe);
config.setByteOrder(byteOrder);
ClassDefinition classDefinition = new ClassDefinitionBuilder(ReferenceObjects.PORTABLE_FACTORY_ID, ReferenceObjects.INNER_PORTABLE_CLASS_ID).addIntField("i").addFloatField("f").build();
return new DefaultSerializationServiceBuilder().setConfig(config).setVersion(version).addPortableFactory(ReferenceObjects.PORTABLE_FACTORY_ID, new APortableFactory()).addDataSerializableFactory(ReferenceObjects.IDENTIFIED_DATA_SERIALIZABLE_FACTORY_ID, new ADataSerializableFactory()).addClassDefinition(classDefinition).build();
}
use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.
the class PortableTest method testWriteObjectWithCustomSerializable.
@Test
public void testWriteObjectWithCustomSerializable() {
SerializationConfig config = new SerializationConfig();
SerializerConfig sc = new SerializerConfig().setImplementation(new CustomSerializationTest.FooXmlSerializer()).setTypeClass(CustomSerializationTest.Foo.class);
config.addSerializerConfig(sc);
SerializationService serializationService = new DefaultSerializationServiceBuilder().setPortableVersion(1).addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory()).setConfig(config).build();
CustomSerializationTest.Foo foo = new CustomSerializationTest.Foo("f");
ObjectCarryingPortable objectCarryingPortable1 = new ObjectCarryingPortable(foo);
Data data = serializationService.toData(objectCarryingPortable1);
ObjectCarryingPortable objectCarryingPortable2 = serializationService.toObject(data);
assertEquals(objectCarryingPortable1, objectCarryingPortable2);
}
use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.
the class CustomSerializationTest method testSerializer.
private void testSerializer(ByteOrder order, boolean allowUnsafe) throws Exception {
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