private void callAddUsageNTimes(ReferenceCountedACLCache deserializedCache, Long aclId, int num) { for (int i = 0; i < num; i++) { deserializedCache.addUsage(aclId); } }
/** * converts the list of acls to a long. * Increments the reference counter for this ACL. * @param acls * @return a long that map to the acls */ public synchronized Long convertAcls(List<ACL> acls) { if (acls == null) return OPEN_UNSAFE_ACL_ID; // get the value from the map Long ret = aclKeyMap.get(acls); if (ret == null) { ret = incrementIndex(); longKeyMap.put(ret, acls); aclKeyMap.put(acls, ret); } addUsage(ret); return ret; }
/** * converts the list of acls to a long. * Increments the reference counter for this ACL. * @param acls * @return a long that map to the acls */ public synchronized Long convertAcls(List<ACL> acls) { if (acls == null) return OPEN_UNSAFE_ACL_ID; // get the value from the map Long ret = aclKeyMap.get(acls); if (ret == null) { ret = incrementIndex(); longKeyMap.put(ret, acls); aclKeyMap.put(acls, ret); } addUsage(ret); return ret; }
nodes.put(path, node); synchronized (node) { aclCache.addUsage(node.acl);
nodes.put(path, node); synchronized (node) { aclCache.addUsage(node.acl);
@Test public void testAddNonExistentUsage() { ReferenceCountedACLCache cache = new ReferenceCountedACLCache(); cache.addUsage(1L); assertEquals(0, cache.size()); /* On startup, it's possible that we'll try calling addUsage of an ID not in the cache. This is safe to ignore as it'll be added later when we traverse the tranlog. See discussion here: http://mail-archives.apache.org/mod_mbox/zookeeper-user/201507.mbox/%3CCAB5oV2_ujhvBA1sEkCG2WRakPjCy%2BNR10620WK2G1GGgmEO44g%40mail.gmail.com%3E This test makes sure that we don't add the ID to the cache in this case as that would result in dupes later and consequently incorrect counts and entries that will never be cleaned out. */ }
@Test public void testAddUsage() { List<ACL> testACL = createACL("myid"); ReferenceCountedACLCache cache = new ReferenceCountedACLCache(); Long aclId = cache.convertAcls(testACL); assertEquals(1, cache.size()); cache.addUsage(aclId); assertEquals(1, cache.size()); cache.removeUsage(aclId); assertEquals(1, cache.size()); cache.removeUsage(aclId); assertEquals(0, cache.size()); }