use of com.hazelcast.spi.serialization.SerializationService 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.spi.serialization.SerializationService 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.spi.serialization.SerializationService 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.spi.serialization.SerializationService 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);
}
use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class SerializationTest method testPartitionHash.
@Test
public void testPartitionHash() {
PartitioningStrategy partitionStrategy = new PartitioningStrategy() {
@Override
public Object getPartitionKey(Object key) {
return key.hashCode();
}
};
SerializationService ss = new DefaultSerializationServiceBuilder().build();
String obj = String.valueOf(System.nanoTime());
Data dataWithPartitionHash = ss.toData(obj, partitionStrategy);
Data dataWithOutPartitionHash = ss.toData(obj);
assertTrue(dataWithPartitionHash.hasPartitionHash());
assertNotEquals(dataWithPartitionHash.hashCode(), dataWithPartitionHash.getPartitionHash());
assertFalse(dataWithOutPartitionHash.hasPartitionHash());
assertEquals(dataWithOutPartitionHash.hashCode(), dataWithOutPartitionHash.getPartitionHash());
}
Aggregations