ZkMigrator { private static void setAcls(String connectionString, String znode, ZkAcl acl) throws IOException, InterruptedException, KeeperException { ZooKeeper client = ZkConnection.open(connectionString, SESSION_TIMEOUT_MILLIS, CONNECTION_TIMEOUT_MILLIS); try { acl.setRecursivelyOn(client, ZkPathPattern.fromString(znode)); } catch (KeeperException.NoNodeException e) { System.out.println("Could not set ACL on " + znode + ". Reason: " + e.getMessage()); } finally { client.close(); } }  static void main(String[] args);  }
@Test public void testSetAclsOnSingleNode() throws Exception { path("/single"); setAcls("/single", "ip:127.0.0.1:rwd"); assertHasAcl("/single", "ip", "127.0.0.1", WRITE | READ | DELETE); }
@Test public void testSetAclsOnParentAndItsDirectChildren() throws Exception { path("/parent"); path("/parent/a"); path("/parent/b"); setAcls("/parent", "ip:127.0.0.1:rd"); assertHasAcl("/parent", "ip", "127.0.0.1", READ | DELETE); assertHasAcl("/parent/a", "ip", "127.0.0.1", READ | DELETE); assertHasAcl("/parent/b", "ip", "127.0.0.1", READ | DELETE); }
@Test public void testSetAclsRecursively() throws Exception { path("/parent"); path("/parent/a"); path("/parent/a/b"); path("/parent/a/b/c"); setAcls("/", "ip:127.0.0.1:r"); assertHasAcl("/parent", "ip", "127.0.0.1", READ); assertHasAcl("/parent/a", "ip", "127.0.0.1", READ); assertHasAcl("/parent/a/b", "ip", "127.0.0.1", READ); assertHasAcl("/parent/a/b/c", "ip", "127.0.0.1", READ); }
@Test public void testSupportsWildcard() throws Exception { path("/abc123"); path("/abcdef/efg"); path("/abc/123"); path("/x"); path("/y/a"); path("/ab"); setAcls("/abc*", "ip:127.0.0.1:r"); assertHasAcl("/abc123", "ip", "127.0.0.1", READ); assertHasAcl("/abcdef/efg", "ip", "127.0.0.1", READ); assertHasAcl("/abc/123", "ip", "127.0.0.1", READ); assertHasAcl("/x", "world", "anyone", ALL); assertHasAcl("/y/a", "world", "anyone", ALL); assertHasAcl("/ab", "world", "anyone", ALL); }
@Test public void testSupportsMultupleWildcards() throws Exception { path("/abc123"); path("/a/abcdef"); path("/def/abc"); path("/xy/abc/efg"); path("/a/xyabc"); path("/a/b/abc"); path("/b"); setAcls("/*/abc*", "ip:127.0.0.1:r"); assertHasAcl("/a/abcdef", "ip", "127.0.0.1", READ); assertHasAcl("/xy/abc/efg", "ip", "127.0.0.1", READ); assertHasAcl("/def/abc", "ip", "127.0.0.1", READ); assertHasAcl("/a/xyabc", "world", "anyone", ALL); assertHasAcl("/abc123", "world", "anyone", ALL); assertHasAcl("/a/b/abc", "world", "anyone", ALL); assertHasAcl("/b", "world", "anyone", ALL); }
@Test public void testSupportsWorldScheme() throws Exception { path("/unprotected"); setAcls("/unprotected", "world:anyone:r"); assertHasAcl("/unprotected", "world", "anyone", READ); }
@Test(expected = IllegalArgumentException.class) public void testRejectsUnsupportedScheme() throws Exception { path("/any"); setAcls("/any", "unsupported:anyone:r"); }
@Test(expected = IllegalArgumentException.class) public void testRejectUnsupportedPermission() throws Exception { path("/any"); setAcls("/any", "world:anyone:invalid"); }
@Test public void testIgnoresNonExistentNode() throws Exception { setAcls("/nonexistent", "world:anyone:rw"); }