Search in sources :

Example 6 with NamedPortable

use of com.hazelcast.internal.serialization.impl.portable.NamedPortable in project hazelcast by hazelcast.

the class ClientMapTest method testPredicateListenerWithPortableKey.

@Test
public void testPredicateListenerWithPortableKey() throws Exception {
    IMap<Portable, Integer> tradeMap = createMap();
    final AtomicInteger atomicInteger = new AtomicInteger(0);
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    EntryListener listener = new EntryAdapter() {

        @Override
        public void entryAdded(EntryEvent event) {
            atomicInteger.incrementAndGet();
            countDownLatch.countDown();
        }
    };
    NamedPortable key = new NamedPortable("a", 1);
    tradeMap.addEntryListener(listener, key, true);
    NamedPortable key2 = new NamedPortable("b", 2);
    tradeMap.put(key2, 1);
    assertFalse(countDownLatch.await(5, TimeUnit.SECONDS));
    assertEquals(0, atomicInteger.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Portable(com.hazelcast.nio.serialization.Portable) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) EntryListener(com.hazelcast.core.EntryListener) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with NamedPortable

use of com.hazelcast.internal.serialization.impl.portable.NamedPortable in project hazelcast by hazelcast.

the class AbstractGenericRecordIntegrationTest method testCloneWithGenericBuilderOnEntryProcessor.

@Test
public void testCloneWithGenericBuilderOnEntryProcessor() {
    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.cloneWithBuilder().setInt32("myint", 4).build();
        entry.setValue(modifiedGenericRecord);
        return genericRecord.getInt32("myint");
    });
    assertEquals(expected.myint, returnValue);
    NamedPortable actualPortable = (NamedPortable) map.get(key);
    assertEquals("foo", 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 8 with NamedPortable

use of com.hazelcast.internal.serialization.impl.portable.NamedPortable in project hazelcast by hazelcast.

the class AbstractGenericRecordIntegrationTest method testPutGenericRecordBack.

@Test
public void testPutGenericRecordBack() {
    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 record = (GenericRecord) clusterMap.get(1);
    clusterMap.put(2, record);
    // read from the cluster without serialization config
    GenericRecord actualRecord = (GenericRecord) clusterMap.get(2);
    assertTrue(actualRecord.hasField("name"));
    assertTrue(actualRecord.hasField("myint"));
    assertEquals(expected.name, actualRecord.getString("name"));
    assertEquals(expected.myint, actualRecord.getInt32("myint"));
    // read from the instance with serialization config
    NamedPortable actualPortable = (NamedPortable) map.get(2);
    assertEquals(expected, actualPortable);
}
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 9 with NamedPortable

use of com.hazelcast.internal.serialization.impl.portable.NamedPortable in project hazelcast by hazelcast.

the class AbstractGenericRecordIntegrationTest method testGenericRecordIsReturnedInRemoteLogic.

@Test
public void testGenericRecordIsReturnedInRemoteLogic() throws Exception {
    HazelcastInstance[] instances = createCluster();
    HazelcastInstance instance = createAccessorInstance(serializationConfig);
    IExecutorService service = instance.getExecutorService("test");
    IMap<Object, Object> map = instance.getMap("test");
    NamedPortable expected = new NamedPortable("foo", 900);
    map.put(1, expected);
    Future<Integer> actual = service.submitToMember(new GetInt(), instances[0].getCluster().getLocalMember());
    assertEquals(expected.myint, actual.get().intValue());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IExecutorService(com.hazelcast.core.IExecutorService) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) PortableTest(com.hazelcast.internal.serialization.impl.portable.PortableTest) Test(org.junit.Test)

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