public void testClear() throws Exception { for (Cache<Object, String> c : caches) assert c.isEmpty(); for (int i = 0; i < 5; i++) { getOwners("k" + i)[0].put("k" + i, "value" + i); asyncWait("k" + i, PutKeyValueCommand.class); } // this will fill up L1 as well for (int i = 0; i < 5; i++) assertOnAllCachesAndOwnership("k" + i, "value" + i); for (Cache<Object, String> c : caches) assert !c.isEmpty(); c1.clear(); asyncWait(null, ClearCommand.class); for (Cache<Object, String> c : caches) assert c.isEmpty(); /* We only check c1 because on a shared situation, no matter where the clear is called, * it should clear the whole store regardless. Bear in mind that in the test, even though * the cache store is shared, each cache has each own cache store, that allows for checking * who execute puts, removes...etc. */ CacheLoader store = TestingUtil.getFirstLoader(c1); assertNumberOfInvocations(store, "clear", calculateTotalSegmentsForAllNodes()); for (int i = 0; i < 5; i++) { String key = "k" + i; assert !store.contains(key); } }
public void testPutFromOwner() throws Exception { String key = "k5", value = "value5"; for (Cache<Object, String> c : caches) assert c.isEmpty(); Cache[] owners = getOwners(key); Object retval = owners[0].put(key, value); asyncWait(key, PutKeyValueCommand.class); CacheLoader store = TestingUtil.getFirstLoader(owners[0]); assertIsInContainerImmortal(owners[0], key); assert store.contains(key); for (int i = 1; i < owners.length; i++) { store = TestingUtil.getFirstLoader(owners[i]); assertIsInContainerImmortal(owners[i], key); assert store.contains(key); } for (Cache<Object, String> c : caches) { store = TestingUtil.getFirstLoader(c); if (isOwner(c, key)) { assertIsInContainerImmortal(c, key); } assert store.contains(key); assertNumberOfInvocations(store, "write", 1); } if (testRetVals) assert retval == null; assertOnAllCachesAndOwnership(key, value); }
public void testPutFromNonOwner() throws Exception { String key = "k4", value = "value4"; for (Cache<Object, String> c : caches) assert c.isEmpty(); Cache<Object, String> nonOwner = getFirstNonOwner(key); CacheLoader nonOwnerStore = TestingUtil.getFirstLoader(nonOwner); assert !nonOwnerStore.contains(key); Object retval = nonOwner.put(key, value); asyncWait(key, PutKeyValueCommand.class); Cache[] owners = getOwners(key); CacheLoader store = TestingUtil.getFirstLoader(owners[0]); assertIsInContainerImmortal(owners[0], key); assert store.contains(key); for (int i = 1; i < owners.length; i++) { store = TestingUtil.getFirstLoader(owners[i]); assertIsInContainerImmortal(owners[i], key); assert store.contains(key); } for (Cache<Object, String> c : caches) { store = TestingUtil.getFirstLoader(c); assert store.contains(key); assertNumberOfInvocations(store, "write", 1); } if (testRetVals) assert retval == null; assertOnAllCachesAndOwnership(key, value); }