use of com.hazelcast.internal.serialization.impl.portable.NamedPortable in project hazelcast by hazelcast.
the class AbstractGenericRecordIntegrationTest method testReadReturnsGenericRecord.
@Test
public void testReadReturnsGenericRecord() {
HazelcastInstance[] instances = createCluster();
HazelcastInstance instance = createAccessorInstance(serializationConfig);
IMap<Object, Object> map = instance.getMap("test");
NamedPortable expected = new NamedPortable("foo", 900);
map.put(1, expected);
IMap<Object, Object> clusterMap = instances[0].getMap("test");
GenericRecord actual = (GenericRecord) clusterMap.get(1);
assertTrue(actual.hasField("name"));
assertTrue(actual.hasField("myint"));
assertEquals(expected.name, actual.getString("name"));
assertEquals(expected.myint, actual.getInt32("myint"));
}
use of com.hazelcast.internal.serialization.impl.portable.NamedPortable in project hazelcast by hazelcast.
the class AbstractGenericRecordIntegrationTest method testEntryProcessorReturnsGenericRecord.
@Test
public void testEntryProcessorReturnsGenericRecord() {
HazelcastInstance[] instances = createCluster();
HazelcastInstance instance = createAccessorInstance(serializationConfig);
IMap<Object, Object> map = instance.getMap("test");
NamedPortable expected = new NamedPortable("foo", 900);
String key = generateKeyOwnedBy(instances[0]);
map.put(key, expected);
Object returnValue = map.executeOnKey(key, (EntryProcessor<Object, Object, Object>) entry -> {
Object value = entry.getValue();
GenericRecord genericRecord = (GenericRecord) value;
GenericRecord modifiedGenericRecord = genericRecord.newBuilder().setString("name", "bar").setInt32("myint", 4).build();
entry.setValue(modifiedGenericRecord);
return genericRecord.getInt32("myint");
});
assertEquals(expected.myint, returnValue);
NamedPortable actualPortable = (NamedPortable) map.get(key);
assertEquals("bar", actualPortable.name);
assertEquals(4, actualPortable.myint);
}
use of com.hazelcast.internal.serialization.impl.portable.NamedPortable in project hazelcast by hazelcast.
the class AbstractGenericRecordIntegrationTest method createGenericRecord.
@Nonnull
private GenericRecord createGenericRecord(MainPortable expectedPortable) {
InnerPortable inner = expectedPortable.p;
ClassDefinition namedPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("name").addIntField("myint").build();
ClassDefinition innerPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.INNER_PORTABLE).addByteArrayField("b").addCharArrayField("c").addShortArrayField("s").addIntArrayField("i").addLongArrayField("l").addFloatArrayField("f").addDoubleArrayField("d").addPortableArrayField("nn", namedPortableClassDefinition).addDecimalArrayField("bigDecimals").addTimeArrayField("localTimes").addDateArrayField("localDates").addTimestampArrayField("localDateTimes").addTimestampWithTimezoneArrayField("offsetDateTimes").build();
ClassDefinition mainPortableClassDefinition = new ClassDefinitionBuilder(PortableTest.PORTABLE_FACTORY_ID, TestSerializationConstants.MAIN_PORTABLE).addByteField("b").addBooleanField("bool").addCharField("c").addShortField("s").addIntField("i").addLongField("l").addFloatField("f").addDoubleField("d").addStringField("str").addPortableField("p", innerPortableClassDefinition).addDecimalField("bigDecimal").addTimeField("localTime").addDateField("localDate").addTimestampField("localDateTime").addTimestampWithTimezoneField("offsetDateTime").build();
GenericRecord[] namedRecords = new GenericRecord[inner.nn.length];
int i = 0;
for (NamedPortable namedPortable : inner.nn) {
GenericRecord namedRecord = GenericRecordBuilder.portable(namedPortableClassDefinition).setString("name", inner.nn[i].name).setInt32("myint", inner.nn[i].myint).build();
namedRecords[i++] = namedRecord;
}
GenericRecord innerRecord = GenericRecordBuilder.portable(innerPortableClassDefinition).setArrayOfInt8("b", inner.bb).setArrayOfChar("c", inner.cc).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.portable(mainPortableClassDefinition).setInt8("b", expectedPortable.b).setBoolean("bool", expectedPortable.bool).setChar("c", expectedPortable.c).setInt16("s", expectedPortable.s).setInt32("i", expectedPortable.i).setInt64("l", expectedPortable.l).setFloat32("f", expectedPortable.f).setFloat64("d", expectedPortable.d).setString("str", expectedPortable.str).setGenericRecord("p", innerRecord).setDecimal("bigDecimal", expectedPortable.bigDecimal).setTime("localTime", expectedPortable.localTime).setDate("localDate", expectedPortable.localDate).setTimestamp("localDateTime", expectedPortable.localDateTime).setTimestampWithTimezone("offsetDateTime", expectedPortable.offsetDateTime).build();
}
use of com.hazelcast.internal.serialization.impl.portable.NamedPortable in project hazelcast by hazelcast.
the class AbstractGenericRecordIntegrationTest method createMainPortable.
@Nonnull
private MainPortable createMainPortable() {
NamedPortable[] nn = new NamedPortable[2];
nn[0] = new NamedPortable("name", 123);
nn[1] = new NamedPortable("name", 123);
InnerPortable inner = new InnerPortable(new byte[] { 0, 1, 2 }, new char[] { 'c', 'h', 'a', 'r' }, new short[] { 3, 4, 5 }, new int[] { 9, 8, 7, 6 }, new long[] { 0, 1, 5, 7, 9, 11 }, new float[] { 0.6543f, -3.56f, 45.67f }, new double[] { 456.456, 789.789, 321.321 }, nn, new BigDecimal[] { new BigDecimal("12345"), new BigDecimal("123456") }, new LocalTime[] { LocalTime.now(), LocalTime.now() }, new LocalDate[] { LocalDate.now(), LocalDate.now() }, new LocalDateTime[] { LocalDateTime.now() }, new OffsetDateTime[] { OffsetDateTime.now() });
return new MainPortable((byte) 113, true, 'x', (short) -500, 56789, -50992225L, 900.5678f, -897543.3678909d, "this is main portable object created for testing!", inner, new BigDecimal("12312313"), LocalTime.now(), LocalDate.now(), LocalDateTime.now(), OffsetDateTime.now());
}
use of com.hazelcast.internal.serialization.impl.portable.NamedPortable in project hazelcast by hazelcast.
the class ClientMapTest method setup.
@Before
public void setup() {
Config config = getConfig();
config.getMapConfig("flushMap").setMapStoreConfig(new MapStoreConfig().setWriteDelaySeconds(1000).setImplementation(flushMapStore));
config.getMapConfig("putTransientMap").setMapStoreConfig(new MapStoreConfig().setWriteDelaySeconds(1000).setImplementation(transientMapStore));
server = hazelcastFactory.newHazelcastInstance(config);
ClientConfig clientConfig = getClientConfig();
clientConfig.getSerializationConfig().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, classId -> new NamedPortable());
client = hazelcastFactory.newHazelcastClient(clientConfig);
}
Aggregations