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);
}
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);
}
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);
}
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));
}
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"));
}
Aggregations