use of com.hazelcast.internal.serialization.InternalSerializationService in project hazelcast by hazelcast.
the class PortableClassVersionTest method testDifferentClassAndServiceVersionsUsingDataWriteAndRead.
@Test
public void testDifferentClassAndServiceVersionsUsingDataWriteAndRead() throws Exception {
InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().setPortableVersion(1).addPortableFactory(FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new NamedPortable();
}
}).build();
InternalSerializationService serializationService2 = new DefaultSerializationServiceBuilder().setPortableVersion(2).addPortableFactory(FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new NamedPortableV2();
}
}).build();
testDifferentClassVersionsUsingDataWriteAndRead(serializationService, serializationService2);
}
use of com.hazelcast.internal.serialization.InternalSerializationService in project hazelcast by hazelcast.
the class PortableTest method testRawData.
@Test
public void testRawData() {
int portableVersion = 1;
final InternalSerializationService 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()));
ClassDefinitionBuilder builder = new ClassDefinitionBuilder(p.getFactoryId(), p.getClassId(), portableVersion);
builder.addLongField("l").addCharArrayField("c").addPortableField("p", createNamedPortableClassDefinition(portableVersion));
serializationService.getPortableContext().registerClassDefinition(builder.build());
final Data data = serializationService.toData(p);
assertEquals(p, serializationService.toObject(data));
}
use of com.hazelcast.internal.serialization.InternalSerializationService in project hazelcast by hazelcast.
the class PortableTest method testRawDataInvalidWrite.
@Test(expected = HazelcastSerializationException.class)
public void testRawDataInvalidWrite() {
int portableVersion = 1;
final InternalSerializationService serializationService = createSerializationService(1);
RawDataPortable p = new InvalidRawDataPortable(System.currentTimeMillis(), "test chars".toCharArray(), new NamedPortable("named portable", 34567), 9876, "Testing raw portable", new ByteArrayDataSerializable("test bytes".getBytes()));
ClassDefinitionBuilder builder = new ClassDefinitionBuilder(p.getFactoryId(), p.getClassId(), portableVersion);
builder.addLongField("l").addCharArrayField("c").addPortableField("p", createNamedPortableClassDefinition(portableVersion));
serializationService.getPortableContext().registerClassDefinition(builder.build());
final Data data = serializationService.toData(p);
assertEquals(p, serializationService.toObject(data));
}
use of com.hazelcast.internal.serialization.InternalSerializationService in project hazelcast by hazelcast.
the class PortableTest method testClassDefinitionLookupBigEndianHeapData.
@Test
public void testClassDefinitionLookupBigEndianHeapData() throws IOException {
InternalSerializationService ss = new DefaultSerializationServiceBuilder().setByteOrder(ByteOrder.BIG_ENDIAN).build();
testClassDefinitionLookup(ss);
}
use of com.hazelcast.internal.serialization.InternalSerializationService in project hazelcast by hazelcast.
the class PortableTest method testSerializationService_createPortableReader.
@Test
public void testSerializationService_createPortableReader() throws IOException {
InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
long timestamp1 = System.nanoTime();
ChildPortableObject child = new ChildPortableObject(timestamp1);
long timestamp2 = System.currentTimeMillis();
ParentPortableObject parent = new ParentPortableObject(timestamp2, child);
long timestamp3 = timestamp1 + timestamp2;
GrandParentPortableObject grandParent = new GrandParentPortableObject(timestamp3, parent);
Data data = serializationService.toData(grandParent);
PortableReader reader = serializationService.createPortableReader(data);
assertEquals(grandParent.timestamp, reader.readLong("timestamp"));
assertEquals(parent.timestamp, reader.readLong("child.timestamp"));
assertEquals(child.timestamp, reader.readLong("child.child.timestamp"));
}
Aggregations