use of com.hazelcast.nio.serialization.GenericRecord in project hazelcast by hazelcast.
the class AbstractGenericRecordIntegrationTest method getInconsistentGenericRecords.
private BiTuple<GenericRecord, GenericRecord> getInconsistentGenericRecords() {
ClassDefinition namedPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("name").addIntField("myint").build();
ClassDefinition inConsistentNamedPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("WrongName").addIntField("myint").build();
GenericRecord record = GenericRecordBuilder.portable(namedPortableClassDefinition).setString("name", "foo").setInt32("myint", 123).build();
GenericRecord inConsistentNamedRecord = GenericRecordBuilder.portable(inConsistentNamedPortableClassDefinition).setString("WrongName", "foo").setInt32("myint", 123).build();
return BiTuple.of(record, inConsistentNamedRecord);
}
use of com.hazelcast.nio.serialization.GenericRecord 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.GenericRecord in project hazelcast by hazelcast.
the class CompactFormatIntegrationTest method testEntryProcessor.
@Test
public void testEntryProcessor() {
IMap<Integer, Object> map = instance1.getMap("test");
for (int i = 0; i < 100; i++) {
if (serverDoesNotHaveClasses) {
GenericRecord record = GenericRecordBuilder.compact("employee").setInt32("age", i).setInt64("id", 102310312).build();
map.put(i, record);
} else {
EmployeeDTO employeeDTO = new EmployeeDTO(i, 102310312);
map.put(i, employeeDTO);
}
}
IMap map2 = instance2.getMap("test");
if (serverDoesNotHaveClasses) {
map2.executeOnEntries(new GenericIncreaseAgeEntryProcessor());
} else {
map2.executeOnEntries(new IncreaseAgeEntryProcessor());
}
for (int i = 0; i < 100; i++) {
if (serverDoesNotHaveClasses) {
GenericRecord record = (GenericRecord) map2.get(i);
assertEquals(record.getInt32("age"), 1000 + i);
} else {
EmployeeDTO employeeDTO = (EmployeeDTO) map.get(i);
assertEquals(employeeDTO.getAge(), 1000 + i);
}
}
}
use of com.hazelcast.nio.serialization.GenericRecord 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.GenericRecord in project hazelcast by hazelcast.
the class SqlPortableTest method when_noFieldsResolved_then_wholeValueMapped.
@Test
public void when_noFieldsResolved_then_wholeValueMapped() {
String name = randomName();
sqlService.execute("CREATE MAPPING " + name + ' ' + "TYPE " + IMapSqlConnector.TYPE_NAME + ' ' + "OPTIONS (" + '\'' + OPTION_KEY_FORMAT + "'='" + PORTABLE_FORMAT + '\'' + ", '" + OPTION_KEY_FACTORY_ID + "'='" + EMPTY_TYPES_FACTORY_ID + '\'' + ", '" + OPTION_KEY_CLASS_ID + "'='" + EMPTY_TYPES_CLASS_ID + '\'' + ", '" + OPTION_KEY_CLASS_VERSION + "'='" + EMPTY_TYPES_CLASS_VERSION + '\'' + ", '" + OPTION_VALUE_FORMAT + "'='" + PORTABLE_FORMAT + '\'' + ", '" + OPTION_VALUE_FACTORY_ID + "'='" + EMPTY_TYPES_FACTORY_ID + '\'' + ", '" + OPTION_VALUE_CLASS_ID + "'='" + EMPTY_TYPES_CLASS_ID + '\'' + ", '" + OPTION_VALUE_CLASS_VERSION + "'='" + EMPTY_TYPES_CLASS_VERSION + '\'' + ")");
GenericRecord record = new PortableGenericRecordBuilder(emptyClassDefinition).build();
instance().getMap(name).put(record, record);
assertRowsAnyOrder("SELECT __key, this FROM " + name, singletonList(new Row(record, record)));
}
Aggregations