Search in sources :

Example 21 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.

the class PortableClassVersionTest method testDifferentClassVersions.

@Test
public void testDifferentClassVersions() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().addPortableFactory(FACTORY_ID, new PortableFactory() {

        public Portable create(int classId) {
            return new NamedPortable();
        }
    }).build();
    SerializationService serializationService2 = new DefaultSerializationServiceBuilder().addPortableFactory(FACTORY_ID, new PortableFactory() {

        public Portable create(int classId) {
            return new NamedPortableV2();
        }
    }).build();
    testDifferentClassVersions(serializationService, serializationService2);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) PortableTest.createSerializationService(com.hazelcast.nio.serialization.PortableTest.createSerializationService) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder 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 23 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.

the class SerializationTest method testCompressionOnSerializables.

/**
     * Ensures that SerializationService correctly handles compressed Serializables,
     * using a Properties object as a test case.
     */
@Test
public void testCompressionOnSerializables() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setEnableCompression(true).build();
    long key = 1, value = 5000;
    Properties properties = new Properties();
    properties.put(key, value);
    Data data = serializationService.toData(properties);
    Properties output = serializationService.toObject(data);
    assertEquals(value, output.get(key));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) Properties(java.util.Properties) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.

the class SerializationTest method testDynamicProxySerialization_withContextClassLoader.

@Test
public void testDynamicProxySerialization_withContextClassLoader() {
    ClassLoader oldContextLoader = Thread.currentThread().getContextClassLoader();
    try {
        ClassLoader current = getClass().getClassLoader();
        DynamicProxyTestClassLoader cl = new DynamicProxyTestClassLoader(current);
        Thread.currentThread().setContextClassLoader(cl);
        SerializationService ss = new DefaultSerializationServiceBuilder().setClassLoader(cl).build();
        IObjectA oa = (IObjectA) Proxy.newProxyInstance(current, new Class[] { IObjectA.class }, DummyInvocationHandler.INSTANCE);
        Data data = ss.toData(oa);
        Object o = ss.toObject(data);
        Assert.assertSame("context classloader is not used", cl, o.getClass().getClassLoader());
        try {
            IObjectA.class.cast(o);
            Assert.fail("the serialized object should not be castable");
        } catch (ClassCastException expected) {
        // expected
        }
    } finally {
        Thread.currentThread().setContextClassLoader(oldContextLoader);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with DefaultSerializationServiceBuilder

use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.

the class SerializationTest method testCompressionOnExternalizables.

/**
     * Ensures that SerializationService correctly handles compressed Serializables,
     * using a test-specific object as a test case.
     */
@Test
public void testCompressionOnExternalizables() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setEnableCompression(true).build();
    String test = "test";
    ExternalizableString ex = new ExternalizableString(test);
    Data data = serializationService.toData(ex);
    ExternalizableString actual = serializationService.toObject(data);
    assertEquals(test, actual.value);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)70 Test (org.junit.Test)56 QuickTest (com.hazelcast.test.annotation.QuickTest)55 SerializationService (com.hazelcast.spi.serialization.SerializationService)46 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)22 ParallelTest (com.hazelcast.test.annotation.ParallelTest)18 HeapData (com.hazelcast.internal.serialization.impl.HeapData)16 Data (com.hazelcast.nio.serialization.Data)15 SerializationConfig (com.hazelcast.config.SerializationConfig)11 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)6 ArrayList (java.util.ArrayList)6 SerializerConfig (com.hazelcast.config.SerializerConfig)5 Before (org.junit.Before)5 PartitioningStrategy (com.hazelcast.core.PartitioningStrategy)4 Config (com.hazelcast.config.Config)3 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)3 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)3 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)3 HashMap (java.util.HashMap)3 HazelcastThreadGroup (com.hazelcast.instance.HazelcastThreadGroup)2