CompatibilityCacheFactory.killCacheFactories(cacheFactory);
}
public void testLoadingAndStoringEventsMemcached() throws InterruptedException, ExecutionException, TimeoutException {
Cache<String, String> embedded = cacheFactory.getEmbeddedCache();
MemcachedClient remote = cacheFactory.getMemcachedClient();
TestCacheListener l = new TestCacheListener();
embedded.addListener(l);
assertTrue(l.created.isEmpty());
assertTrue(l.removed.isEmpty());
assertTrue(l.modified.isEmpty());
assertTrue(l.visited.isEmpty());
Future<Boolean> future1 = remote.add("k", 0, "v");
assertTrue(future1.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());
Future<Boolean> future2 = remote.set("key", 0, "value");
assertTrue(future2.get(60, TimeUnit.SECONDS));
assertEquals(2, l.createdCounter);
assertTrue(l.removed.isEmpty());
assertEquals(2, l.modifiedCounter);
assertTrue(l.visited.isEmpty());
Future<Boolean> future3 = remote.set("key", 0, "modifiedValue");
assertTrue(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());
Future<Boolean> future4 = remote.replace("k", 0, "replacedValue");
assertTrue(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();
Future<Boolean> future5 = remote.delete("key");
assertTrue(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();
String value = (String) remote.get("k");
assertTrue(l.created.isEmpty());
assertTrue(l.removed.isEmpty());
assertTrue(l.modified.isEmpty());
assertEquals(1, l.visitedCounter);
assertEquals("replacedValue", l.visited.get("k"));