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