use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class SerializationTest method testLinkedListSerialization.
@Test
public void testLinkedListSerialization() {
SerializationService ss = new DefaultSerializationServiceBuilder().build();
LinkedList<Person> linkedList = new LinkedList<Person>();
linkedList.add(new Person(35, 180, 100, "Orhan", null));
linkedList.add(new Person(12, 120, 60, "Osman", null));
Data data = ss.toData(linkedList);
LinkedList deserialized = ss.toObject(data);
assertTrue("Objects are not identical!", linkedList.equals(deserialized));
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class SerializationTest method testGlobalSerializer_withoutOverrideJavaSerializable.
@Test
public void testGlobalSerializer_withoutOverrideJavaSerializable() {
GlobalSerializerConfig globalSerializerConfig = new GlobalSerializerConfig();
globalSerializerConfig.setOverrideJavaSerialization(false);
final AtomicInteger writeCounter = new AtomicInteger();
final AtomicInteger readCounter = new AtomicInteger();
SerializationConfig serializationConfig = new SerializationConfig().setGlobalSerializerConfig(globalSerializerConfig.setImplementation(new StreamSerializer<Object>() {
@Override
public void write(ObjectDataOutput out, Object v) throws IOException {
writeCounter.incrementAndGet();
out.writeUTF(((DummyValue) v).s);
out.writeInt(((DummyValue) v).k);
}
@Override
public Object read(ObjectDataInput in) throws IOException {
readCounter.incrementAndGet();
return new DummyValue(in.readUTF(), in.readInt());
}
public int getTypeId() {
return 123;
}
public void destroy() {
}
}));
SerializationService ss1 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
DummyValue value = new DummyValue("test", 111);
Data data1 = ss1.toData(value);
Data data2 = ss1.toData(new Foo());
Assert.assertNotNull(data1);
Assert.assertNotNull(data2);
assertEquals(1, writeCounter.get());
SerializationService ss2 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
Object o1 = ss2.toObject(data1);
Object o2 = ss2.toObject(data2);
Assert.assertEquals(value, o1);
Assert.assertNotNull(o2);
assertEquals(1, readCounter.get());
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class PartitionTableViewTest method test_writeAndReadData.
@Test
public void test_writeAndReadData() throws Exception {
InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
PartitionTableView table1 = createRandomPartitionTable();
BufferObjectDataOutput out = serializationService.createObjectDataOutput();
PartitionTableView.writeData(table1, out);
BufferObjectDataInput in = serializationService.createObjectDataInput(out.toByteArray());
PartitionTableView table2 = PartitionTableView.readData(in);
assertEquals(table1, table2);
assertEquals(table1.hashCode(), table2.hashCode());
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder 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.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class PortableClassVersionTest method testDifferentClassAndServiceVersions.
@Test
public void testDifferentClassAndServiceVersions() {
SerializationService serializationService = new DefaultSerializationServiceBuilder().setPortableVersion(1).addPortableFactory(FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new NamedPortable();
}
}).build();
SerializationService serializationService2 = new DefaultSerializationServiceBuilder().setPortableVersion(2).addPortableFactory(FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new NamedPortableV2();
}
}).build();
testDifferentClassVersions(serializationService, serializationService2);
}
Aggregations