Search in sources :

Example 26 with EntryEvent

use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.

the class IssuesTest method testIssue321_3.

// verify an event including values and an event excluding values are received, in any order
@Test
public void testIssue321_3() throws Exception {
    int n = 1;
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(n);
    final IMap<Integer, Integer> imap = factory.newHazelcastInstance(getConfig()).getMap("testIssue321_3");
    final List<EntryEvent<Integer, Integer>> eventsWithValues = new ArrayList<EntryEvent<Integer, Integer>>();
    final List<EntryEvent<Integer, Integer>> eventsWithoutValues = new ArrayList<EntryEvent<Integer, Integer>>();
    final EntryAdapter<Integer, Integer> listener = new EntryAdapter<Integer, Integer>() {

        @Override
        public void entryAdded(com.hazelcast.core.EntryEvent<Integer, Integer> event) {
            if (event.getValue() == null) {
                eventsWithoutValues.add(event);
            } else {
                eventsWithValues.add(event);
            }
        }
    };
    imap.addEntryListener(listener, true);
    Thread.sleep(50L);
    imap.addEntryListener(listener, false);
    imap.put(1, 1);
    assertEqualsEventually(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            return eventsWithValues.size();
        }
    }, 1);
    assertEqualsEventually(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            return eventsWithoutValues.size();
        }
    }, 1);
}
Also used : EntryAdapter(com.hazelcast.core.EntryAdapter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) EntryEvent(com.hazelcast.core.EntryEvent) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with EntryEvent

use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.

the class LocalMapStatsMultipleNodeTest method testLocalMapStats_preservedAfterEviction.

@Test
public void testLocalMapStats_preservedAfterEviction() {
    String mapName = randomMapName();
    Config config = new Config();
    config.getProperties().setProperty(ClusterProperty.PARTITION_COUNT.getName(), "5");
    MapConfig mapConfig = config.getMapConfig(mapName);
    EvictionConfig evictionConfig = mapConfig.getEvictionConfig();
    evictionConfig.setEvictionPolicy(EvictionPolicy.LRU);
    evictionConfig.setMaxSizePolicy(MaxSizePolicy.PER_PARTITION);
    evictionConfig.setSize(25);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Object, Object> map = instance.getMap(mapName);
    final CountDownLatch entryEvictedLatch = new CountDownLatch(700);
    map.addEntryListener(new EntryEvictedListener() {

        @Override
        public void entryEvicted(EntryEvent event) {
            entryEvictedLatch.countDown();
        }
    }, true);
    for (int i = 0; i < 1000; i++) {
        map.put(i, i);
        map.set(i, i);
        assertEquals(i, map.get(i));
    }
    LocalMapStats localMapStats = map.getLocalMapStats();
    assertEquals(2000, localMapStats.getHits());
    assertEquals(1000, localMapStats.getPutOperationCount());
    assertEquals(1000, localMapStats.getSetOperationCount());
    assertEquals(1000, localMapStats.getGetOperationCount());
    assertOpenEventually(entryEvictedLatch);
    localMapStats = map.getLocalMapStats();
    assertEquals(2000, localMapStats.getHits());
    assertEquals(1000, localMapStats.getPutOperationCount());
    assertEquals(1000, localMapStats.getSetOperationCount());
    assertEquals(1000, localMapStats.getGetOperationCount());
}
Also used : MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) MemberGroupConfig(com.hazelcast.config.MemberGroupConfig) PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) EntryEvictedListener(com.hazelcast.map.listener.EntryEvictedListener) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryEvent(com.hazelcast.core.EntryEvent) MapConfig(com.hazelcast.config.MapConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 28 with EntryEvent

use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.

the class EntryEventDataCacheTest method createInvalidationEventRejectingFilter.

private static EventListenerFilter createInvalidationEventRejectingFilter() {
    ListenerAdapter listenerAdapter = createListenerAdapter(new EntryAddedListener() {

        @Override
        public void entryAdded(EntryEvent event) {
        }
    });
    int flags = setAndGetListenerFlags(listenerAdapter);
    return new EventListenerFilter(flags, TrueEventFilter.INSTANCE);
}
Also used : ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) ListenerAdapter(com.hazelcast.map.impl.ListenerAdapter) EntryEvent(com.hazelcast.core.EntryEvent) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) EventListenerFilter(com.hazelcast.map.impl.EventListenerFilter)

Example 29 with EntryEvent

use of com.hazelcast.core.EntryEvent 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)

Example 30 with EntryEvent

use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.

the class MapExpirationManagerTest method backgroundClearTaskStops_whenLifecycleState.

private void backgroundClearTaskStops_whenLifecycleState(LifecycleEvent.LifecycleState lifecycleState) {
    Config config = getConfig();
    config.setProperty(taskPeriodSecondsPropName(), "1");
    HazelcastInstance node = createHazelcastInstance(config);
    final AtomicInteger expirationCounter = new AtomicInteger();
    IMap<Integer, Integer> map = node.getMap("test");
    map.addEntryListener(new EntryExpiredListener() {

        @Override
        public void entryExpired(EntryEvent event) {
            expirationCounter.incrementAndGet();
        }
    }, true);
    map.put(1, 1, 3, TimeUnit.SECONDS);
    ((LifecycleServiceImpl) node.getLifecycleService()).fireLifecycleEvent(lifecycleState);
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() {
            int expirationCount = expirationCounter.get();
            assertEquals(format("Expecting no expiration but found:%d", expirationCount), 0, expirationCount);
        }
    }, 5);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryExpiredListener(com.hazelcast.map.listener.EntryExpiredListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Config(com.hazelcast.config.Config) EntryEvent(com.hazelcast.core.EntryEvent) AssertTask(com.hazelcast.test.AssertTask) LifecycleServiceImpl(com.hazelcast.instance.impl.LifecycleServiceImpl)

Aggregations

EntryEvent (com.hazelcast.core.EntryEvent)71 Test (org.junit.Test)62 QuickTest (com.hazelcast.test.annotation.QuickTest)47 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)39 EntryAdapter (com.hazelcast.core.EntryAdapter)22 HazelcastInstance (com.hazelcast.core.HazelcastInstance)22 Config (com.hazelcast.config.Config)19 CountDownLatch (java.util.concurrent.CountDownLatch)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 AssertTask (com.hazelcast.test.AssertTask)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)15 MapListener (com.hazelcast.map.listener.MapListener)11 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)10 MapConfig (com.hazelcast.config.MapConfig)9 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)8 Predicate (com.hazelcast.query.Predicate)8 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 EntryAddedListener (com.hazelcast.map.listener.EntryAddedListener)7 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)6