use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class ClientRegressionWithMockNetworkTest method testListenerReconnect.
public void testListenerReconnect() throws InterruptedException {
final HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final CountDownLatch latch = new CountDownLatch(2);
final IMap<Object, Object> m = client.getMap("m");
final String id = m.addEntryListener(new EntryAdapter() {
public void entryAdded(EntryEvent event) {
latch.countDown();
}
@Override
public void entryUpdated(EntryEvent event) {
latch.countDown();
}
}, true);
m.put("key1", "value1");
final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
instance1.shutdown();
final Thread thread = new Thread() {
@Override
public void run() {
while (!isInterrupted()) {
m.put("key2", "value2");
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
}
}
};
thread.start();
assertOpenEventually(latch, 10);
thread.interrupt();
assertTrue(m.removeEntryListener(id));
assertFalse(m.removeEntryListener("foo"));
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class ClientMapTest method testIssue537.
@Test
@SuppressWarnings("deprecation")
public void testIssue537() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch nullLatch = new CountDownLatch(2);
EntryListener<String, GenericEvent> listener = new EntryAdapter<String, GenericEvent>() {
@Override
public void entryAdded(EntryEvent<String, GenericEvent> event) {
latch.countDown();
}
@Override
public void entryEvicted(EntryEvent<String, GenericEvent> event) {
GenericEvent value = event.getValue();
GenericEvent oldValue = event.getOldValue();
if (value == null) {
nullLatch.countDown();
}
if (oldValue != null) {
nullLatch.countDown();
}
latch.countDown();
}
};
IMap<String, GenericEvent> map = createMap();
String id = map.addEntryListener(listener, true);
map.put("key1", new GenericEvent("value1"), 2, TimeUnit.SECONDS);
assertOpenEventually(latch);
assertOpenEventually(nullLatch);
map.removeEntryListener(id);
map.put("key2", new GenericEvent("value2"));
assertEquals(1, map.size());
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class ClientMapTest method testListener.
@Test
@SuppressWarnings("deprecation")
public void testListener() throws InterruptedException {
IMap<String, String> map = createMap();
final CountDownLatch latch1Add = new CountDownLatch(5);
final CountDownLatch latch1Remove = new CountDownLatch(2);
EntryListener<String, String> listener1 = new EntryAdapter<String, String>() {
@Override
public void entryAdded(EntryEvent<String, String> event) {
latch1Add.countDown();
}
@Override
public void entryRemoved(EntryEvent<String, String> event) {
latch1Remove.countDown();
}
};
final CountDownLatch latch2Add = new CountDownLatch(1);
final CountDownLatch latch2Remove = new CountDownLatch(1);
EntryListener<String, String> listener2 = new EntryAdapter<String, String>() {
@Override
public void entryAdded(EntryEvent<String, String> event) {
latch2Add.countDown();
}
@Override
public void entryRemoved(EntryEvent<String, String> 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));
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class ClientMapTest method testPredicateListenerWithPortableKey.
@Test
@SuppressWarnings("deprecation")
public void testPredicateListenerWithPortableKey() throws InterruptedException {
IMap<Portable, Integer> tradeMap = createMap();
final AtomicInteger atomicInteger = new AtomicInteger(0);
final CountDownLatch countDownLatch = new CountDownLatch(1);
EntryListener listener = new EntryAdapter() {
@Override
public void entryAdded(EntryEvent event) {
atomicInteger.incrementAndGet();
countDownLatch.countDown();
}
};
NamedPortable key = new NamedPortable("a", 1);
tradeMap.addEntryListener(listener, key, true);
NamedPortable key2 = new NamedPortable("b", 2);
tradeMap.put(key2, 1);
assertFalse(countDownLatch.await(5, TimeUnit.SECONDS));
assertEquals(0, atomicInteger.get());
}
use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.
the class ClientMultiMapListenersTest method testListenerOnKey_whenOtherKeysAdded.
@Test
public void testListenerOnKey_whenOtherKeysAdded() throws InterruptedException {
final MultiMap mm = client.getMultiMap(randomString());
final List<EntryEvent> events = new ArrayList<EntryEvent>();
mm.addEntryListener(new EntryAdapter() {
@Override
public void entryAdded(EntryEvent event) {
events.add(event);
}
}, "key", true);
mm.put("key2", "value");
mm.put("key", "value");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, events.size());
assertEquals("key", events.get(0).getKey());
}
});
}
Aggregations