Search in sources :

Example 91 with DefaultSerializationServiceBuilder

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());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 92 with DefaultSerializationServiceBuilder

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));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 93 with DefaultSerializationServiceBuilder

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);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) ArrayList(java.util.ArrayList) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 94 with DefaultSerializationServiceBuilder

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);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) Data(com.hazelcast.internal.serialization.Data) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) Before(org.junit.Before)

Example 95 with DefaultSerializationServiceBuilder

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));
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) Operation(com.hazelcast.spi.impl.operationservice.Operation) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)197 Test (org.junit.Test)146 QuickTest (com.hazelcast.test.annotation.QuickTest)119 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)91 Data (com.hazelcast.internal.serialization.Data)56 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)56 SerializationService (com.hazelcast.internal.serialization.SerializationService)50 SerializationService (com.hazelcast.spi.serialization.SerializationService)40 SerializationConfig (com.hazelcast.config.SerializationConfig)36 Before (org.junit.Before)22 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)20 HeapData (com.hazelcast.internal.serialization.impl.HeapData)18 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)16 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)15 CustomSerializationTest (com.hazelcast.internal.serialization.impl.CustomSerializationTest)14 ParallelTest (com.hazelcast.test.annotation.ParallelTest)13 Parameters (junitparams.Parameters)13 ArrayList (java.util.ArrayList)12 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)10 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)9