use of example.serialization.EmployeeDTO in project hazelcast by hazelcast.
the class CompactStreamSerializerTest method testWithExplicitSerializer.
@Test
public void testWithExplicitSerializer() {
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);
Object object = serializationService.toObject(data);
EmployeeDTO actual = (EmployeeDTO) object;
assertEquals(employeeDTO, actual);
}
use of example.serialization.EmployeeDTO in project hazelcast by hazelcast.
the class CompactWithSchemaStreamSerializerTest method testFromData.
@Test
public void testFromData() {
SerializationService serializationService = createSerializationService();
EmployeeDTO employeeDTO = new EmployeeDTO(30, 102310312);
Data employeeData = serializationService.toDataWithSchema(employeeDTO);
Data data = serializationService.toDataWithSchema(employeeData);
// Create a second schema service so that schemas are not shared accross these two
// This is to make sure that toObject call will use the schema in the data
SerializationService serializationService2 = createSerializationService();
EmployeeDTO actual = serializationService2.toObject(data);
assertEquals(employeeDTO, actual);
}
use of example.serialization.EmployeeDTO in project hazelcast by hazelcast.
the class CompactTestUtil method verifyExplicitSerializerIsUsed.
public static void verifyExplicitSerializerIsUsed(SerializationConfig serializationConfig) {
SerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(CompactTestUtil.createInMemorySchemaService()).setConfig(serializationConfig).build();
EmployeeDTO object = new EmployeeDTO(1, 1);
Data data = serializationService.toData(object);
EmployeeDTO deserializedObject = serializationService.toObject(data);
assertEquals(object, deserializedObject);
}
use of example.serialization.EmployeeDTO in project hazelcast by hazelcast.
the class CompactStreamSerializerTest method testDefaultsReflection.
@Test
public void testDefaultsReflection() {
SerializationService serializationService = createSerializationService();
EmployeeDTO employeeDTO = new EmployeeDTO(30, 102310312);
Data data = serializationService.toData(employeeDTO);
EmployeeDTO object = serializationService.toObject(data);
assertEquals(employeeDTO, object);
}
use of example.serialization.EmployeeDTO in project hazelcast by hazelcast.
the class CompactStreamSerializerTest method testSchemaEvolution_fieldRemoved.
@Test
public void testSchemaEvolution_fieldRemoved() {
SerializationConfig serializationConfig = new SerializationConfig();
// Using this registration to mimic schema evolution. This is usage is not advised.
serializationConfig.getCompactSerializationConfig().setEnabled(true).register(EmployeeDTO.class, EmployeeDTO.class.getName(), new CompactSerializer<EmployeeDTO>() {
@Nonnull
@Override
public EmployeeDTO read(@Nonnull CompactReader in) {
throw new UnsupportedOperationException("We will not read from here on this test");
}
@Override
public void write(@Nonnull CompactWriter out, @Nonnull EmployeeDTO object) {
out.writeInt32("age", object.getAge());
}
});
SerializationService serializationService = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).setSchemaService(schemaService).build();
EmployeeDTO expected = new EmployeeDTO(20, 102310312);
Data data = serializationService.toData(expected);
SerializationService serializationService2 = createSerializationService();
EmployeeDTO actual = serializationService2.toObject(data);
assertEquals(expected.getAge(), actual.getAge());
assertEquals(0, actual.getId());
}
Aggregations