RemoteCache<String, String> remote = cacheFactory.getHotRodCache();
TestCacheListener l = new TestCacheListener();
embedded.addListener(l);
NotifyingFuture future = remote.putAsync("k", "v");
future.get(60, TimeUnit.SECONDS);
assertEquals(1, l.createdCounter);
assertEquals("v", l.created.get("k"));
assertTrue(l.removed.isEmpty());
assertEquals(1, l.modifiedCounter);
assertEquals("v", l.modified.get("k"));
assertTrue(l.visited.isEmpty());
NotifyingFuture future2 = remote.putAsync("key", "value");
future2.get(60, TimeUnit.SECONDS);
assertEquals(2, l.createdCounter);
assertTrue(l.removed.isEmpty());
assertEquals(2, l.modifiedCounter);
assertTrue(l.visited.isEmpty());
NotifyingFuture future3 = remote.putAsync("key", "modifiedValue");
future3.get(60, TimeUnit.SECONDS);
assertEquals(2, l.createdCounter);
assertTrue(l.removed.isEmpty());
assertEquals(3, l.modifiedCounter);
assertEquals("modifiedValue", l.modified.get("key"));
assertTrue(l.visited.isEmpty());
NotifyingFuture future4 = remote.replaceAsync("k", "replacedValue");
future4.get(60, TimeUnit.SECONDS);
assertEquals(2, l.createdCounter);
assertTrue(l.removed.isEmpty());
assertEquals(4, l.modifiedCounter);
assertEquals("replacedValue", l.modified.get("k"));
assertTrue(l.visited.isEmpty());
//resetting so don't have to type "== 2" etc. all over again
l.reset();
NotifyingFuture future5 = remote.removeAsync("key");
future5.get(60, TimeUnit.SECONDS);
assertTrue(l.created.isEmpty());
assertEquals(1, l.removedCounter);
assertEquals("modifiedValue", l.removed.get("key"));
assertTrue(l.modified.isEmpty());
l.reset();
NotifyingFuture future6 = remote.getAsync("k");
future6.get(60, TimeUnit.SECONDS);
assertTrue(l.created.isEmpty());
assertTrue(l.removed.isEmpty());
assertTrue(l.modified.isEmpty());
assertEquals(1, l.visitedCounter);
assertEquals("replacedValue", l.visited.get("k"));