Search in sources :

Example 46 with SerializationConfig

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);
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig)

Example 47 with 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;
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Example 48 with 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);
    }
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) ClientDiscoverySpiTest(com.hazelcast.client.impl.spi.impl.discovery.ClientDiscoverySpiTest)

Example 49 with SerializationConfig

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 50 with SerializationConfig

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());
}
Also used : GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SerializationConfig (com.hazelcast.config.SerializationConfig)73 Test (org.junit.Test)45 QuickTest (com.hazelcast.test.annotation.QuickTest)37 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)36 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)23 SerializerConfig (com.hazelcast.config.SerializerConfig)21 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)21 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 Data (com.hazelcast.internal.serialization.Data)18 SerializationService (com.hazelcast.internal.serialization.SerializationService)14 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 ClientConfig (com.hazelcast.client.config.ClientConfig)8 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)7 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)7 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)6 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)6 SerializationService (com.hazelcast.spi.serialization.SerializationService)6 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)6 Config (com.hazelcast.config.Config)5