use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class PortableTest method testWriteObject_withPortable.
@Test
public void testWriteObject_withPortable() {
SerializationService ss = new DefaultSerializationServiceBuilder().addPortableFactory(PORTABLE_FACTORY_ID, new PortableFactory() {
@Override
public Portable create(int classId) {
return new NamedPortableV2();
}
}).build();
SerializationService ss2 = new DefaultSerializationServiceBuilder().addPortableFactory(PORTABLE_FACTORY_ID, new PortableFactory() {
@Override
public Portable create(int classId) {
return new NamedPortable();
}
}).setPortableVersion(5).build();
Object o1 = new ComplexDataSerializable(new NamedPortableV2("test", 123, 500), new ByteArrayDataSerializable(new byte[3]), null);
Data data = ss.toData(o1);
Object o2 = ss2.toObject(data);
assertEquals(o1, o2);
}
use of com.hazelcast.spi.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();
}
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.spi.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();
}
return null;
}
}).build();
Object object = ss2.toObject(data);
assertNotNull(object);
assertTrue(object instanceof TestObject1);
}
use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class PortableTest method testWriteData_withPortable.
@Test
public void testWriteData_withPortable() {
SerializationService ss = new DefaultSerializationServiceBuilder().addPortableFactory(PORTABLE_FACTORY_ID, new PortableFactory() {
@Override
public Portable create(int classId) {
return new NamedPortableV2();
}
}).build();
SerializationService ss2 = new DefaultSerializationServiceBuilder().addPortableFactory(PORTABLE_FACTORY_ID, new PortableFactory() {
@Override
public Portable create(int classId) {
return new NamedPortable();
}
}).setPortableVersion(5).build();
Portable p1 = new NamedPortableV2("test", 456, 500);
Object o1 = new DataDataSerializable(ss.toData(p1));
Data data = ss.toData(o1);
DataDataSerializable o2 = ss2.toObject(data);
assertEquals(o1, o2);
Portable p2 = ss2.toObject(o2.data);
assertEquals(p1, p2);
}
use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class PortableTest method testRawDataWithoutRegistering.
@Test
public void testRawDataWithoutRegistering() {
final SerializationService serializationService = createSerializationService(1);
RawDataPortable p = new RawDataPortable(System.currentTimeMillis(), "test chars".toCharArray(), new NamedPortable("named portable", 34567), 9876, "Testing raw portable", new ByteArrayDataSerializable("test bytes".getBytes()));
final Data data = serializationService.toData(p);
assertEquals(p, serializationService.toObject(data));
}
Aggregations