Search in sources :

Example 6 with CompactReader

use of com.hazelcast.nio.serialization.compact.CompactReader 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

CompactReader (com.hazelcast.nio.serialization.compact.CompactReader)6 CompactWriter (com.hazelcast.nio.serialization.compact.CompactWriter)5 Nonnull (javax.annotation.Nonnull)5 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)4 SerializationConfig (com.hazelcast.config.SerializationConfig)3 Data (com.hazelcast.internal.serialization.Data)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 EmployeeDTO (example.serialization.EmployeeDTO)3 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)3 Test (org.junit.Test)3 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 Config (com.hazelcast.config.Config)1 DefaultCompactReader (com.hazelcast.internal.serialization.impl.compact.DefaultCompactReader)1 FieldDescriptor (com.hazelcast.internal.serialization.impl.compact.FieldDescriptor)1 Schema (com.hazelcast.internal.serialization.impl.compact.Schema)1