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