Search in sources :

Example 36 with SerializationConfig

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);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) Test(org.junit.Test)

Example 37 with SerializationConfig

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();
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SerializationConfig(com.hazelcast.config.SerializationConfig) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) Test(org.junit.Test)

Example 38 with SerializationConfig

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

Example 39 with SerializationConfig

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());
}
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)

Example 40 with SerializationConfig

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