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"));
}
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"));
}
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);
}
}
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);
}
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"));
}
Aggregations