Search in sources :

Example 51 with DefaultSerializationServiceBuilder

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

the class SerializationTest method testDynamicProxySerialization_withConfiguredClassLoader.

@Test
public void testDynamicProxySerialization_withConfiguredClassLoader() {
    ClassLoader current = getClass().getClassLoader();
    DynamicProxyTestClassLoader cl = new DynamicProxyTestClassLoader(current);
    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("configured 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
    }
}
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 52 with DefaultSerializationServiceBuilder

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

the class SerializationTest method testArrayListSerialization.

@Test
public void testArrayListSerialization() {
    SerializationService ss = new DefaultSerializationServiceBuilder().build();
    ArrayList<Person> arrayList = new ArrayList<Person>();
    arrayList.add(new Person(35, 180, 100, "Orhan", null));
    arrayList.add(new Person(12, 120, 60, "Osman", null));
    Data data = ss.toData(arrayList);
    ArrayList deserialized = ss.toObject(data);
    assertTrue("Objects are not identical!", arrayList.equals(deserialized));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ArrayList(java.util.ArrayList) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) Person(com.hazelcast.nio.serialization.SerializationConcurrencyTest.Person) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 53 with DefaultSerializationServiceBuilder

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

the class SerializationTest method testNullData.

@Test
public void testNullData() {
    Data data = new HeapData();
    SerializationService ss = new DefaultSerializationServiceBuilder().build();
    assertNull(ss.toObject(data));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 54 with DefaultSerializationServiceBuilder

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

the class SerializationTest method testSharedJavaSerialization.

/**
     * issue #1265
     */
@Test
public void testSharedJavaSerialization() {
    SerializationService ss = new DefaultSerializationServiceBuilder().setEnableSharedObject(true).build();
    Data data = ss.toData(new Foo());
    Foo foo = (Foo) ss.toObject(data);
    assertTrue("Objects are not identical!", foo == foo.getBar().getFoo());
}
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 55 with DefaultSerializationServiceBuilder

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

the class SerializationTest method testNonPublicDynamicProxySerialization_withClassLoaderMess.

@Test
public void testNonPublicDynamicProxySerialization_withClassLoaderMess() {
    ClassLoader current = getClass().getClassLoader();
    DynamicProxyTestClassLoader cl1 = new DynamicProxyTestClassLoader(current, IPrivateObjectB.class.getName());
    DynamicProxyTestClassLoader cl2 = new DynamicProxyTestClassLoader(cl1, IPrivateObjectC.class.getName());
    SerializationService ss = new DefaultSerializationServiceBuilder().setClassLoader(cl2).build();
    Object ocd = Proxy.newProxyInstance(current, new Class[] { IPrivateObjectB.class, IPrivateObjectC.class }, DummyInvocationHandler.INSTANCE);
    Data data = ss.toData(ocd);
    try {
        ss.toObject(data);
        Assert.fail("the object should not be deserializable");
    } catch (IllegalAccessError expected) {
    // expected
    }
}
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