Search in sources :

Example 1 with NamedPortable

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"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) Test(org.junit.Test)

Example 2 with NamedPortable

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);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) TestSerializationConstants(com.hazelcast.internal.serialization.impl.TestSerializationConstants) LocalDateTime(java.time.LocalDateTime) Callable(java.util.concurrent.Callable) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) SerializationConfig(com.hazelcast.config.SerializationConfig) Json(com.hazelcast.internal.json.Json) BigDecimal(java.math.BigDecimal) Future(java.util.concurrent.Future) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) BiTuple(com.hazelcast.internal.util.BiTuple) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) LocalTime(java.time.LocalTime) Nonnull(javax.annotation.Nonnull) MainPortable(com.hazelcast.internal.serialization.impl.portable.MainPortable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Serializable(java.io.Serializable) OffsetDateTime(java.time.OffsetDateTime) IExecutorService(com.hazelcast.core.IExecutorService) EntryProcessor(com.hazelcast.map.EntryProcessor) LocalDate(java.time.LocalDate) InnerPortable(com.hazelcast.internal.serialization.impl.portable.InnerPortable) GenericRecordBuilder(com.hazelcast.nio.serialization.GenericRecordBuilder) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) Test(org.junit.Test)

Example 3 with NamedPortable

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();
}
Also used : InnerPortable(com.hazelcast.internal.serialization.impl.portable.InnerPortable) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) Nonnull(javax.annotation.Nonnull)

Example 4 with NamedPortable

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());
}
Also used : MainPortable(com.hazelcast.internal.serialization.impl.portable.MainPortable) InnerPortable(com.hazelcast.internal.serialization.impl.portable.InnerPortable) BigDecimal(java.math.BigDecimal) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) Nonnull(javax.annotation.Nonnull)

Example 5 with NamedPortable

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);
}
Also used : MapStoreConfig(com.hazelcast.config.MapStoreConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) Before(org.junit.Before)

Aggregations

NamedPortable (com.hazelcast.internal.serialization.impl.portable.NamedPortable)9 Test (org.junit.Test)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 PortableTest (com.hazelcast.internal.serialization.impl.portable.PortableTest)5 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)5 InnerPortable (com.hazelcast.internal.serialization.impl.portable.InnerPortable)4 Nonnull (javax.annotation.Nonnull)4 IExecutorService (com.hazelcast.core.IExecutorService)3 MainPortable (com.hazelcast.internal.serialization.impl.portable.MainPortable)3 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)3 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)3 BigDecimal (java.math.BigDecimal)3 SerializationConfig (com.hazelcast.config.SerializationConfig)2 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)2 Json (com.hazelcast.internal.json.Json)2 TestSerializationConstants (com.hazelcast.internal.serialization.impl.TestSerializationConstants)2 BiTuple (com.hazelcast.internal.util.BiTuple)2 EntryProcessor (com.hazelcast.map.EntryProcessor)2 IMap (com.hazelcast.map.IMap)2 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)2