use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.
the class SerializationTest method testEmptyData.
@Test
public void testEmptyData() {
SerializationConfig serializationConfig = new SerializationConfig().addSerializerConfig(new SerializerConfig().setTypeClass(SingletonValue.class).setImplementation(new StreamSerializer<SingletonValue>() {
@Override
public void write(ObjectDataOutput out, SingletonValue v) throws IOException {
}
@Override
public SingletonValue read(ObjectDataInput in) throws IOException {
return new SingletonValue();
}
@Override
public int getTypeId() {
return 123;
}
@Override
public void destroy() {
}
}));
SerializationService ss1 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
Data data = ss1.toData(new SingletonValue());
Assert.assertNotNull(data);
SerializationService ss2 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
Object o = ss2.toObject(data);
Assert.assertEquals(new SingletonValue(), o);
}
use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.
the class ReplicatedMapAntiEntropyTest method testMapConvergesToSameValueWhenMissingReplicationUpdate.
@Test
public void testMapConvergesToSameValueWhenMissingReplicationUpdate() throws Exception {
Config config = new Config();
SerializationConfig serializationConfig = new SerializationConfig();
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setTypeClassName(PutOperation.class.getName());
serializerConfig.setImplementation(new PutOperationWithNoReplicationSerializer());
serializationConfig.addSerializerConfig(serializerConfig);
config.setSerializationConfig(serializationConfig);
System.setProperty("hazelcast.serialization.custom.override", "true");
String mapName = randomMapName();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance instance1 = factory.newHazelcastInstance(config);
HazelcastInstance instance2 = factory.newHazelcastInstance(config);
HazelcastInstance instance3 = factory.newHazelcastInstance(config);
final ReplicatedMap<Object, Object> map1 = instance1.getReplicatedMap(mapName);
final ReplicatedMap<Object, Object> map2 = instance2.getReplicatedMap(mapName);
final ReplicatedMap<Object, Object> map3 = instance3.getReplicatedMap(mapName);
final String key = generateKeyOwnedBy(instance2);
final String value = randomString();
map1.put(key, value);
assertEquals(value, map1.get(key));
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(value, map2.get(key));
assertEquals(value, map3.get(key));
}
});
}
use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.
the class TestFullApplicationContext method testSerializationConfig.
@Test
public void testSerializationConfig() {
SerializationConfig serializationConfig = config.getSerializationConfig();
assertEquals(ByteOrder.BIG_ENDIAN, serializationConfig.getByteOrder());
assertEquals(false, 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.SerializerConfig in project hazelcast by hazelcast.
the class ClientCardinalityEstimatorTest method createSerializationConfiguredClient.
private HazelcastInstance createSerializationConfiguredClient() {
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomObjectSerializer());
serializerConfig.setTypeClass(CustomObject.class);
ClientConfig config = new ClientConfig();
config.getSerializationConfig().addSerializerConfig(serializerConfig);
return hazelcastFactory.newHazelcastClient(config);
}
use of com.hazelcast.config.SerializerConfig in project hazelcast by hazelcast.
the class BinaryCompatibilityFileGenerator method createSerializationService.
private static SerializationService createSerializationService(ByteOrder byteOrder) {
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.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();
}
Aggregations