use of com.hazelcast.config.SerializationConfig 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.SerializationConfig in project hazelcast by hazelcast.
the class PortableTest method testClassDefinitionConfigWithErrors.
@Test
public void testClassDefinitionConfigWithErrors() throws Exception {
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory());
serializationConfig.setPortableVersion(1);
serializationConfig.addClassDefinition(new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, TestSerializationConstants.RAW_DATA_PORTABLE, 1).addLongField("l").addCharArrayField("c").addPortableField("p", createNamedPortableClassDefinition(1)).build());
try {
new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
fail("Should throw HazelcastSerializationException!");
} catch (HazelcastSerializationException ignored) {
}
new DefaultSerializationServiceBuilder().setConfig(serializationConfig).setCheckClassDefErrors(false).build();
// -- OR --
serializationConfig.setCheckClassDefErrors(false);
new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class GenericRecordIntegrationTest method createAccessorInstance.
@Override
protected HazelcastInstance createAccessorInstance(SerializationConfig serializationConfig) {
Config config = new Config();
config.setLiteMember(true);
config.setSerializationConfig(serializationConfig);
return factory.newHazelcastInstance(config);
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class ClientConfigXmlGeneratorTest method serialization.
@Test
public void serialization() {
SerializationConfig expected = buildSerializationConfig().addSerializerConfig(new SerializerConfig().setClassName(TestSerializer.class.getName()).setTypeClassName(TestType.class.getName()));
clientConfig.setSerializationConfig(expected);
SerializationConfig actual = newConfigViaGenerator().getSerializationConfig();
assertEquals(expected.getPortableVersion(), actual.getPortableVersion());
assertEquals(expected.isUseNativeByteOrder(), actual.isUseNativeByteOrder());
assertEquals(expected.getByteOrder(), actual.getByteOrder());
assertEquals(expected.isEnableCompression(), actual.isEnableCompression());
assertEquals(expected.isEnableSharedObject(), actual.isEnableSharedObject());
assertEquals(expected.isAllowUnsafe(), actual.isAllowUnsafe());
assertEquals(expected.isAllowOverrideDefaultSerializers(), actual.isAllowOverrideDefaultSerializers());
assertEquals(expected.isCheckClassDefErrors(), actual.isCheckClassDefErrors());
assertEquals(expected.getGlobalSerializerConfig(), actual.getGlobalSerializerConfig());
assertCollection(expected.getSerializerConfigs(), actual.getSerializerConfigs());
assertMap(expected.getDataSerializableFactoryClasses(), actual.getDataSerializableFactoryClasses());
assertMap(expected.getPortableFactoryClasses(), actual.getPortableFactoryClasses());
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class ClientConfigTest method testAccessSerializationConfigOverClientInstance.
@Test
public void testAccessSerializationConfigOverClientInstance() {
hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getSerializationConfig().addPortableFactory(PortableFactory.FACTORY_ID, new PortableFactory());
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
SerializationConfig serializationConfig = client.getConfig().getSerializationConfig();
Map<Integer, com.hazelcast.nio.serialization.PortableFactory> factories = serializationConfig.getPortableFactories();
assertEquals(1, factories.size());
assertEquals(factories.get(PortableFactory.FACTORY_ID).create(Employee.CLASS_ID).getClassId(), Employee.CLASS_ID);
}
Aggregations