Search in sources :

Example 16 with EmployeeDTO

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);
}
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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with EmployeeDTO

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

Example 18 with EmployeeDTO

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);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ExternalizableEmployeeDTO(example.serialization.ExternalizableEmployeeDTO) EmployeeDTO(example.serialization.EmployeeDTO) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data)

Example 19 with EmployeeDTO

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);
}
Also used : EmployeeDTO(example.serialization.EmployeeDTO) ExternalizableEmployeeDTO(example.serialization.ExternalizableEmployeeDTO) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with EmployeeDTO

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());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) CompactWriter(com.hazelcast.nio.serialization.compact.CompactWriter) EmployeeDTO(example.serialization.EmployeeDTO) ExternalizableEmployeeDTO(example.serialization.ExternalizableEmployeeDTO) CompactReader(com.hazelcast.nio.serialization.compact.CompactReader) Nonnull(javax.annotation.Nonnull) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

EmployeeDTO (example.serialization.EmployeeDTO)21 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)20 QuickTest (com.hazelcast.test.annotation.QuickTest)20 Test (org.junit.Test)20 Data (com.hazelcast.internal.serialization.Data)11 SerializationService (com.hazelcast.internal.serialization.SerializationService)11 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)11 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)10 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)6 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)6 SerializationConfig (com.hazelcast.config.SerializationConfig)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 EmployerDTO (example.serialization.EmployerDTO)4 CompactReader (com.hazelcast.nio.serialization.compact.CompactReader)3 CompactWriter (com.hazelcast.nio.serialization.compact.CompactWriter)3 Nonnull (javax.annotation.Nonnull)3 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)2 SqlResult (com.hazelcast.sql.SqlResult)2 EmployeeDTOSerializer (example.serialization.EmployeeDTOSerializer)2 NodeDTO (example.serialization.NodeDTO)2