use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class PortableTest method testPortableNestedInOthers.
@Test
public void testPortableNestedInOthers() {
SerializationService serializationService = createSerializationService(1);
Object o1 = new ComplexDataSerializable(new NamedPortable("test-portable", 137), new ByteArrayDataSerializable("test-data-serializable".getBytes()), new ByteArrayDataSerializable("test-data-serializable-2".getBytes()));
Data data = serializationService.toData(o1);
SerializationService serializationService2 = createSerializationService(2);
Object o2 = serializationService2.toObject(data);
assertEquals(o1, o2);
}
use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class PortableTest method testGenericPortable_whenMultipleTypesAreUsed.
@Test(expected = HazelcastSerializationException.class)
public void testGenericPortable_whenMultipleTypesAreUsed() {
SerializationService ss = new DefaultSerializationServiceBuilder().addPortableFactory(1, new PortableFactory() {
@Override
public Portable create(int classId) {
switch(classId) {
case ParentGenericPortable.CLASS_ID:
return new ParentGenericPortable();
case ChildGenericPortable1.CLASS_ID:
return new ChildGenericPortable1();
case ChildGenericPortable2.CLASS_ID:
return new ChildGenericPortable2();
default:
throw new IllegalArgumentException();
}
}
}).build();
ss.toData(new ParentGenericPortable<ChildGenericPortable1>(new ChildGenericPortable1("aaa", "bbb")));
Data data = ss.toData(new ParentGenericPortable<ChildGenericPortable2>(new ChildGenericPortable2("ccc")));
ss.toObject(data);
}
use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class PortableTest method testWriteRead_withNullPortableArray.
@Test
public void testWriteRead_withNullPortableArray() {
int portableVersion = 1;
ClassDefinitionBuilder builder0 = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, 1, portableVersion);
ClassDefinitionBuilder builder1 = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, 2, portableVersion);
builder0.addPortableArrayField("list", builder1.build());
SerializationService ss = new DefaultSerializationServiceBuilder().setPortableVersion(portableVersion).addClassDefinition(builder0.build()).addClassDefinition(builder1.build()).build();
Data data = ss.toData(new TestObject1());
SerializationService ss2 = new DefaultSerializationServiceBuilder().addPortableFactory(1, new PortableFactory() {
@Override
public Portable create(int classId) {
switch(classId) {
case 1:
return new TestObject1();
case 2:
return new TestObject2();
default:
return null;
}
}
}).build();
Object object = ss2.toObject(data);
assertNotNull(object);
assertTrue(object instanceof TestObject1);
}
use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class PortableTest method testWriteObjectWithCustomSerializable.
@Test
public void testWriteObjectWithCustomSerializable() {
SerializationConfig config = new SerializationConfig();
SerializerConfig sc = new SerializerConfig().setImplementation(new CustomSerializationTest.FooXmlSerializer()).setTypeClass(CustomSerializationTest.Foo.class);
config.addSerializerConfig(sc);
SerializationService serializationService = new DefaultSerializationServiceBuilder().setPortableVersion(1).addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory()).setConfig(config).build();
CustomSerializationTest.Foo foo = new CustomSerializationTest.Foo("f");
ObjectCarryingPortable objectCarryingPortable1 = new ObjectCarryingPortable(foo);
Data data = serializationService.toData(objectCarryingPortable1);
ObjectCarryingPortable objectCarryingPortable2 = serializationService.toObject(data);
assertEquals(objectCarryingPortable1, objectCarryingPortable2);
}
use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.
the class PortableTest method testWriteObjectWithPortable.
@Test
public void testWriteObjectWithPortable() {
SerializationService serializationService = createSerializationService(1);
NamedPortable namedPortable = new NamedPortable("name", 2);
ObjectCarryingPortable objectCarryingPortable1 = new ObjectCarryingPortable(namedPortable);
Data data = serializationService.toData(objectCarryingPortable1);
ObjectCarryingPortable objectCarryingPortable2 = serializationService.toObject(data);
assertEquals(objectCarryingPortable1, objectCarryingPortable2);
}
Aggregations