use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class SerializationIssueTest 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.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class SerializationIssueTest 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.SerializationService in project hazelcast by hazelcast.
the class SerializationIssueTest method testUnsharedJavaSerialization.
/**
* issue #1265
*/
@Test
public void testUnsharedJavaSerialization() {
SerializationService ss = new DefaultSerializationServiceBuilder().setEnableSharedObject(false).build();
Data data = ss.toData(new Foo());
Foo foo = ss.toObject(data);
Assert.assertFalse("Objects should not be identical!", foo == foo.getBar().getFoo());
}
use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class SerializationIssueTest 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;
long 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.SerializationService in project hazelcast by hazelcast.
the class GenericRecordTest method testCloneObjectConvertedFromData.
@Test
public void testCloneObjectConvertedFromData() {
SerializationService serializationService = createSerializationService();
GenericRecordBuilder builder = compact("fooBarTypeName");
builder.setInt32("foo", 1);
assertTrue(trySetAndGetMessage("foo", 5, builder).startsWith("Field can only be written once"));
builder.setInt64("bar", 1231L);
GenericRecord expectedGenericRecord = builder.build();
Data data = serializationService.toData(expectedGenericRecord);
Object object = serializationService.toObject(data);
GenericRecord genericRecord = (GenericRecord) object;
GenericRecordBuilder cloneBuilder = genericRecord.cloneWithBuilder();
cloneBuilder.setInt32("foo", 2);
assertTrue(trySetAndGetMessage("foo", 5, cloneBuilder).startsWith("Field can only be written once"));
assertTrue(trySetAndGetMessage("notExisting", 3, cloneBuilder).startsWith("Invalid field name"));
GenericRecord clone = cloneBuilder.build();
assertEquals(2, clone.getInt32("foo"));
assertEquals(1231L, clone.getInt64("bar"));
}
Aggregations