Search in sources :

Example 1 with BINARY

use of com.hazelcast.config.InMemoryFormat.BINARY in project hazelcast by hazelcast.

the class EntryProcessorTest method testExecuteOnEntriesWithEntryListener.

@Test
public void testExecuteOnEntriesWithEntryListener() {
    IMap<String, String> map = createHazelcastInstance(getConfig()).getMap(MAP_NAME);
    map.put("key", "value");
    CountDownLatch latch = new CountDownLatch(1);
    map.addEntryListener((EntryUpdatedListener<String, String>) event -> {
        String val = event.getValue();
        String oldValue = event.getOldValue();
        if ("newValue".equals(val) && ((inMemoryFormat == BINARY || inMemoryFormat == NATIVE) && "value".equals(oldValue) || inMemoryFormat == OBJECT && null == oldValue)) {
            latch.countDown();
        }
    }, true);
    map.executeOnEntries(entry -> {
        entry.setValue("newValue");
        return 5;
    });
    assertOpenEventually(latch, 5);
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BINARY(com.hazelcast.config.InMemoryFormat.BINARY) QuickTest(com.hazelcast.test.annotation.QuickTest) QueryContext(com.hazelcast.query.impl.QueryContext) MultipleEntryWithPredicateOperation(com.hazelcast.map.impl.operation.MultipleEntryWithPredicateOperation) MapConfig(com.hazelcast.config.MapConfig) Json(com.hazelcast.internal.json.Json) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) Future(java.util.concurrent.Future) NATIVE(com.hazelcast.config.InMemoryFormat.NATIVE) MapEntries(com.hazelcast.map.impl.MapEntries) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Duration(java.time.Duration) Map(java.util.Map) DataSerializable(com.hazelcast.nio.serialization.DataSerializable) Employee(com.hazelcast.query.SampleTestObjects.Employee) Assert.fail(org.junit.Assert.fail) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Predicate(com.hazelcast.query.Predicate) PREDICATE_APPLY_COUNT(com.hazelcast.map.EntryProcessorTest.ApplyCountAwareIndexedTestPredicate.PREDICATE_APPLY_COUNT) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) EntryUpdatedListener(com.hazelcast.map.listener.EntryUpdatedListener) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) Set(java.util.Set) EntryView(com.hazelcast.core.EntryView) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) IndexConfig(com.hazelcast.config.IndexConfig) Serializable(java.io.Serializable) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Entry(java.util.Map.Entry) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) SampleTestObjects(com.hazelcast.query.SampleTestObjects) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) Index(com.hazelcast.query.impl.Index) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) InMemoryFormat(com.hazelcast.config.InMemoryFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) EntryRemovedListener(com.hazelcast.map.listener.EntryRemovedListener) ArrayList(java.util.ArrayList) IndexAwarePredicate(com.hazelcast.query.impl.predicates.IndexAwarePredicate) HashSet(java.util.HashSet) IndexType(com.hazelcast.config.IndexType) Operation(com.hazelcast.spi.impl.operationservice.Operation) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Collections.emptyMap(java.util.Collections.emptyMap) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) Parameter(org.junit.runners.Parameterized.Parameter) Assert.assertNotNull(org.junit.Assert.assertNotNull) Record(com.hazelcast.map.impl.record.Record) Data(com.hazelcast.internal.serialization.Data) Assert.assertTrue(org.junit.Assert.assertTrue) HazelcastParallelParametersRunnerFactory(com.hazelcast.test.HazelcastParallelParametersRunnerFactory) Test(org.junit.Test) IOException(java.io.IOException) Offloadable(com.hazelcast.core.Offloadable) MapService(com.hazelcast.map.impl.MapService) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Assert.assertNull(org.junit.Assert.assertNull) Predicates(com.hazelcast.query.Predicates) ReadOnly(com.hazelcast.core.ReadOnly) AssertTask(com.hazelcast.test.AssertTask) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) OBJECT(com.hazelcast.config.InMemoryFormat.OBJECT) Assert.assertEquals(org.junit.Assert.assertEquals) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with BINARY

use of com.hazelcast.config.InMemoryFormat.BINARY in project hazelcast by hazelcast.

the class EntryProcessorTest method testExecuteOnKeysWithEntryListener.

@Test
public void testExecuteOnKeysWithEntryListener() {
    IMap<String, String> map = createHazelcastInstance(getConfig()).getMap(MAP_NAME);
    map.put("key", "value");
    final CountDownLatch latch = new CountDownLatch(1);
    map.addEntryListener((EntryUpdatedListener<String, String>) event -> {
        String val = event.getValue();
        String oldValue = event.getOldValue();
        if ("newValue".equals(val) && ((inMemoryFormat == BINARY || inMemoryFormat == NATIVE) && "value".equals(oldValue) || inMemoryFormat == OBJECT && null == oldValue)) {
            latch.countDown();
        }
    }, true);
    HashSet<String> keys = new HashSet<>();
    keys.add("key");
    map.executeOnKeys(keys, entry -> {
        entry.setValue("newValue");
        return 5;
    });
    assertOpenEventually(latch, 5);
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) BINARY(com.hazelcast.config.InMemoryFormat.BINARY) QuickTest(com.hazelcast.test.annotation.QuickTest) QueryContext(com.hazelcast.query.impl.QueryContext) MultipleEntryWithPredicateOperation(com.hazelcast.map.impl.operation.MultipleEntryWithPredicateOperation) MapConfig(com.hazelcast.config.MapConfig) Json(com.hazelcast.internal.json.Json) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) Future(java.util.concurrent.Future) NATIVE(com.hazelcast.config.InMemoryFormat.NATIVE) MapEntries(com.hazelcast.map.impl.MapEntries) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Duration(java.time.Duration) Map(java.util.Map) DataSerializable(com.hazelcast.nio.serialization.DataSerializable) Employee(com.hazelcast.query.SampleTestObjects.Employee) Assert.fail(org.junit.Assert.fail) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Predicate(com.hazelcast.query.Predicate) PREDICATE_APPLY_COUNT(com.hazelcast.map.EntryProcessorTest.ApplyCountAwareIndexedTestPredicate.PREDICATE_APPLY_COUNT) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) EntryUpdatedListener(com.hazelcast.map.listener.EntryUpdatedListener) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) Set(java.util.Set) EntryView(com.hazelcast.core.EntryView) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) IndexConfig(com.hazelcast.config.IndexConfig) Serializable(java.io.Serializable) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Entry(java.util.Map.Entry) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) SampleTestObjects(com.hazelcast.query.SampleTestObjects) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) Index(com.hazelcast.query.impl.Index) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) InMemoryFormat(com.hazelcast.config.InMemoryFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) EntryRemovedListener(com.hazelcast.map.listener.EntryRemovedListener) ArrayList(java.util.ArrayList) IndexAwarePredicate(com.hazelcast.query.impl.predicates.IndexAwarePredicate) HashSet(java.util.HashSet) IndexType(com.hazelcast.config.IndexType) Operation(com.hazelcast.spi.impl.operationservice.Operation) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Collections.emptyMap(java.util.Collections.emptyMap) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) Parameter(org.junit.runners.Parameterized.Parameter) Assert.assertNotNull(org.junit.Assert.assertNotNull) Record(com.hazelcast.map.impl.record.Record) Data(com.hazelcast.internal.serialization.Data) Assert.assertTrue(org.junit.Assert.assertTrue) HazelcastParallelParametersRunnerFactory(com.hazelcast.test.HazelcastParallelParametersRunnerFactory) Test(org.junit.Test) IOException(java.io.IOException) Offloadable(com.hazelcast.core.Offloadable) MapService(com.hazelcast.map.impl.MapService) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Assert.assertNull(org.junit.Assert.assertNull) Predicates(com.hazelcast.query.Predicates) ReadOnly(com.hazelcast.core.ReadOnly) AssertTask(com.hazelcast.test.AssertTask) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) OBJECT(com.hazelcast.config.InMemoryFormat.OBJECT) Assert.assertEquals(org.junit.Assert.assertEquals) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Config (com.hazelcast.config.Config)2 InMemoryFormat (com.hazelcast.config.InMemoryFormat)2 BINARY (com.hazelcast.config.InMemoryFormat.BINARY)2 NATIVE (com.hazelcast.config.InMemoryFormat.NATIVE)2 OBJECT (com.hazelcast.config.InMemoryFormat.OBJECT)2 IndexConfig (com.hazelcast.config.IndexConfig)2 IndexType (com.hazelcast.config.IndexType)2 MapConfig (com.hazelcast.config.MapConfig)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 EntryView (com.hazelcast.core.EntryView)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)2 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)2 Offloadable (com.hazelcast.core.Offloadable)2 ReadOnly (com.hazelcast.core.ReadOnly)2 Json (com.hazelcast.internal.json.Json)2 JsonValue (com.hazelcast.internal.json.JsonValue)2 Data (com.hazelcast.internal.serialization.Data)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 PREDICATE_APPLY_COUNT (com.hazelcast.map.EntryProcessorTest.ApplyCountAwareIndexedTestPredicate.PREDICATE_APPLY_COUNT)2