Search in sources :

Example 46 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class SerializationIssueTest method testNullData.

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

Example 47 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class SerializationIssueTest method testVersionedDataSerializable_inputHasMemberVersion.

@Test
public void testVersionedDataSerializable_inputHasMemberVersion() {
    SerializationService ss = new DefaultSerializationServiceBuilder().build();
    VersionedDataSerializable object = new VersionedDataSerializable();
    VersionedDataSerializable otherObject = ss.toObject(ss.toData(object));
    assertEquals("ObjectDataInput.getVersion should be equal to member version", Version.of(BuildInfoProvider.getBuildInfo().getVersion()), otherObject.getVersion());
}
Also used : SerializationService(com.hazelcast.internal.serialization.SerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 48 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class SerializationIssueTest 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 : SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class SerializationIssueTest 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 : SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 50 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class SerializationIssueTest 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 : SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SerializationService (com.hazelcast.internal.serialization.SerializationService)170 Data (com.hazelcast.internal.serialization.Data)117 Test (org.junit.Test)100 QuickTest (com.hazelcast.test.annotation.QuickTest)99 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)50 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)43 ArrayList (java.util.ArrayList)15 SerializationConfig (com.hazelcast.config.SerializationConfig)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Node (com.hazelcast.instance.impl.Node)12 CustomSerializationTest (com.hazelcast.internal.serialization.impl.CustomSerializationTest)12 Accessors.getNode (com.hazelcast.test.Accessors.getNode)12 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)11 EmployeeDTO (example.serialization.EmployeeDTO)11 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)11 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)8 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8