Search in sources :

Example 11 with SerializerConfig

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);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with SerializerConfig

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));
        }
    });
}
Also used : PutOperation(com.hazelcast.replicatedmap.impl.operation.PutOperation) Config(com.hazelcast.config.Config) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) IOException(java.io.IOException) SerializerConfig(com.hazelcast.config.SerializerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with SerializerConfig

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());
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) DummyDataSerializableFactory(com.hazelcast.spring.serialization.DummyDataSerializableFactory) DummyPortableFactory(com.hazelcast.spring.serialization.DummyPortableFactory) DummyDataSerializableFactory(com.hazelcast.spring.serialization.DummyDataSerializableFactory) DummyPortableFactory(com.hazelcast.spring.serialization.DummyPortableFactory) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) Test(org.junit.Test) QuickTest(com.hazelcast.test.annotation.QuickTest)

Example 14 with SerializerConfig

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

Example 15 with SerializerConfig

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();
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Aggregations

SerializerConfig (com.hazelcast.config.SerializerConfig)17 SerializationConfig (com.hazelcast.config.SerializationConfig)14 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)5 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 Config (com.hazelcast.config.Config)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)2 SampleIdentifiedDataSerializable (com.hazelcast.nio.serialization.SampleIdentifiedDataSerializable)2 LoadBalancer (com.hazelcast.client.LoadBalancer)1 ProxyFactoryConfig (com.hazelcast.client.config.ProxyFactoryConfig)1 RoundRobinLB (com.hazelcast.client.util.RoundRobinLB)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 XMLConfigBuilderTest (com.hazelcast.config.XMLConfigBuilderTest)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1