use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class ClientDomConfigProcessor method handleSerialization.
private void handleSerialization(Node node) {
SerializationConfig serializationConfig = parseSerialization(node);
clientConfig.setSerializationConfig(serializationConfig);
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class SqlBasicTest method serializationConfig.
public static SerializationConfig serializationConfig() {
SerializationConfig serializationConfig = new SerializationConfig();
ClassDefinition nestedClassDefinition = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, PORTABLE_NESTED_CLASS_ID, 0).addIntField("val").build();
ClassDefinition valueClassDefinition = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, PORTABLE_VALUE_CLASS_ID, 0).addBooleanField(portableFieldName("booleanVal")).addByteField(portableFieldName("tinyIntVal")).addShortField(portableFieldName("smallIntVal")).addIntField(portableFieldName("intVal")).addLongField(portableFieldName("bigIntVal")).addFloatField(portableFieldName("realVal")).addDoubleField(portableFieldName("doubleVal")).addDecimalField(portableFieldName("decimalVal")).addCharField(portableFieldName("charVal")).addStringField(portableFieldName("varcharVal")).addDateField(portableFieldName("dateVal")).addTimeField(portableFieldName("timeVal")).addTimestampField(portableFieldName("timestampVal")).addTimestampWithTimezoneField(portableFieldName("tsTzOffsetDateTimeVal")).addPortableField(portableFieldName("portableVal"), nestedClassDefinition).addStringField(portableFieldName("nullVal")).build();
ClassDefinition keyClassDefinition = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, PORTABLE_KEY_CLASS_ID, 0).addLongField(portableFieldName("key")).build();
serializationConfig.addClassDefinition(nestedClassDefinition);
serializationConfig.addClassDefinition(valueClassDefinition);
serializationConfig.addClassDefinition(keyClassDefinition);
serializationConfig.addPortableFactory(PORTABLE_FACTORY_ID, classId -> {
if (classId == PORTABLE_KEY_CLASS_ID) {
return new PortablePojoKey();
} else if (classId == PORTABLE_VALUE_CLASS_ID) {
return new PortablePojo();
} else if (classId == PORTABLE_NESTED_CLASS_ID) {
return new PortablePojoNested();
}
throw new IllegalArgumentException("Unsupported class ID: " + classId);
});
serializationConfig.addDataSerializableFactory(IDS_FACTORY_ID, classId -> {
if (classId == IDS_KEY_CLASS_ID) {
return new IdentifiedDataSerializablePojoKey();
} else if (classId == IDS_VALUE_CLASS_ID) {
return new IdentifiedDataSerializablePojo();
}
throw new IllegalArgumentException("Unsupported class ID: " + classId);
});
return serializationConfig;
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class ThreadLeakClientTest method testThreadLeakWhenClientCanNotConstructDueToIncorrectSerializationServiceFactoryClassName.
@Test(expected = HazelcastSerializationException.class)
public void testThreadLeakWhenClientCanNotConstructDueToIncorrectSerializationServiceFactoryClassName() {
ClientConfig config = new ClientConfig();
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.addDataSerializableFactoryClass(5, "invalid.factory");
config.setSerializationConfig(serializationConfig);
Set<Thread> testStartThreads = getThreads();
try {
HazelcastClient.newHazelcastClient(config);
} finally {
assertHazelcastThreadShutdown(testStartThreads);
}
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class ClientRegressionWithMockNetworkTest method testClientPortableWithoutRegisteringToNode.
@Test
public void testClientPortableWithoutRegisteringToNode() {
hazelcastFactory.newHazelcastInstance();
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.addPortableFactory(5, classId -> new SamplePortable());
ClientConfig clientConfig = new ClientConfig();
clientConfig.setSerializationConfig(serializationConfig);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
IMap<Integer, SamplePortable> sampleMap = client.getMap(randomString());
sampleMap.put(1, new SamplePortable(666));
SamplePortable samplePortable = sampleMap.get(1);
assertEquals(666, samplePortable.a);
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class ClientConfigXmlGeneratorTest method serialization_class.
@Test
public void serialization_class() {
SerializationConfig expected = buildSerializationConfig().addSerializerConfig(new SerializerConfig().setClass(TestSerializer.class).setTypeClass(TestType.class));
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.isCheckClassDefErrors(), actual.isCheckClassDefErrors());
assertEquals(expected.getGlobalSerializerConfig(), actual.getGlobalSerializerConfig());
assertCollection(expected.getSerializerConfigs(), actual.getSerializerConfigs(), (e, a) -> e.getTypeClass().getName().compareTo(a.getTypeClassName()));
assertMap(expected.getDataSerializableFactoryClasses(), actual.getDataSerializableFactoryClasses());
assertMap(expected.getPortableFactoryClasses(), actual.getPortableFactoryClasses());
}
Aggregations