Search in sources :

Example 66 with ClassDefinition

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());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.internal.serialization.impl.CustomSerializationTest) Test(org.junit.Test)

Example 67 with ClassDefinition

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);
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Example 68 with ClassDefinition

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"));
}
Also used : GenericRecordBuilder(com.hazelcast.nio.serialization.GenericRecordBuilder) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 69 with ClassDefinition

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));
}
Also used : GenericRecordBuilder(com.hazelcast.nio.serialization.GenericRecordBuilder) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 70 with ClassDefinition

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();
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializerConfig(com.hazelcast.config.SerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Aggregations

ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)70 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)37 Test (org.junit.Test)25 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)16 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)7 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)7 Parameters (junitparams.Parameters)7 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)6 MappingField (com.hazelcast.sql.impl.schema.MappingField)6 Portable (com.hazelcast.nio.serialization.Portable)5 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 SerializationConfig (com.hazelcast.config.SerializationConfig)3 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)3 Data (com.hazelcast.internal.serialization.Data)3 BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)3