Search in sources :

Example 41 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class CompactNullablePrimitiveInteroperabilityTest method testWriteNullReadPrimitiveThrowsException.

@Test
public void testWriteNullReadPrimitiveThrowsException() {
    GenericRecordBuilder builder = compact("test");
    builder.setNullableBoolean("boolean", null);
    builder.setNullableInt8("byte", null);
    builder.setNullableInt16("short", null);
    builder.setNullableInt32("int", null);
    builder.setNullableInt64("long", null);
    builder.setNullableFloat32("float", null);
    builder.setNullableFloat64("double", null);
    builder.setArrayOfNullableBoolean("booleans", new Boolean[] { null, false });
    builder.setArrayOfNullableInt8("bytes", new Byte[] { 1, null });
    builder.setArrayOfNullableInt16("shorts", new Short[] { null, 2 });
    builder.setArrayOfNullableInt32("ints", new Integer[] { 1, null });
    builder.setArrayOfNullableInt64("longs", new Long[] { null, 2L });
    builder.setArrayOfNullableFloat32("floats", new Float[] { null, 2F });
    builder.setArrayOfNullableFloat64("doubles", new Double[] { 1.0, null });
    GenericRecord record = builder.build();
    assertReadNullAsPrimitiveThrowsException(record);
    SerializationService serializationService = createSerializationService();
    Data data = serializationService.toData(record);
    GenericRecord serializedRecord = serializationService.toObject(data);
    assertTrue(serializedRecord instanceof CompactInternalGenericRecord);
    assertReadNullAsPrimitiveThrowsException(serializedRecord);
}
Also used : GenericRecordBuilder(com.hazelcast.nio.serialization.GenericRecordBuilder) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class CompactNullablePrimitiveInteroperabilityTest method testWritePrimitiveReadNullable.

@Test
public void testWritePrimitiveReadNullable() {
    GenericRecordBuilder builder = compact("test");
    builder.setBoolean("boolean", true);
    builder.setInt8("byte", (byte) 2);
    builder.setInt16("short", (short) 4);
    builder.setInt32("int", 8);
    builder.setInt64("long", 4444L);
    builder.setFloat32("float", 8321.321F);
    builder.setFloat64("double", 41231.32);
    builder.setArrayOfBoolean("booleans", new boolean[] { true, false });
    builder.setArrayOfInt8("bytes", new byte[] { 1, 2 });
    builder.setArrayOfInt16("shorts", new short[] { 1, 4 });
    builder.setArrayOfInt32("ints", new int[] { 1, 8 });
    builder.setArrayOfInt64("longs", new long[] { 1, 4444L });
    builder.setArrayOfFloat32("floats", new float[] { 1, 8321.321F });
    builder.setArrayOfFloat64("doubles", new double[] { 41231.32, 2 });
    GenericRecord record = builder.build();
    assertTrue(record instanceof DeserializedGenericRecord);
    assertReadAsNullable(record);
    SerializationService serializationService = createSerializationService();
    Data data = serializationService.toData(record);
    GenericRecord serializedRecord = serializationService.toObject(data);
    assertTrue(serializedRecord instanceof CompactInternalGenericRecord);
    assertReadAsNullable(serializedRecord);
}
Also used : GenericRecordBuilder(com.hazelcast.nio.serialization.GenericRecordBuilder) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 43 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class CompactStreamSerializerTest method testDefaultsReflection_recursive.

@Test
public void testDefaultsReflection_recursive() {
    SerializationService serializationService = createSerializationService();
    NodeDTO node = new NodeDTO(new NodeDTO(new NodeDTO(2), 1), 0);
    Data data = serializationService.toData(node);
    Object object = serializationService.toObject(data);
    NodeDTO o = (NodeDTO) object;
    assertEquals(node, o);
}
Also used : InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) NodeDTO(example.serialization.NodeDTO) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class CompactStreamSerializerTest method testDefaultsReflection_insideCollection.

@Test
public void testDefaultsReflection_insideCollection() {
    SerializationService serializationService = createSerializationService();
    NodeDTO node = new NodeDTO(new NodeDTO(new NodeDTO(2), 1), 0);
    EmployeeDTO employeeDTO = new EmployeeDTO(30, 102310312);
    long[] ids = new long[] { 22, 44 };
    EmployeeDTO[] employeeDTOS = new EmployeeDTO[5];
    for (int j = 0; j < employeeDTOS.length; j++) {
        employeeDTOS[j] = new EmployeeDTO(20 + j, j * 100);
    }
    EmployerDTO employerDTO = new EmployerDTO("nbss", 40, HIRING, ids, employeeDTO, employeeDTOS);
    ArrayList<Object> expected = new ArrayList<>();
    expected.add(node);
    expected.add(employeeDTO);
    expected.add(employerDTO);
    Data data = serializationService.toData(expected);
    ArrayList<Object> arrayList = serializationService.toObject(data);
    assertEquals(node, arrayList.get(0));
    assertEquals(employeeDTO, arrayList.get(1));
    assertEquals(employerDTO, arrayList.get(2));
}
Also used : EmployeeDTO(example.serialization.EmployeeDTO) ExternalizableEmployeeDTO(example.serialization.ExternalizableEmployeeDTO) ArrayList(java.util.ArrayList) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) NodeDTO(example.serialization.NodeDTO) EmployerDTO(example.serialization.EmployerDTO) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class CompactStreamSerializerTest method testDeserializedToGenericRecordWhenClassNotFoundOnClassPath.

@Test
public void testDeserializedToGenericRecordWhenClassNotFoundOnClassPath() {
    SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.getCompactSerializationConfig().setEnabled(true).register(EmployeeDTO.class, "employee", new EmployeeDTOSerializer());
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(serializationConfig).build();
    EmployeeDTO employeeDTO = new EmployeeDTO(30, 102310312);
    Data data = serializationService.toData(employeeDTO);
    SerializationConfig serializationConfig2 = new SerializationConfig();
    serializationConfig2.getCompactSerializationConfig().setEnabled(true);
    SerializationService readerService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(serializationConfig2).build();
    GenericRecord genericRecord = readerService.toObject(data);
    assertEquals(employeeDTO.getAge(), genericRecord.getInt32("age"));
    assertEquals(employeeDTO.getId(), genericRecord.getInt64("id"));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) EmployeeDTO(example.serialization.EmployeeDTO) ExternalizableEmployeeDTO(example.serialization.ExternalizableEmployeeDTO) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) EmployeeDTOSerializer(example.serialization.EmployeeDTOSerializer) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) CompactTestUtil.createCompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SerializationService (com.hazelcast.internal.serialization.SerializationService)170 Data (com.hazelcast.internal.serialization.Data)117 Test (org.junit.Test)100 QuickTest (com.hazelcast.test.annotation.QuickTest)99 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)50 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)43 ArrayList (java.util.ArrayList)15 SerializationConfig (com.hazelcast.config.SerializationConfig)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Node (com.hazelcast.instance.impl.Node)12 CustomSerializationTest (com.hazelcast.internal.serialization.impl.CustomSerializationTest)12 Accessors.getNode (com.hazelcast.test.Accessors.getNode)12 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)11 EmployeeDTO (example.serialization.EmployeeDTO)11 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)11 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)8 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8