Search in sources :

Example 11 with GenericRecord

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

the class GenericRecordTest method testGetFieldKindThrowsExceptionWhenFieldDoesNotExist.

@Test
public void testGetFieldKindThrowsExceptionWhenFieldDoesNotExist() throws IOException {
    GenericRecord record = compact("test").build();
    assertThrows(IllegalArgumentException.class, () -> {
        record.getFieldKind("doesNotExist");
    });
    InternalSerializationService serializationService = (InternalSerializationService) createSerializationService();
    Data data = serializationService.toData(record);
    InternalGenericRecord internalGenericRecord = serializationService.readAsInternalGenericRecord(data);
    assertThrows(IllegalArgumentException.class, () -> {
        internalGenericRecord.getFieldKind("doesNotExist");
    });
}
Also used : Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) CompactTestUtil.createCompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord) InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with GenericRecord

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

the class CompactTestUtil method createCompactGenericRecord.

@Nonnull
static GenericRecord createCompactGenericRecord(MainDTO mainDTO) {
    InnerDTO inner = mainDTO.p;
    GenericRecord[] namedRecords = new GenericRecord[inner.nn.length];
    int i = 0;
    for (NamedDTO named : inner.nn) {
        GenericRecord namedRecord = GenericRecordBuilder.compact("named").setString("name", named.name).setInt32("myint", named.myint).build();
        namedRecords[i++] = namedRecord;
    }
    GenericRecord innerRecord = GenericRecordBuilder.compact("inner").setArrayOfInt8("b", inner.bb).setArrayOfInt16("s", inner.ss).setArrayOfInt32("i", inner.ii).setArrayOfInt64("l", inner.ll).setArrayOfFloat32("f", inner.ff).setArrayOfFloat64("d", inner.dd).setArrayOfGenericRecord("nn", namedRecords).setArrayOfDecimal("bigDecimals", inner.bigDecimals).setArrayOfTime("localTimes", inner.localTimes).setArrayOfDate("localDates", inner.localDates).setArrayOfTimestamp("localDateTimes", inner.localDateTimes).setArrayOfTimestampWithTimezone("offsetDateTimes", inner.offsetDateTimes).build();
    return GenericRecordBuilder.compact("main").setInt8("b", mainDTO.b).setBoolean("bool", mainDTO.bool).setInt16("s", mainDTO.s).setInt32("i", mainDTO.i).setInt64("l", mainDTO.l).setFloat32("f", mainDTO.f).setFloat64("d", mainDTO.d).setString("str", mainDTO.str).setDecimal("bigDecimal", mainDTO.bigDecimal).setGenericRecord("p", innerRecord).setTime("localTime", mainDTO.localTime).setDate("localDate", mainDTO.localDate).setTimestamp("localDateTime", mainDTO.localDateTime).setTimestampWithTimezone("offsetDateTime", mainDTO.offsetDateTime).setNullableInt8("nullable_b", mainDTO.b).setNullableBoolean("nullable_bool", mainDTO.bool).setNullableInt16("nullable_s", mainDTO.s).setNullableInt32("nullable_i", mainDTO.i).setNullableInt64("nullable_l", mainDTO.l).setNullableFloat32("nullable_f", mainDTO.f).setNullableFloat64("nullable_d", mainDTO.d).build();
}
Also used : NamedDTO(example.serialization.NamedDTO) InnerDTO(example.serialization.InnerDTO) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) Nonnull(javax.annotation.Nonnull)

Example 13 with GenericRecord

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

the class GenericRecordTest method testReadWriteChar.

@Test
public void testReadWriteChar() {
    assertThrows(UnsupportedOperationException.class, () -> {
        compact("writeChar").setChar("c", 'a');
    });
    assertThrows(UnsupportedOperationException.class, () -> {
        GenericRecord record = compact("readChar").build();
        record.getChar("c");
    });
}
Also used : InternalGenericRecord(com.hazelcast.internal.serialization.impl.InternalGenericRecord) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) CompactTestUtil.createCompactGenericRecord(com.hazelcast.internal.serialization.impl.compact.CompactTestUtil.createCompactGenericRecord) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with GenericRecord

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

the class AbstractGenericRecordIntegrationTest method testPutWithoutFactory_readAsGenericRecord.

@Test
public void testPutWithoutFactory_readAsGenericRecord() {
    MainPortable expectedPortable = createMainPortable();
    GenericRecord expected = createGenericRecord(expectedPortable);
    assertEquals(expectedPortable.c, expected.getChar("c"));
    assertEquals(expectedPortable.f, expected.getFloat32("f"), 0.1);
    HazelcastInstance[] instances = createCluster();
    IMap<Object, Object> clusterMap = instances[0].getMap("test");
    clusterMap.put(1, expected);
    HazelcastInstance instance = createAccessorInstance(new SerializationConfig());
    IMap<Object, Object> map = instance.getMap("test");
    GenericRecord actual = (GenericRecord) map.get(1);
    assertEquals(expected, actual);
}
Also used : MainPortable(com.hazelcast.internal.serialization.impl.portable.MainPortable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) Test(org.junit.Test)

Example 15 with GenericRecord

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

the class AbstractGenericRecordIntegrationTest method testInconsistentClassDefinitionOfNestedPortableFields.

@Test(expected = HazelcastSerializationException.class)
public void testInconsistentClassDefinitionOfNestedPortableFields() {
    createCluster();
    HazelcastInstance instance = createAccessorInstance(serializationConfig);
    IMap<Object, Object> map = instance.getMap("test");
    BiTuple<GenericRecord, GenericRecord> records = getInconsistentNestedGenericRecords();
    map.put(1, records.element1);
    map.put(2, records.element2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) 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