Search in sources :

Example 51 with EntryEvent

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

the class MapPreconditionsTest method testAddLocalEntryListenerWithMapListenerAndPredicateAndKey_NullPredicate.

@Test(expected = NullPointerException.class)
public void testAddLocalEntryListenerWithMapListenerAndPredicateAndKey_NullPredicate() {
    MapListener mapListener = new MapListenerAdapter() {

        public void onEntryEvent(EntryEvent event) {
            System.out.println("-");
        }
    };
    Predicate predicate = null;
    map.addLocalEntryListener(mapListener, predicate, null, true);
}
Also used : MapListener(com.hazelcast.map.listener.MapListener) MapListenerAdapter(com.hazelcast.map.impl.MapListenerAdapter) EntryEvent(com.hazelcast.core.EntryEvent) TruePredicate(com.hazelcast.query.TruePredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 52 with EntryEvent

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

the class MapPreconditionsTest method testAddEntryListenerWithMapListenerAndKey_NullKey.

@Test(expected = NullPointerException.class)
public void testAddEntryListenerWithMapListenerAndKey_NullKey() {
    MapListener mapListener = new MapListenerAdapter() {

        public void onEntryEvent(EntryEvent event) {
            System.out.println("-");
        }
    };
    map.addEntryListener(mapListener, null, false);
}
Also used : MapListener(com.hazelcast.map.listener.MapListener) MapListenerAdapter(com.hazelcast.map.impl.MapListenerAdapter) EntryEvent(com.hazelcast.core.EntryEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 53 with EntryEvent

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

the class MapStoreWriteThroughTest method testOneMemberWriteThroughWithLRU.

@Test(timeout = 120000)
public void testOneMemberWriteThroughWithLRU() throws Exception {
    final int size = 10000;
    TestMapStore testMapStore = new TestMapStore(size * 2, 1, 1);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 0);
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setSize(size);
    MapConfig mapConfig = config.getMapConfig("default");
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    mapConfig.setMinEvictionCheckMillis(0);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap("default");
    final CountDownLatch countDownLatch = new CountDownLatch(size);
    map.addEntryListener(new EntryAdapter() {

        @Override
        public void entryEvicted(EntryEvent event) {
            countDownLatch.countDown();
        }
    }, false);
    for (int i = 0; i < size * 2; i++) {
        // trigger eviction.
        if (i == (size * 2) - 1 || i == size) {
            sleepMillis(1001);
        }
        map.put(i, new Employee("joe", i, true, 100.00));
    }
    assertEquals(testMapStore.getStore().size(), size * 2);
    assertOpenEventually(countDownLatch);
    final String msgFailure = String.format("map size: %d put count: %d", map.size(), size);
    assertTrue(msgFailure, map.size() > size / 2);
    assertTrue(msgFailure, map.size() <= size);
    assertEquals(testMapStore.getStore().size(), size * 2);
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) EntryAdapter(com.hazelcast.core.EntryAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) EntryEvent(com.hazelcast.core.EntryEvent) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 54 with EntryEvent

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

the class MultiMapListenerTest method testConfigListenerRegistration.

@Test
public void testConfigListenerRegistration() throws InterruptedException {
    Config config = new Config();
    final String name = "default";
    final CountDownLatch latch = new CountDownLatch(1);
    config.getMultiMapConfig(name).addEntryListenerConfig(new EntryListenerConfig().setImplementation(new EntryAdapter() {

        public void entryAdded(EntryEvent event) {
            latch.countDown();
        }
    }));
    final HazelcastInstance hz = createHazelcastInstance(config);
    hz.getMultiMap(name).put(1, 1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MultiMapConfig(com.hazelcast.config.MultiMapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 55 with EntryEvent

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

the class EventPublishOrderWithEvictionTest method assertEmittedEventsOrder.

private void assertEmittedEventsOrder(EventOrderAwareEntryListener entryListener) {
    Map<Integer, List<EntryEventType>> eventsPerKey = new HashMap<Integer, List<EntryEventType>>();
    List<EntryEvent> events = entryListener.getOrderedEvents();
    for (EntryEvent event : events) {
        Integer key = (Integer) event.getKey();
        List<EntryEventType> eventTypes = eventsPerKey.get(key);
        if (eventTypes == null) {
            eventTypes = new ArrayList<EntryEventType>();
            eventsPerKey.put(key, eventTypes);
        }
        EntryEventType eventType = event.getEventType();
        eventTypes.add(eventType);
    }
    Set<Map.Entry<Integer, List<EntryEventType>>> entries = eventsPerKey.entrySet();
    for (Map.Entry<Integer, List<EntryEventType>> entry : entries) {
        List<EntryEventType> eventTypes = entry.getValue();
        EntryEventType prev = null;
        for (int i = 0; i < eventTypes.size(); i++) {
            final EntryEventType eventType = eventTypes.get(i);
            if (i == 0) {
                assertEquals(EntryEventType.ADDED, eventType);
                prev = eventType;
                continue;
            }
            if (prev.equals(EntryEventType.ADDED)) {
                assertEquals(EntryEventType.EVICTED, eventType);
            } else if (prev.equals(EntryEventType.EVICTED)) {
                assertEquals(EntryEventType.ADDED, eventType);
            }
            prev = eventType;
        }
    }
}
Also used : HashMap(java.util.HashMap) EntryEventType(com.hazelcast.core.EntryEventType) EntryEvent(com.hazelcast.core.EntryEvent) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) IMap(com.hazelcast.core.IMap) Map(java.util.Map)

Aggregations

EntryEvent (com.hazelcast.core.EntryEvent)57 Test (org.junit.Test)49 QuickTest (com.hazelcast.test.annotation.QuickTest)38 ParallelTest (com.hazelcast.test.annotation.ParallelTest)37 EntryAdapter (com.hazelcast.core.EntryAdapter)21 CountDownLatch (java.util.concurrent.CountDownLatch)19 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 Config (com.hazelcast.config.Config)15 AssertTask (com.hazelcast.test.AssertTask)11 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)10 MapListener (com.hazelcast.map.listener.MapListener)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Predicate (com.hazelcast.query.Predicate)8 TruePredicate (com.hazelcast.query.TruePredicate)8 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)7 MapConfig (com.hazelcast.config.MapConfig)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)6 MapEvent (com.hazelcast.core.MapEvent)5 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)4