Search in sources :

Example 16 with GenericRecordBuilder

use of com.hazelcast.nio.serialization.GenericRecordBuilder in project hazelcast by hazelcast.

the class CompactStreamSerializerTest method testSchemaEvolution_GenericRecord.

@Test
public void testSchemaEvolution_GenericRecord() {
    SerializationService serializationService = createSerializationService();
    GenericRecordBuilder builder = compact("fooBarTypeName");
    builder.setInt32("foo", 1);
    builder.setInt64("bar", 1231L);
    GenericRecord expectedGenericRecord = builder.build();
    Data data = serializationService.toData(expectedGenericRecord);
    SerializationService serializationService2 = createSerializationService();
    GenericRecordBuilder builder2 = compact("fooBarTypeName");
    builder2.setInt32("foo", 1);
    builder2.setInt64("bar", 1231L);
    builder2.setString("foobar", "new field");
    serializationService2.toData(builder2.build());
    Object object = serializationService2.toObject(data);
    GenericRecord genericRecord = (GenericRecord) object;
    assertFalse(genericRecord.hasField("foobar"));
    assertEquals(1, genericRecord.getInt32("foo"));
    assertEquals(1231L, genericRecord.getInt64("bar"));
}
Also used : InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) GenericRecordBuilder(com.hazelcast.nio.serialization.GenericRecordBuilder) 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

GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 Test (org.junit.Test)15 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)11 Data (com.hazelcast.internal.serialization.Data)7 SerializationService (com.hazelcast.internal.serialization.SerializationService)7 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)7 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)6 CompactTestUtil.createCompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord)5 InternalGenericRecord (com.hazelcast.internal.serialization.impl.InternalGenericRecord)4 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3