use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class RabinFingerprintTest method testRabinFingerprintIsConsistentWithWrittenData.
@Test
public void testRabinFingerprintIsConsistentWithWrittenData() throws IOException {
SchemaWriter writer = new SchemaWriter("typeName");
writer.addField(new FieldDescriptor("a", FieldKind.BOOLEAN));
writer.addField(new FieldDescriptor("b", FieldKind.ARRAY_OF_BOOLEAN));
writer.addField(new FieldDescriptor("c", FieldKind.TIMESTAMP_WITH_TIMEZONE));
Schema schema = writer.build();
InternalSerializationService internalSerializationService = new DefaultSerializationServiceBuilder().setByteOrder(ByteOrder.LITTLE_ENDIAN).build();
BufferObjectDataOutput output = internalSerializationService.createObjectDataOutput();
schema.writeData(output);
long fingerprint64 = RabinFingerprint.fingerprint64(output.toByteArray());
assertEquals(fingerprint64, schema.getSchemaId());
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class ExplicitClassDefinitionRegistrationTest method test_classesWithSameClassIdInDifferentFactories.
@Test
public void test_classesWithSameClassIdInDifferentFactories() {
SerializationService ss = new DefaultSerializationServiceBuilder().addPortableFactory(MyPortableFactory1.ID, new MyPortableFactory1()).addPortableFactory(MyPortableFactory2.ID, new MyPortableFactory2()).addClassDefinition(new ClassDefinitionBuilder(MyPortableFactory1.ID, MyPortable1.ID).addStringField("stringField").build()).addClassDefinition(new ClassDefinitionBuilder(MyPortableFactory2.ID, MyPortable2.ID).addIntField("intField").build()).build();
MyPortable1 object = new MyPortable1("test");
Data data = ss.toData(object);
assertEquals(object, ss.toObject(data));
MyPortable2 object2 = new MyPortable2(1);
Data data2 = ss.toData(object2);
assertEquals(object2, ss.toObject(data2));
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class GenericRecordBuilderTest method testWriteReadGenericRecordToObjectDataInput.
@Test
public void testWriteReadGenericRecordToObjectDataInput() throws IOException {
ClassDefinitionBuilder classDefinitionBuilder = new ClassDefinitionBuilder(1, 1);
classDefinitionBuilder.addIntField("age");
classDefinitionBuilder.addStringField("name");
ClassDefinition classDefinition = classDefinitionBuilder.build();
InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
BufferObjectDataOutput objectDataOutput = serializationService.createObjectDataOutput();
List<GenericRecord> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
GenericRecord record = GenericRecordBuilder.portable(classDefinition).setInt32("age", i).setString("name", " " + i).build();
objectDataOutput.writeObject(record);
list.add(record);
}
byte[] bytes = objectDataOutput.toByteArray();
BufferObjectDataInput objectDataInput = serializationService.createObjectDataInput(bytes);
for (int i = 0; i < 10; i++) {
GenericRecord record = objectDataInput.readObject();
assertEquals(list.get(i), record);
}
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class MorphingPortableReaderTest method before.
@Before
public void before() throws Exception {
service1 = (SerializationServiceV1) new DefaultSerializationServiceBuilder().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new MorphingBasePortable();
}
}).build();
service2 = (SerializationServiceV1) new DefaultSerializationServiceBuilder().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {
public Portable create(int classId) {
return new MorphingPortable();
}
}).build();
Data data = service1.toData(new MorphingBasePortable((byte) 1, true, (char) 2, (short) 3, 4, 5, 1f, 2d, "test"));
BufferObjectDataInput in = service2.createObjectDataInput(data);
PortableSerializer portableSerializer = service2.getPortableSerializer();
reader = portableSerializer.createMorphingReader(in);
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class CollectionTxnUtilTest method testWriteRead.
@Test
public void testWriteRead() throws IOException {
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
BufferObjectDataOutput out = ss.createObjectDataOutput();
CollectionTxnUtil.write(out, operationList);
BufferObjectDataInput in = ss.createObjectDataInput(out.toByteArray());
List<Operation> resultList = CollectionTxnUtil.read(in);
assertEquals(operationList.size(), resultList.size());
for (int i = 0; i < operationList.size(); i++) {
assertEquals(operationList.get(i), resultList.get(i));
}
}
Aggregations