Repository: curator
Updated Branches:
  refs/heads/CURATOR-397 3a3e6dd2d -> 0cafc9199


fixed typo bug with the cached values in ZPath - also made them more efficient


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

Branch: refs/heads/CURATOR-397
Commit: 0cafc9199f3136f4f22703793bd56c73319d3161
Parents: 3a3e6dd
Author: randgalt <[email protected]>
Authored: Tue Apr 25 14:29:35 2017 -0500
Committer: randgalt <[email protected]>
Committed: Tue Apr 25 14:29:35 2017 -0500

----------------------------------------------------------------------
 .../apache/curator/test/BaseClassForTests.java  | 10 +++++++---
 .../apache/curator/x/async/modeled/ZPath.java   | 11 ++++++++---
 .../details/ModeledCuratorFrameworkImpl.java    |  2 +-
 .../x/async/modeled/details/ZPathImpl.java      | 18 ++++++++++++------
 .../curator/x/async/modeled/TestZPath.java      | 20 ++++++++++----------
 5 files changed, 38 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/0cafc919/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
----------------------------------------------------------------------
diff --git 
a/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java 
b/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
index 5114552..8238c82 100644
--- a/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
+++ b/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
@@ -27,12 +27,12 @@ import org.testng.IRetryAnalyzer;
 import org.testng.ITestContext;
 import org.testng.ITestNGMethod;
 import org.testng.ITestResult;
-import org.testng.TestListenerAdapter;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.BeforeSuite;
 import java.io.IOException;
 import java.net.BindException;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -155,7 +155,7 @@ public class BaseClassForTests
         RetryAnalyzer(Logger log, RetryContext retryContext)
         {
             this.log = log;
-            this.retryContext = retryContext;
+            this.retryContext = Objects.requireNonNull(retryContext, 
"retryContext cannot be null");
         }
 
         @Override
@@ -218,7 +218,11 @@ public class BaseClassForTests
             }
             else if ( method.isTestMethod() )
             {
-                method.getTestMethod().setRetryAnalyzer(new RetryAnalyzer(log, 
(RetryContext)context.getAttribute(ATTRIBUTE_NAME)));
+                RetryContext retryContext = 
(RetryContext)context.getAttribute(ATTRIBUTE_NAME);
+                if ( retryContext != null )
+                {
+                    method.getTestMethod().setRetryAnalyzer(new 
RetryAnalyzer(log, retryContext));
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/curator/blob/0cafc919/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java
----------------------------------------------------------------------
diff --git 
a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java 
b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java
index 3e0dc2d..0f1556b 100644
--- 
a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java
+++ 
b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ZPath.java
@@ -26,9 +26,14 @@ import org.apache.curator.x.async.modeled.details.ZPathImpl;
 public interface ZPath
 {
     /**
-     * The root path: "/"
+     * Return the root path: "/"
+     *
+     * @return root path
      */
-    ZPath root = ZPathImpl.root;
+    static ZPath root()
+    {
+        return ZPathImpl.root;
+    }
 
     /**
      * Take a ZNode string path and return a ZPath
@@ -52,7 +57,7 @@ public interface ZPath
      */
     static ZPath from(String... names)
     {
-        ZPath path = root;
+        ZPath path = root();
         for ( String n : names )
         {
             path = path.at(n);

http://git-wip-us.apache.org/repos/asf/curator/blob/0cafc919/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git 
a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java
 
b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java
index 1926cf0..ebe9d62 100644
--- 
a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java
+++ 
b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCuratorFrameworkImpl.java
@@ -126,7 +126,7 @@ public class ModeledCuratorFrameworkImpl<T> implements 
ModeledCuratorFramework<T
         long dirtyZxid = getDirtyZxid();
         byte[] bytes = model.serializer().serialize(item);
         AsyncStage<String> asyncStage = 
dslClient.create().withOptions(model.createOptions(), model.createMode(), 
fixAclList(model.aclList()), storingStatIn).forPath(model.path().fullPath(), 
bytes);
-        ModelStage<String> modelStage = new ModelStage<>(asyncStage.event());
+        ModelStage<String> modelStage = new ModelStage<>();
         markDirtyCompleter(dirtyZxid, asyncStage, modelStage);
         return modelStage;
     }

http://git-wip-us.apache.org/repos/asf/curator/blob/0cafc919/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
----------------------------------------------------------------------
diff --git 
a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
 
b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
index 75f2fe7..8c51e32 100644
--- 
a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
+++ 
b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
@@ -27,13 +27,13 @@ import java.util.Collections;
 import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.Objects;
-import java.util.concurrent.atomic.AtomicReference;
 
 public class ZPathImpl implements ZPath
 {
     public static final ZPath root = new 
ZPathImpl(Collections.singletonList(ZKPaths.PATH_SEPARATOR));
-    public static final AtomicReference<String> fullPathCache = new 
AtomicReference<>();
-    public static final AtomicReference<String> parentPathCache = new 
AtomicReference<>();
+
+    private volatile String fullPathCache = null;
+    private volatile String parentPathCache = null;
 
     private final List<String> nodes;
 
@@ -138,8 +138,7 @@ public class ZPathImpl implements ZPath
 
     private String buildFullPath(boolean parent)
     {
-        AtomicReference<String> cache = parent ? parentPathCache : 
fullPathCache;
-        String path = cache.get();
+        String path = parent ? parentPathCache : fullPathCache;
         if ( path != null )
         {
             return path;
@@ -158,7 +157,14 @@ public class ZPathImpl implements ZPath
         }
         path = str.toString();
 
-        cache.compareAndSet(null, path);
+        if ( parent )
+        {
+            parentPathCache = path;
+        }
+        else
+        {
+            fullPathCache = path;
+        }
         return path;
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/0cafc919/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
----------------------------------------------------------------------
diff --git 
a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
 
b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
index f3c3dff..c6049f2 100644
--- 
a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
+++ 
b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestZPath.java
@@ -28,20 +28,20 @@ public class TestZPath
     @Test
     public void testRoot()
     {
-        Assert.assertEquals(ZPath.root.nodeName(), ZKPaths.PATH_SEPARATOR);
-        Assert.assertEquals(ZPath.root, ZPathImpl.root);
-        Assert.assertTrue(ZPath.root.isRoot());
-        Assert.assertEquals(ZPath.root.at("foo").parent(), ZPath.root);
-        Assert.assertTrue(ZPath.root.at("foo").parent().isRoot());
+        Assert.assertEquals(ZPath.root().nodeName(), ZKPaths.PATH_SEPARATOR);
+        Assert.assertEquals(ZPath.root(), ZPathImpl.root);
+        Assert.assertTrue(ZPath.root().isRoot());
+        Assert.assertEquals(ZPath.root().at("foo").parent(), ZPath.root());
+        Assert.assertTrue(ZPath.root().at("foo").parent().isRoot());
     }
 
     @Test
     public void testBasic()
     {
-        ZPath path = ZPath.root.at("one").at("two");
+        ZPath path = ZPath.root().at("one").at("two");
         Assert.assertFalse(path.isRoot());
-        Assert.assertEquals(path, ZPath.root.at("one").at("two"));
-        Assert.assertNotEquals(path, ZPath.root.at("onex").at("two"));
+        Assert.assertEquals(path, ZPath.root().at("one").at("two"));
+        Assert.assertNotEquals(path, ZPath.root().at("onex").at("two"));
         Assert.assertEquals(path.nodeName(), "two");
         Assert.assertEquals(path.fullPath(), "/one/two");
         Assert.assertEquals(path.parentPath(), "/one");
@@ -50,8 +50,8 @@ public class TestZPath
     @Test
     public void testParsing()
     {
-        Assert.assertEquals(ZPath.parse("/"), ZPath.root);
-        Assert.assertEquals(ZPath.parse("/one/two/three"), 
ZPath.root.at("one").at("two").at("three"));
+        Assert.assertEquals(ZPath.parse("/"), ZPath.root());
+        Assert.assertEquals(ZPath.parse("/one/two/three"), 
ZPath.root().at("one").at("two").at("three"));
         Assert.assertEquals(ZPath.parse("/one/two/three"), ZPath.from("one", 
"two", "three"));
     }
 }

Reply via email to