assertEquals(2, map.get(1));
}
@Test
public void testListener() throws InterruptedException {
final IMap map = createMap();
final CountDownLatch latch1Add = new CountDownLatch(5);
final CountDownLatch latch1Remove = new CountDownLatch(2);
final CountDownLatch latch2Add = new CountDownLatch(1);
final CountDownLatch latch2Remove = new CountDownLatch(1);
EntryListener listener1 = new EntryAdapter() {
public void entryAdded(EntryEvent event) {
latch1Add.countDown();
}
public void entryRemoved(EntryEvent event) {
latch1Remove.countDown();
}
};
EntryListener listener2 = new EntryAdapter() {
public void entryAdded(EntryEvent event) {
latch2Add.countDown();
}
public void entryRemoved(EntryEvent event) {
latch2Remove.countDown();
}
};
map.addEntryListener(listener1, false);
map.addEntryListener(listener2, "key3", true);
Thread.sleep(1000);
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
map.put("key4", "value4");
map.put("key5", "value5");
map.remove("key1");
map.remove("key3");
assertTrue(latch1Add.await(10, TimeUnit.SECONDS));
assertTrue(latch1Remove.await(10, TimeUnit.SECONDS));
assertTrue(latch2Add.await(5, TimeUnit.SECONDS));
assertTrue(latch2Remove.await(5, TimeUnit.SECONDS));