ZooKeeperUtils { public static void ensurePath(ZooKeeperClient zkClient, List<ACL> acl, String path) throws ZooKeeperConnectionException, InterruptedException, KeeperException { Preconditions.checkNotNull(zkClient); Preconditions.checkNotNull(path); Preconditions.checkArgument(path.startsWith("/")); ensurePathInternal(zkClient, acl, path); } private  ZooKeeperUtils(); static boolean isRetryable(KeeperException e); static void ensurePath(ZooKeeperClient zkClient, List<ACL> acl, String path); static String normalizePath(String path); static final Amount<Integer,Time> DEFAULT_ZK_SESSION_TIMEOUT; static final int ANY_VERSION; static final ImmutableList<ACL> OPEN_ACL_UNSAFE; static final ImmutableList<ACL> EVERYONE_READ_CREATOR_ALL; }
@Test public void testEnsurePath() throws Exception { ZooKeeperClient zkClient = createZkClient(); zkClient.get().addAuthInfo("digest", "client1:boo".getBytes(Charsets.UTF_8)); assertNull(zkClient.get().exists("/foo", false)); ZooKeeperUtils.ensurePath(zkClient, ZooDefs.Ids.CREATOR_ALL_ACL, "/foo/bar/baz"); zkClient = createZkClient(); zkClient.get().addAuthInfo("digest", "client2:bap".getBytes(Charsets.UTF_8)); assertNotNull(zkClient.get().exists("/foo", false)); assertNotNull(zkClient.get().exists("/foo/bar", false)); assertNotNull(zkClient.get().exists("/foo/bar/baz", false)); try { zkClient.get().delete("/foo/bar/baz", -1 ); fail("Expected CREATOR_ALL_ACL to be applied to created path and client2 mutations to be " + "rejected"); } catch (NoAuthException e) { } }