Search in sources :

Example 1 with EntryRemovedListener

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

the class EntryProcessorTest method receivesEntryRemovedEvent_onPostProcessingMapStore_after_executeOnKey.

@Test
public void receivesEntryRemovedEvent_onPostProcessingMapStore_after_executeOnKey() {
    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.executeOnKey(1, 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)

Example 2 with EntryRemovedListener

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

the class EntryProcessorTest method testMapEntryProcessorEntryListeners.

@Test
public void testMapEntryProcessorEntryListeners() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    Config cfg = getConfig();
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(cfg);
    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);
    AtomicInteger addKey1Sum = new AtomicInteger(0);
    AtomicInteger updateKey1Sum = new AtomicInteger(0);
    AtomicInteger removeKey1Sum = new AtomicInteger(0);
    CountDownLatch latch = new CountDownLatch(6);
    map.addEntryListener((EntryAddedListener<Integer, Integer>) event -> {
        addCount.incrementAndGet();
        if (event.getKey() == 1) {
            addKey1Sum.addAndGet(event.getValue());
        }
        latch.countDown();
    }, true);
    map.addEntryListener((EntryRemovedListener<Integer, Integer>) event -> {
        removeCount.incrementAndGet();
        if (event.getKey() == 1) {
            removeKey1Sum.addAndGet(event.getOldValue());
        }
        latch.countDown();
    }, true);
    map.addEntryListener((EntryUpdatedListener<Integer, Integer>) event -> {
        updateCount.incrementAndGet();
        if (event.getKey() == 1) {
            updateKey1Sum.addAndGet(event.getValue());
        }
        latch.countDown();
    }, true);
    map.executeOnKey(1, new ValueSetterEntryProcessor(5));
    map.executeOnKey(2, new ValueSetterEntryProcessor(7));
    map.executeOnKey(2, new ValueSetterEntryProcessor(1));
    map.executeOnKey(1, new ValueSetterEntryProcessor(3));
    map.executeOnKey(1, new ValueSetterEntryProcessor(1));
    map.executeOnKey(1, new ValueSetterEntryProcessor(null));
    assertEquals((Integer) 1, map.get(2));
    assertNull(map.get(1));
    assertTrue(latch.await(100, TimeUnit.SECONDS));
    assertEquals(2, addCount.get());
    assertEquals(3, updateCount.get());
    assertEquals(1, removeCount.get());
    assertEquals(5, addKey1Sum.get());
    assertEquals(4, updateKey1Sum.get());
    assertEquals(1, removeKey1Sum.get());
}
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) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with EntryRemovedListener

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

the class EntryProcessorTest method testIssue969.

@Test
public void testIssue969() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    Config cfg = getConfig();
    HazelcastInstance instance1 = 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(3);
    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);
    map.executeOnKey(1, new ValueReaderEntryProcessor());
    assertNull(map.get(1));
    map.executeOnKey(1, new ValueReaderEntryProcessor());
    map.put(1, 3);
    assertNotNull(map.get(1));
    map.executeOnKey(1, new ValueReaderEntryProcessor());
    map.put(2, 2);
    ValueReaderEntryProcessor valueReaderEntryProcessor = new ValueReaderEntryProcessor();
    map.executeOnKey(2, valueReaderEntryProcessor);
    assertEquals(2, valueReaderEntryProcessor.getValue().intValue());
    map.put(2, 5);
    map.executeOnKey(2, valueReaderEntryProcessor);
    assertEquals(5, valueReaderEntryProcessor.getValue().intValue());
    assertTrue(latch.await(1, TimeUnit.MINUTES));
    assertEquals(2, addCount.get());
    assertEquals(0, removeCount.get());
    assertEquals(1, updateCount.get());
}
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) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with EntryRemovedListener

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

the class LocalListenerTest method no_exception_when_not_notifiable_listener.

@Test
public void no_exception_when_not_notifiable_listener() throws IllegalAccessException {
    Config config = getConfig().setProperty(PROP_LISTENER_WITH_PREDICATE_PRODUCES_NATURAL_EVENT_TYPES, "true");
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<String, String> map = instance.getMap(randomString());
    MapEventPublisherLogger mapEventPublisherLogger = new MapEventPublisherLogger();
    injectLogger(instance, mapEventPublisherLogger);
    // this entry-removed-listener is not notifiable,
    // since we expect entry added events.
    map.addLocalEntryListener((EntryRemovedListener<String, String>) event -> {
    });
    // generate entry-added event
    map.put("key", "value");
    // no exception we expect (we use assertTrueAllTheTime
    // since event is fired after put return)
    assertTrueAllTheTime(() -> assertTrue(mapEventPublisherLogger.logCollector.toString(), mapEventPublisherLogger.logCollector.isEmpty()), 5);
}
Also used : Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) PROP_LISTENER_WITH_PREDICATE_PRODUCES_NATURAL_EVENT_TYPES(com.hazelcast.map.impl.event.MapEventPublisherImpl.PROP_LISTENER_WITH_PREDICATE_PRODUCES_NATURAL_EVENT_TYPES) QuickTest(com.hazelcast.test.annotation.QuickTest) LogEvent(com.hazelcast.logging.LogEvent) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MapService(com.hazelcast.map.impl.MapService) Category(org.junit.experimental.categories.Category) MapServiceContext(com.hazelcast.map.impl.MapServiceContext) EntryRemovedListener(com.hazelcast.map.listener.EntryRemovedListener) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) Level(java.util.logging.Level) MapEventPublisher(com.hazelcast.map.impl.event.MapEventPublisher) ReflectionUtils.setFieldValueReflectively(com.hazelcast.test.starter.ReflectionUtils.setFieldValueReflectively) AbstractLogger(com.hazelcast.logging.AbstractLogger) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with EntryRemovedListener

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

the class EventQueuePluginTest method testMap.

@Test
public void testMap() {
    final IMap<Integer, Integer> map = hz.getMap(MAP_NAME);
    map.addLocalEntryListener(new EntryAddedListener<Integer, Integer>() {

        @Override
        public void entryAdded(EntryEvent<Integer, Integer> event) {
            assertOpenEventually(listenerLatch);
        }
    });
    map.addLocalEntryListener(new EntryRemovedListener() {

        @Override
        public void entryRemoved(EntryEvent event) {
            assertOpenEventually(listenerLatch);
        }
    });
    spawn(new Runnable() {

        @Override
        public void run() {
            Random random = new Random();
            for (int i = 0; i < EVENT_COUNTER; i++) {
                int key = random.nextInt(Integer.MAX_VALUE);
                map.putAsync(key, 23);
                map.removeAsync(key);
            }
        }
    });
    assertContainsEventually("IMap '" + MAP_NAME + "' ADDED sampleCount=", "IMap '" + MAP_NAME + "' REMOVED sampleCount=");
}
Also used : Random(java.util.Random) EntryRemovedListener(com.hazelcast.map.listener.EntryRemovedListener) CacheEntryRemovedListener(javax.cache.event.CacheEntryRemovedListener) EntryEvent(com.hazelcast.core.EntryEvent) CacheEntryEvent(javax.cache.event.CacheEntryEvent) 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