Search in sources :

Example 21 with GenericRecord

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

Example 22 with GenericRecord

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"));
}
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 23 with GenericRecord

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);
        }
    }
}
Also used : IMap(com.hazelcast.map.IMap) EmployeeDTO(example.serialization.EmployeeDTO) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with GenericRecord

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);
    }
}
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 25 with GenericRecord

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)));
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) PortableGenericRecordBuilder(com.hazelcast.internal.serialization.impl.portable.PortableGenericRecordBuilder) Test(org.junit.Test)

Aggregations

GenericRecord (com.hazelcast.nio.serialization.GenericRecord)45 Test (org.junit.Test)36 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)23 QuickTest (com.hazelcast.test.annotation.QuickTest)23 Data (com.hazelcast.internal.serialization.Data)15 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)13 SerializationService (com.hazelcast.internal.serialization.SerializationService)11 InternalGenericRecord (com.hazelcast.internal.serialization.impl.InternalGenericRecord)11 CompactTestUtil.createCompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord)11 PortableTest (com.hazelcast.internal.serialization.impl.portable.PortableTest)11 HazelcastInstance (com.hazelcast.core.HazelcastInstance)10 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)10 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)8 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)8 SerializationConfig (com.hazelcast.config.SerializationConfig)7 MainPortable (com.hazelcast.internal.serialization.impl.portable.MainPortable)5 NamedPortable (com.hazelcast.internal.serialization.impl.portable.NamedPortable)5 BigDecimal (java.math.BigDecimal)4 LocalDate (java.time.LocalDate)4 LocalDateTime (java.time.LocalDateTime)4