Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public ACLableExistBuilderMain creatingParentsIfNeeded() {

@Override
public ACLableExistBuilderMain creatingParentContainersIfNeeded() {
createParentContainersIfNeeded = true;
createParentsIfNeeded = false;
createParentContainersIfNeeded = client.useContainerParentsIfAvailable();
createParentsIfNeeded = true;
return this;
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public Stat forPath(String path) throws Exception {
operationAndData,
operationAndData.getData(),
acling.getACLProviderForParents(),
createParentContainersIfNeeded);
createParentsAsContainers());
} else {
client.processBackgroundOperation(operationAndData, null);
}
Expand All @@ -205,6 +205,10 @@ public Stat forPath(String path) throws Exception {
return returnStat;
}

private boolean createParentsAsContainers() {
return createParentContainersIfNeeded && client.useContainerParentsIfAvailable();
}

private Stat pathInForeground(final String path) throws Exception {
if (createParentContainersIfNeeded || createParentsIfNeeded) {
final String parent = ZKPaths.getPathAndNode(path).getPath();
Expand All @@ -220,7 +224,7 @@ public Void call() throws Exception {
parent,
true,
acling.getACLProviderForParents(),
createParentContainersIfNeeded);
createParentsAsContainers());
} catch (KeeperException.NodeExistsException e) {
// ignore
} catch (KeeperException.NoNodeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Object call() throws Exception {
ZKPaths.makePath("/", namespace),
true,
client.getAclProvider(),
true);
client.useContainerParentsIfAvailable());
return null;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,61 @@ public void testExistsCreatingParents() throws Exception {
}
}

@Test
public void testExistsOverrideCreateParentContainers() throws Exception {
if (!checkForContainers()) {
return;
}

CuratorFramework client = CuratorFrameworkFactory.builder()
.connectString(server.getConnectString())
.retryPolicy(new RetryOneTime(1))
.dontUseContainerParents()
.build();
try {
client.start();
assertNull(client.checkExists().creatingParentContainersIfNeeded().forPath("/one/two/three"));
client.create().forPath("/one/two/three", "foo".getBytes());
byte[] data = client.getData().forPath("/one/two/three");
assertArrayEquals(data, "foo".getBytes());

client.delete().forPath("/one/two/three");
new Timing().sleepABit();

assertNotNull(client.checkExists().forPath("/one/two"));
new Timing().sleepABit();
assertNotNull(client.checkExists().forPath("/one"));
} finally {
CloseableUtils.closeQuietly(client);
}
}

@Test
public void testNamespaceOverrideCreateParentContainers() throws Exception {
if (!checkForContainers()) {
return;
}

CuratorFramework client = CuratorFrameworkFactory.builder()
.connectString(server.getConnectString())
.retryPolicy(new RetryOneTime(1))
.namespace("one")
.dontUseContainerParents()
.build();
try {
client.start();
client.create().forPath("/two");
assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/one/two", false));

client.delete().forPath("/two");
new Timing().sleepABit();

assertNotNull(client.getZookeeperClient().getZooKeeper().exists("/one", false));
} finally {
CloseableUtils.closeQuietly(client);
}
}

@Test
public void testExistsCreatingParentsInBackground() throws Exception {
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
Expand Down