use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableTest method testClassDefinition_getNestedField.
@Test
public void testClassDefinition_getNestedField() throws IOException {
InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
PortableContext portableContext = serializationService.getPortableContext();
ChildPortableObject child = new ChildPortableObject(System.nanoTime());
ParentPortableObject parent = new ParentPortableObject(System.currentTimeMillis(), child);
GrandParentPortableObject grandParent = new GrandParentPortableObject(System.nanoTime(), parent);
Data data = serializationService.toData(grandParent);
ClassDefinition classDefinition = portableContext.lookupClassDefinition(data);
FieldDefinition fd = portableContext.getFieldDefinition(classDefinition, "child");
assertNotNull(fd);
assertEquals(FieldType.PORTABLE, fd.getType());
fd = portableContext.getFieldDefinition(classDefinition, "child.child");
assertNotNull(fd);
assertEquals(FieldType.PORTABLE, fd.getType());
fd = portableContext.getFieldDefinition(classDefinition, "child.child.timestamp");
assertNotNull(fd);
assertEquals(FieldType.LONG, fd.getType());
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class AbstractGenericRecordIntegrationTest method getInconsistentNestedGenericRecords.
private BiTuple<GenericRecord, GenericRecord> getInconsistentNestedGenericRecords() {
ClassDefinition childCd = new ClassDefinitionBuilder(1, 1).addIntField("a").build();
ClassDefinition inconsistentChildCd = new ClassDefinitionBuilder(1, 1).addBooleanField("a").build();
ClassDefinition namedPortableClassDefinition = new ClassDefinitionBuilder(1, 2).addStringField("name").addPortableField("child", childCd).build();
ClassDefinition inconsistentNamedPortableClassDefinition = new ClassDefinitionBuilder(1, 2).addStringField("name").addPortableField("child", inconsistentChildCd).build();
GenericRecord record = GenericRecordBuilder.portable(namedPortableClassDefinition).setString("name", "foo").setGenericRecord("child", GenericRecordBuilder.portable(childCd).setInt32("a", 1).build()).build();
GenericRecord otherRecord = GenericRecordBuilder.portable(inconsistentNamedPortableClassDefinition).setString("name", "foo").setGenericRecord("child", GenericRecordBuilder.portable(inconsistentChildCd).setBoolean("a", false).build()).build();
return BiTuple.of(record, otherRecord);
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class GenericRecordBuilderTest method testOverwritingSameFieldMultipleTimes.
@Test
public void testOverwritingSameFieldMultipleTimes() {
ClassDefinition namedPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("name").addIntField("myint").build();
GenericRecord record = GenericRecordBuilder.portable(namedPortableClassDefinition).setString("name", "foo").setInt32("myint", 123).build();
GenericRecordBuilder builder = record.cloneWithBuilder().setString("name", "foo2");
assertThrows(HazelcastSerializationException.class, () -> builder.setString("name", "foo3"));
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class GenericRecordBuilderTest method testWritingToFieldWithWrongType.
@Test
public void testWritingToFieldWithWrongType() {
ClassDefinition classDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("name").addIntField("myint").build();
GenericRecordBuilder builder = GenericRecordBuilder.portable(classDefinition);
assertThrows(HazelcastSerializationException.class, () -> builder.setInt32("name", 1));
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class BinaryCompatibilityFileGenerator method createSerializationService.
@SuppressWarnings("checkstyle:avoidnestedblocks")
private static SerializationService createSerializationService(ByteOrder byteOrder) {
SerializationConfig config = new SerializationConfig();
{
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomByteArraySerializer()).setTypeClass(CustomByteArraySerializable.class);
config.addSerializerConfig(serializerConfig);
}
{
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomStreamSerializer()).setTypeClass(CustomStreamSerializable.class);
config.addSerializerConfig(serializerConfig);
}
config.setByteOrder(byteOrder);
ClassDefinition classDefinition = new ClassDefinitionBuilder(ReferenceObjects.PORTABLE_FACTORY_ID, ReferenceObjects.INNER_PORTABLE_CLASS_ID).addIntField("i").addFloatField("f").build();
return new DefaultSerializationServiceBuilder().setConfig(config).setVersion(VERSION).addPortableFactory(ReferenceObjects.PORTABLE_FACTORY_ID, new APortableFactory()).addDataSerializableFactory(ReferenceObjects.IDENTIFIED_DATA_SERIALIZABLE_FACTORY_ID, new ADataSerializableFactory()).addClassDefinition(classDefinition).build();
}
Aggregations