Search in sources :

Example 6 with EntryRemovedListener

use of com.hazelcast.map.listener.EntryRemovedListener in project hazelcast by hazelcast.

the class EntryProcessorTest method testIssue969MapEntryProcessorAllKeys.

@Test
public void testIssue969MapEntryProcessorAllKeys() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    Config cfg = getConfig();
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(cfg);
    nodeFactory.newHazelcastInstance(cfg);
    IMap<Integer, Integer> map = instance1.getMap(MAP_NAME);
    AtomicInteger addCount = new AtomicInteger(0);
    AtomicInteger updateCount = new AtomicInteger(0);
    AtomicInteger removeCount = new AtomicInteger(0);
    CountDownLatch latch = new CountDownLatch(300);
    map.addEntryListener((EntryAddedListener<Integer, Integer>) event -> {
        addCount.incrementAndGet();
        latch.countDown();
    }, true);
    map.addEntryListener((EntryRemovedListener<Integer, Integer>) event -> {
        removeCount.incrementAndGet();
        latch.countDown();
    }, true);
    map.addEntryListener((EntryUpdatedListener<Integer, Integer>) event -> {
        updateCount.incrementAndGet();
        latch.countDown();
    }, true);
    int size = 100;
    for (int i = 0; i < size; i++) {
        map.put(i, i);
    }
    IncrementorEntryProcessor<Integer> entryProcessor = new IncrementorEntryProcessor<>();
    Map<Integer, Integer> res = map.executeOnEntries(entryProcessor);
    for (int i = 0; i < size; i++) {
        assertEquals(map.get(i), (Object) (i + 1));
    }
    for (int i = 0; i < size; i++) {
        assertEquals(map.get(i), res.get(i));
    }
    RemoveEntryProcessor removeEntryProcessor = new RemoveEntryProcessor();
    map.executeOnEntries(removeEntryProcessor);
    assertEquals(0, map.size());
    assertTrue(latch.await(100, TimeUnit.SECONDS));
    assertEquals(100, addCount.get());
    assertEquals(100, removeCount.get());
    assertEquals(100, updateCount.get());
}
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) MapConfig(com.hazelcast.config.MapConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with EntryRemovedListener

use of com.hazelcast.map.listener.EntryRemovedListener in project hazelcast by hazelcast.

the class EntryProcessorTest method receivesEntryRemovedEvent_onPostProcessingMapStore_after_executeOnEntries.

@Test
public void receivesEntryRemovedEvent_onPostProcessingMapStore_after_executeOnEntries() {
    Config config = getConfig();
    config.getMapConfig(MAP_NAME).getMapStoreConfig().setEnabled(true).setImplementation(new TestPostProcessingMapStore<>());
    IMap<Integer, Integer> map = createHazelcastInstance(config).getMap(MAP_NAME);
    final CountDownLatch latch = new CountDownLatch(1);
    map.addEntryListener((EntryRemovedListener<Integer, Integer>) event -> latch.countDown(), true);
    map.put(1, 1);
    map.executeOnEntries(entry -> {
        entry.setValue(null);
        return null;
    });
    assertOpenEventually(latch);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) MapConfig(com.hazelcast.config.MapConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

EntryRemovedListener (com.hazelcast.map.listener.EntryRemovedListener)7 Config (com.hazelcast.config.Config)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 MapService (com.hazelcast.map.impl.MapService)6 InMemoryFormat (com.hazelcast.config.InMemoryFormat)5 BINARY (com.hazelcast.config.InMemoryFormat.BINARY)5 NATIVE (com.hazelcast.config.InMemoryFormat.NATIVE)5 OBJECT (com.hazelcast.config.InMemoryFormat.OBJECT)5 IndexConfig (com.hazelcast.config.IndexConfig)5 IndexType (com.hazelcast.config.IndexType)5 MapConfig (com.hazelcast.config.MapConfig)5 MapStoreConfig (com.hazelcast.config.MapStoreConfig)5 EntryView (com.hazelcast.core.EntryView)5 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)5 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)5 Offloadable (com.hazelcast.core.Offloadable)5 ReadOnly (com.hazelcast.core.ReadOnly)5 Json (com.hazelcast.internal.json.Json)5 JsonValue (com.hazelcast.internal.json.JsonValue)5 Data (com.hazelcast.internal.serialization.Data)5