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