You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2014/07/30 19:29:14 UTC
[1/2] git commit: Closes #25
Repository: curator
Updated Branches:
refs/heads/master bd319a92c -> 10bd72c51
Closes #25
some reformatting and added tests with nulls
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/49c20982
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/49c20982
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/49c20982
Branch: refs/heads/master
Commit: 49c20982a32399d55b8ff29f5ef6e6f5fd5995f5
Parents: 8699efc
Author: randgalt <ra...@apache.org>
Authored: Wed Jul 30 11:49:42 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Wed Jul 30 12:28:48 2014 -0500
----------------------------------------------------------------------
.../java/org/apache/curator/utils/ZKPaths.java | 87 ++++++++++----------
.../org/apache/curator/utils/TestZKPaths.java | 15 ++++
2 files changed, 59 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/49c20982/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java b/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java
index dfc69a7..820f45f 100644
--- a/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java
+++ b/curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.curator.utils;
import com.google.common.collect.Lists;
@@ -33,10 +34,10 @@ public class ZKPaths
* Apply the namespace to the given path
*
* @param namespace namespace (can be null)
- * @param path path
+ * @param path path
* @return adjusted path
*/
- public static String fixForNamespace(String namespace, String path)
+ public static String fixForNamespace(String namespace, String path)
{
// Child path must be valid in and of itself.
PathUtils.validatePath(path);
@@ -50,7 +51,7 @@ public class ZKPaths
/**
* Given a full path, return the node name. i.e. "/one/two/three" will return "three"
- *
+ *
* @param path the path
* @return the node
*/
@@ -62,7 +63,7 @@ public class ZKPaths
{
return path;
}
- if ( (i + 1) >= path.length() )
+ if ( (i + 1) >= path.length() )
{
return "";
}
@@ -71,8 +72,8 @@ public class ZKPaths
public static class PathAndNode
{
- private final String path;
- private final String node;
+ private final String path;
+ private final String node;
public PathAndNode(String path, String node)
{
@@ -105,7 +106,7 @@ public class ZKPaths
{
return new PathAndNode(path, "");
}
- if ( (i + 1) >= path.length() )
+ if ( (i + 1) >= path.length() )
{
return new PathAndNode("/", "");
}
@@ -120,12 +121,10 @@ public class ZKPaths
*
* @param zookeeper the client
* @param path path to ensure
- * @throws InterruptedException thread interruption
- * @throws org.apache.zookeeper.KeeperException
- * Zookeeper errors
+ * @throws InterruptedException thread interruption
+ * @throws org.apache.zookeeper.KeeperException Zookeeper errors
*/
- public static void mkdirs(ZooKeeper zookeeper, String path)
- throws InterruptedException, KeeperException
+ public static void mkdirs(ZooKeeper zookeeper, String path) throws InterruptedException, KeeperException
{
mkdirs(zookeeper, path, true, null);
}
@@ -134,15 +133,13 @@ public class ZKPaths
* Make sure all the nodes in the path are created. NOTE: Unlike File.mkdirs(), Zookeeper doesn't distinguish
* between directories and files. So, every node in the path is created. The data for each node is an empty blob
*
- * @param zookeeper the client
- * @param path path to ensure
+ * @param zookeeper the client
+ * @param path path to ensure
* @param makeLastNode if true, all nodes are created. If false, only the parent nodes are created
- * @throws InterruptedException thread interruption
- * @throws org.apache.zookeeper.KeeperException
- * Zookeeper errors
+ * @throws InterruptedException thread interruption
+ * @throws org.apache.zookeeper.KeeperException Zookeeper errors
*/
- public static void mkdirs(ZooKeeper zookeeper, String path, boolean makeLastNode)
- throws InterruptedException, KeeperException
+ public static void mkdirs(ZooKeeper zookeeper, String path, boolean makeLastNode) throws InterruptedException, KeeperException
{
mkdirs(zookeeper, path, makeLastNode, null);
}
@@ -151,16 +148,14 @@ public class ZKPaths
* Make sure all the nodes in the path are created. NOTE: Unlike File.mkdirs(), Zookeeper doesn't distinguish
* between directories and files. So, every node in the path is created. The data for each node is an empty blob
*
- * @param zookeeper the client
- * @param path path to ensure
+ * @param zookeeper the client
+ * @param path path to ensure
* @param makeLastNode if true, all nodes are created. If false, only the parent nodes are created
- * @throws InterruptedException thread interruption
- * @throws org.apache.zookeeper.KeeperException
- * Zookeeper errors
- * @param aclProvider if not null, the ACL provider to use when creating parent nodes
+ * @param aclProvider if not null, the ACL provider to use when creating parent nodes
+ * @throws InterruptedException thread interruption
+ * @throws org.apache.zookeeper.KeeperException Zookeeper errors
*/
- public static void mkdirs(ZooKeeper zookeeper, String path, boolean makeLastNode, InternalACLProvider aclProvider)
- throws InterruptedException, KeeperException
+ public static void mkdirs(ZooKeeper zookeeper, String path, boolean makeLastNode, InternalACLProvider aclProvider) throws InterruptedException, KeeperException
{
PathUtils.validatePath(path);
@@ -214,28 +209,36 @@ public class ZKPaths
/**
* Recursively deletes children of a node.
*
- * @param zookeeper the client
- * @param path path of the node to delete
- * @param deleteSelf flag that indicates that the node should also get deleted
+ * @param zookeeper the client
+ * @param path path of the node to delete
+ * @param deleteSelf flag that indicates that the node should also get deleted
* @throws InterruptedException
* @throws KeeperException
*/
- public static void deleteChildren(ZooKeeper zookeeper, String path, boolean deleteSelf) throws InterruptedException, KeeperException {
+ public static void deleteChildren(ZooKeeper zookeeper, String path, boolean deleteSelf) throws InterruptedException, KeeperException
+ {
PathUtils.validatePath(path);
List<String> children = zookeeper.getChildren(path, null);
- for (String child : children) {
+ for ( String child : children )
+ {
String fullPath = makePath(path, child);
deleteChildren(zookeeper, fullPath, true);
}
- if (deleteSelf) {
- try {
+ if ( deleteSelf )
+ {
+ try
+ {
zookeeper.delete(path, -1);
- } catch (KeeperException.NotEmptyException e) {
+ }
+ catch ( KeeperException.NotEmptyException e )
+ {
//someone has created a new child since we checked ... delete again.
- deleteChildren(zookeeper, path, deleteSelf);
- } catch (KeeperException.NoNodeException e) {
+ deleteChildren(zookeeper, path, true);
+ }
+ catch ( KeeperException.NoNodeException e )
+ {
// ignore... someone else has deleted the node it since we checked
}
}
@@ -247,12 +250,10 @@ public class ZKPaths
* @param zookeeper the client
* @param path the path
* @return sorted list of children
- * @throws InterruptedException thread interruption
- * @throws org.apache.zookeeper.KeeperException
- * zookeeper errors
+ * @throws InterruptedException thread interruption
+ * @throws org.apache.zookeeper.KeeperException zookeeper errors
*/
- public static List<String> getSortedChildren(ZooKeeper zookeeper, String path)
- throws InterruptedException, KeeperException
+ public static List<String> getSortedChildren(ZooKeeper zookeeper, String path) throws InterruptedException, KeeperException
{
List<String> children = zookeeper.getChildren(path, false);
List<String> sortedList = Lists.newArrayList(children);
@@ -272,7 +273,7 @@ public class ZKPaths
StringBuilder path = new StringBuilder();
// Add parent piece, with no trailing slash.
- if ( parent != null && parent.length() > 0)
+ if ( (parent != null) && (parent.length() > 0) )
{
if ( !parent.startsWith("/") )
{
http://git-wip-us.apache.org/repos/asf/curator/blob/49c20982/curator-client/src/test/java/org/apache/curator/utils/TestZKPaths.java
----------------------------------------------------------------------
diff --git a/curator-client/src/test/java/org/apache/curator/utils/TestZKPaths.java b/curator-client/src/test/java/org/apache/curator/utils/TestZKPaths.java
index f757984..fb49d8b 100644
--- a/curator-client/src/test/java/org/apache/curator/utils/TestZKPaths.java
+++ b/curator-client/src/test/java/org/apache/curator/utils/TestZKPaths.java
@@ -27,6 +27,11 @@ public class TestZKPaths
@Test
public void testMakePath()
{
+ Assert.assertEquals(ZKPaths.makePath(null, "/"), "/");
+ Assert.assertEquals(ZKPaths.makePath("", null), "/");
+ Assert.assertEquals(ZKPaths.makePath("/", null), "/");
+ Assert.assertEquals(ZKPaths.makePath(null, null), "/");
+
Assert.assertEquals(ZKPaths.makePath("/", "/"), "/");
Assert.assertEquals(ZKPaths.makePath("", "/"), "/");
Assert.assertEquals(ZKPaths.makePath("/", ""), "/");
@@ -37,11 +42,21 @@ public class TestZKPaths
Assert.assertEquals(ZKPaths.makePath("/foo", ""), "/foo");
Assert.assertEquals(ZKPaths.makePath("/foo", "/"), "/foo");
+ Assert.assertEquals(ZKPaths.makePath("foo", null), "/foo");
+ Assert.assertEquals(ZKPaths.makePath("foo", null), "/foo");
+ Assert.assertEquals(ZKPaths.makePath("/foo", null), "/foo");
+ Assert.assertEquals(ZKPaths.makePath("/foo", null), "/foo");
+
Assert.assertEquals(ZKPaths.makePath("", "bar"), "/bar");
Assert.assertEquals(ZKPaths.makePath("/", "bar"), "/bar");
Assert.assertEquals(ZKPaths.makePath("", "/bar"), "/bar");
Assert.assertEquals(ZKPaths.makePath("/", "/bar"), "/bar");
+ Assert.assertEquals(ZKPaths.makePath(null, "bar"), "/bar");
+ Assert.assertEquals(ZKPaths.makePath(null, "bar"), "/bar");
+ Assert.assertEquals(ZKPaths.makePath(null, "/bar"), "/bar");
+ Assert.assertEquals(ZKPaths.makePath(null, "/bar"), "/bar");
+
Assert.assertEquals(ZKPaths.makePath("foo", "bar"), "/foo/bar");
Assert.assertEquals(ZKPaths.makePath("/foo", "bar"), "/foo/bar");
Assert.assertEquals(ZKPaths.makePath("foo", "/bar"), "/foo/bar");
[2/2] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/curator
Posted by ra...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/curator
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/10bd72c5
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/10bd72c5
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/10bd72c5
Branch: refs/heads/master
Commit: 10bd72c510edff5f065bab6cd969ef0e6132ac85
Parents: 49c2098 bd319a9
Author: randgalt <ra...@apache.org>
Authored: Wed Jul 30 12:29:07 2014 -0500
Committer: randgalt <ra...@apache.org>
Committed: Wed Jul 30 12:29:07 2014 -0500
----------------------------------------------------------------------
----------------------------------------------------------------------