public Long getACL(DataNodeV1 oldDataNode) { synchronized (oldDataNode) { return aclCache.convertAcls(oldDataNode.acl); } }
private Long convertACLsNTimes(ReferenceCountedACLCache cache, List<ACL> acl, int num) { if (num <= 0) { return -1L; } for (int i = 0; i < num -1; i++) { cache.convertAcls(acl); } return cache.convertAcls(acl); }
public Stat setACL(String path, List<ACL> acl, int version) throws KeeperException.NoNodeException { Stat stat = new Stat(); DataNode n = nodes.get(path); if (n == null) { throw new KeeperException.NoNodeException(); } synchronized (n) { aclCache.removeUsage(n.acl); n.stat.setAversion(version); n.acl = aclCache.convertAcls(acl); n.copyStat(stat); return stat; } }
public Stat setACL(String path, List<ACL> acl, int version) throws KeeperException.NoNodeException { Stat stat = new Stat(); DataNode n = nodes.get(path); if (n == null) { throw new KeeperException.NoNodeException(); } synchronized (n) { aclCache.removeUsage(n.acl); n.stat.setAversion(version); n.acl = aclCache.convertAcls(acl); n.copyStat(stat); return stat; } }
@Test public void testSameACLGivesSameID() { List<ACL> testACL = createACL("myid"); ReferenceCountedACLCache cache = new ReferenceCountedACLCache(); Long aclId = cache.convertAcls(testACL); List<ACL> testACL2 = createACL("myid"); assertEquals(aclId, cache.convertAcls(testACL2)); }
parent.stat.setPzxid(zxid); Long longval = aclCache.convertAcls(acl); DataNode child = new DataNode(data, longval, stat); parent.addChild(childName);
@Test public void testWhetherOrderingMatters() { List<ACL> testACL = new ArrayList<ACL>(); testACL.add(new ACL(ZooDefs.Perms.READ, new Id("scheme", "ro"))); testACL.add(new ACL(ZooDefs.Perms.WRITE, new Id("scheme", "rw"))); ReferenceCountedACLCache cache = new ReferenceCountedACLCache(); Long aclId = cache.convertAcls(testACL); List<ACL> testACL2 = new ArrayList<ACL>(); testACL2.add(new ACL(ZooDefs.Perms.WRITE, new Id("scheme", "rw"))); testACL2.add(new ACL(ZooDefs.Perms.READ, new Id("scheme", "ro"))); assertFalse(aclId.equals(cache.convertAcls(testACL2))); }
@Test public void testCacheSize() { List<ACL> testACL = createACL("myid"); ReferenceCountedACLCache cache = new ReferenceCountedACLCache(); Long aclId = cache.convertAcls(testACL); assertEquals(1, cache.size()); List<ACL> testACL2 = createACL("myid"); assertEquals(aclId, cache.convertAcls(testACL2)); assertEquals(1, cache.size()); List<ACL> testACL3 = createACL("differentId"); Long aclId3 = cache.convertAcls(testACL3); assertFalse(aclId3.equals(aclId)); assertEquals(2, cache.size()); }
Long longval = aclCache.convertAcls(acl); DataNode child = new DataNode(parent, data, longval, stat); parent.addChild(childName);
@Test public void testMultipleAddsAndRemove() { List<ACL> testACL = createACL("myid"); ReferenceCountedACLCache cache = new ReferenceCountedACLCache(); Long aclId = cache.convertAcls(testACL); assertEquals(1, cache.size()); cache.convertAcls(testACL); assertEquals(1, cache.size()); List<ACL> testACL2 = createACL("anotherId"); cache.convertAcls(testACL2); cache.removeUsage(aclId); assertEquals(2, cache.size()); cache.removeUsage(aclId); assertEquals(1, cache.size()); Long newId = cache.convertAcls(testACL); assertFalse(aclId.equals(newId)); }
@Test public void testBidirectionality() { List<ACL> testACL = createACL("myid"); ReferenceCountedACLCache cache = new ReferenceCountedACLCache(); Long aclId = cache.convertAcls(testACL); assertEquals(testACL, cache.convertLong(aclId)); }
@Test public void testPurgeUnused() throws IOException { ReferenceCountedACLCache cache = new ReferenceCountedACLCache(); List<ACL> acl1 = createACL("one"); List<ACL> acl2 = createACL("two"); List<ACL> acl3 = createACL("three"); List<ACL> acl4 = createACL("four"); List<ACL> acl5 = createACL("five"); Long aclId1 = convertACLsNTimes(cache, acl1, 1); Long aclId2 = convertACLsNTimes(cache, acl2, 2); Long aclId3 = convertACLsNTimes(cache, acl3, 3); Long aclId4 = convertACLsNTimes(cache, acl4, 4); Long aclId5 = convertACLsNTimes(cache, acl5, 5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive archive = BinaryOutputArchive.getArchive(baos); cache.serialize(archive); BinaryInputArchive inArchive = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray())); ReferenceCountedACLCache deserializedCache = new ReferenceCountedACLCache(); deserializedCache.deserialize(inArchive); callAddUsageNTimes(deserializedCache, aclId1, 1); callAddUsageNTimes(deserializedCache, aclId2, 2); deserializedCache.purgeUnused(); assertEquals(2, deserializedCache.size()); assertEquals(aclId1, deserializedCache.convertAcls(acl1)); assertEquals(aclId2, deserializedCache.convertAcls(acl2)); assertFalse(acl3.equals(deserializedCache.convertAcls(acl3))); assertFalse(acl4.equals(deserializedCache.convertAcls(acl4))); assertFalse(acl5.equals(deserializedCache.convertAcls(acl5))); }
@Test public void testAddThenRemove() { List<ACL> testACL = createACL("myid"); ReferenceCountedACLCache cache = new ReferenceCountedACLCache(); Long aclId = cache.convertAcls(testACL); assertEquals(1, cache.size()); cache.removeUsage(aclId); assertEquals(0, cache.size()); }
@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()); }