curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject curator git commit: Refactoring and more tests
Date Tue, 19 May 2015 22:26:09 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-222 35ec01c08 -> 12baea342


Refactoring and more tests


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/12baea34
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/12baea34
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/12baea34

Branch: refs/heads/CURATOR-222
Commit: 12baea342d2b35c48bfb17327b0736a179d04d32
Parents: 35ec01c
Author: randgalt <randgalt@apache.org>
Authored: Tue May 19 15:26:06 2015 -0700
Committer: randgalt <randgalt@apache.org>
Committed: Tue May 19 15:26:06 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/curator/utils/ZKPaths.java  | 13 ++-
 .../curator/framework/imps/TestFramework.java   | 89 +++++++++++++++++++-
 2 files changed, 93 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/12baea34/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 242e4b7..13b0cba 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
@@ -53,17 +53,14 @@ public class ZKPaths
 
         static
         {
-            CreateMode localCreateMode = CreateMode.PERSISTENT;
-            for ( CreateMode createMode : CreateMode.class.getEnumConstants() )
+            CreateMode localCreateMode;
+            try
             {
-                if ( createMode.name().equals("CONTAINER") )
-                {
-                    localCreateMode = createMode;
-                    break;
-                }
+                localCreateMode = CreateMode.valueOf("CONTAINER");
             }
-            if ( localCreateMode == CreateMode.PERSISTENT )
+            catch ( IllegalArgumentException ignore )
             {
+                localCreateMode = CreateMode.PERSISTENT;
                 log.warn("The version of ZooKeeper being used doesn't support Container nodes.
CreateMode.PERSISTENT will be used instead");
             }
             containerCreateMode = localCreateMode;

http://git-wip-us.apache.org/repos/asf/curator/blob/12baea34/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
index ac21172..15db5de 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
@@ -419,13 +419,100 @@ public class TestFramework extends BaseClassForTests
     }
 
     @Test
+    public void testOverrideCreateParentContainers() throws Exception
+    {
+        CuratorFramework client = CuratorFrameworkFactory.builder()
+            .connectString(server.getConnectString())
+            .retryPolicy(new RetryOneTime(1))
+            .dontUseContainerParents()
+            .build();
+        try
+        {
+            client.start();
+            client.create().creatingParentContainersIfNeeded().forPath("/one/two/three",
"foo".getBytes());
+            byte[] data = client.getData().forPath("/one/two/three");
+            Assert.assertEquals(data, "foo".getBytes());
+
+            client.delete().forPath("/one/two/three");
+            new Timing().sleepABit();
+
+            Assert.assertNotNull(client.checkExists().forPath("/one/two"));
+            new Timing().sleepABit();
+            Assert.assertNotNull(client.checkExists().forPath("/one"));
+        }
+        finally
+        {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testOverrideEnsureParentContainers() throws Exception
+    {
+        CuratorFramework client = CuratorFrameworkFactory.builder()
+            .connectString(server.getConnectString())
+            .retryPolicy(new RetryOneTime(1))
+            .dontUseContainerParents()
+            .build();
+        try
+        {
+            client.start();
+            EnsurePath ensurePath = client.newNamespaceAwareEnsurePathContainers("/one/two");
+            ensurePath.ensure(client.getZookeeperClient());
+            client.create().creatingParentContainersIfNeeded().forPath("/one/two/three",
"foo".getBytes());
+            byte[] data = client.getData().forPath("/one/two/three");
+            Assert.assertEquals(data, "foo".getBytes());
+
+            client.delete().forPath("/one/two/three");
+            new Timing().sleepABit();
+
+            Assert.assertNotNull(client.checkExists().forPath("/one/two"));
+            new Timing().sleepABit();
+            Assert.assertNotNull(client.checkExists().forPath("/one"));
+        }
+        finally
+        {
+            client.close();
+        }
+    }
+
+    @Test
+    public void testEnsureParentContainers() throws Exception
+    {
+        CuratorFramework client = CuratorFrameworkFactory.builder()
+            .connectString(server.getConnectString())
+            .retryPolicy(new RetryOneTime(1))
+            .build();
+        try
+        {
+            client.start();
+            EnsurePath ensurePath = client.newNamespaceAwareEnsurePathContainers("/one/two");
+            ensurePath.ensure(client.getZookeeperClient());
+            client.create().creatingParentContainersIfNeeded().forPath("/one/two/three",
"foo".getBytes());
+            byte[] data = client.getData().forPath("/one/two/three");
+            Assert.assertEquals(data, "foo".getBytes());
+
+            client.delete().forPath("/one/two/three");
+            new Timing().sleepABit();
+
+            Assert.assertNull(client.checkExists().forPath("/one/two"));
+            new Timing().sleepABit();
+            Assert.assertNull(client.checkExists().forPath("/one"));
+        }
+        finally
+        {
+            client.close();
+        }
+    }
+
+    @Test
     public void testCreateParentContainers() throws Exception
     {
         CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
         CuratorFramework client = builder.connectString(server.getConnectString()).retryPolicy(new
RetryOneTime(1)).build();
-        client.start();
         try
         {
+            client.start();
             client.create().creatingParentContainersIfNeeded().forPath("/one/two/three",
"foo".getBytes());
             byte[] data = client.getData().forPath("/one/two/three");
             Assert.assertEquals(data, "foo".getBytes());


Mime
View raw message