Search in sources :

Example 31 with ClassDefinition

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

the class GenericRecordTest method testUnsupportedMethods.

@Test
public void testUnsupportedMethods() {
    ClassDefinition namedPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("name").addIntField("myint").build();
    GenericRecordBuilder builder = GenericRecordBuilder.portable(namedPortableClassDefinition).setString("name", "foo").setInt32("myint", 123);
    GenericRecord record = builder.build();
    assertThrows(UnsupportedOperationException.class, () -> builder.setNullableBoolean("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setNullableInt8("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setNullableInt16("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setNullableInt32("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setNullableInt64("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setNullableFloat32("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setNullableFloat64("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setArrayOfNullableBoolean("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setArrayOfNullableInt8("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setArrayOfNullableInt16("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setArrayOfNullableInt32("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setArrayOfNullableInt64("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setArrayOfNullableFloat32("name", null));
    assertThrows(UnsupportedOperationException.class, () -> builder.setArrayOfNullableFloat64("name", null));
    assertThrows(UnsupportedOperationException.class, () -> record.getNullableBoolean("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getNullableInt8("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getNullableInt16("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getNullableInt32("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getNullableInt64("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getNullableFloat32("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getNullableFloat64("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getArrayOfNullableBoolean("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getArrayOfNullableInt8("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getArrayOfNullableInt16("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getArrayOfNullableInt32("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getArrayOfNullableInt64("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getArrayOfNullableFloat32("name"));
    assertThrows(UnsupportedOperationException.class, () -> record.getArrayOfNullableFloat64("name"));
}
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 32 with ClassDefinition

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

the class GenericRecordBuilderTest method testWritingSameFieldMultipleTimes.

@Test
public void testWritingSameFieldMultipleTimes() {
    ClassDefinition namedPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("name").addIntField("myint").build();
    GenericRecordBuilder builder = GenericRecordBuilder.portable(namedPortableClassDefinition);
    builder.setString("name", "foo");
    builder.setInt32("myint", 123);
    assertThrows(HazelcastSerializationException.class, () -> builder.setString("name", "foo2"));
}
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 33 with ClassDefinition

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

the class GenericRecordBuilderTest method testWriteReadGenericRecordToObjectDataInput.

@Test
public void testWriteReadGenericRecordToObjectDataInput() throws IOException {
    ClassDefinitionBuilder classDefinitionBuilder = new ClassDefinitionBuilder(1, 1);
    classDefinitionBuilder.addIntField("age");
    classDefinitionBuilder.addStringField("name");
    ClassDefinition classDefinition = classDefinitionBuilder.build();
    InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    BufferObjectDataOutput objectDataOutput = serializationService.createObjectDataOutput();
    List<GenericRecord> list = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        GenericRecord record = GenericRecordBuilder.portable(classDefinition).setInt32("age", i).setString("name", " " + i).build();
        objectDataOutput.writeObject(record);
        list.add(record);
    }
    byte[] bytes = objectDataOutput.toByteArray();
    BufferObjectDataInput objectDataInput = serializationService.createObjectDataInput(bytes);
    for (int i = 0; i < 10; i++) {
        GenericRecord record = objectDataInput.readObject();
        assertEquals(list.get(i), record);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) ArrayList(java.util.ArrayList) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 34 with ClassDefinition

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

the class GenericRecordBuilderTest method testUnwrittenFieldsThrowException.

@Test
public void testUnwrittenFieldsThrowException() {
    ClassDefinition classDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("name").addIntField("myint").build();
    GenericRecordBuilder builder = GenericRecordBuilder.portable(classDefinition);
    builder.setInt32("myint", 1);
    assertThrows(HazelcastSerializationException.class, builder::build);
}
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 35 with ClassDefinition

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

the class GenericRecordBuilderTest method testWritingToNonExistingField.

@Test
public void testWritingToNonExistingField() {
    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.setString("nonExistingField", "foo3"));
}
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)

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