This is an automated email from the ASF dual-hosted git repository.

randgalt pushed a commit to branch CURATOR-546-ModeledCacheImpl-removes-zpath
in repository https://gitbox.apache.org/repos/asf/curator.git

commit 551e86647aa7b806389f9f8b7d53bf1d5e11e189
Author: randgalt <[email protected]>
AuthorDate: Fri Oct 11 08:25:36 2019 +0300

    CURATOR-546
    
    Bad copy/paste bug. ModeledCacheImpl.currentData() was removing from 
entries instead of calling get()
---
 .../x/async/modeled/details/ModeledCacheImpl.java  |  2 +-
 .../async/modeled/TestCachedModeledFramework.java  | 32 ++++++++++++++++------
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git 
a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
 
b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
index 72e6762..b95e92d 100644
--- 
a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
+++ 
b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
@@ -100,7 +100,7 @@ class ModeledCacheImpl<T> implements TreeCacheListener, 
ModeledCache<T>
     @Override
     public Optional<ZNode<T>> currentData(ZPath path)
     {
-        Entry<T> entry = entries.remove(path);
+        Entry<T> entry = entries.get(path);
         if ( entry != null )
         {
             return Optional.of(new ZNodeImpl<>(path, entry.stat, entry.model));
diff --git 
a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestCachedModeledFramework.java
 
b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestCachedModeledFramework.java
index 825d4b7..2d33c13 100644
--- 
a/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestCachedModeledFramework.java
+++ 
b/curator-x-async/src/test/java/org/apache/curator/x/async/modeled/TestCachedModeledFramework.java
@@ -30,6 +30,7 @@ import java.io.IOException;
 import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Semaphore;
@@ -144,15 +145,30 @@ public class TestCachedModeledFramework extends 
TestModeledFrameworkBase
                 });
             });
 
-            complete(client.child("p").child("c1").childrenAsZNodes(), (v, e) 
->
-            {
-                Assert.assertEquals(toSet(v.stream(), ZNode::model), 
Sets.newHashSet(grandChild1));
-            });
+            complete(client.child("p").child("c1").childrenAsZNodes(), (v, e) 
-> Assert.assertEquals(toSet(v.stream(), ZNode::model), 
Sets.newHashSet(grandChild1)));
+            complete(client.child("p").child("c2").childrenAsZNodes(), (v, e) 
-> Assert.assertEquals(toSet(v.stream(), ZNode::model), 
Sets.newHashSet(grandChild2)));
+        }
+    }
 
-            complete(client.child("p").child("c2").childrenAsZNodes(), (v, e) 
->
-            {
-                Assert.assertEquals(toSet(v.stream(), ZNode::model), 
Sets.newHashSet(grandChild2));
-            });
+    // note: CURATOR-546
+    @Test
+    public void testAccessCacheDirectly()
+    {
+        TestModel model = new TestModel("a", "b", "c", 20, BigInteger.ONE);
+        try (CachedModeledFramework<TestModel> client = 
ModeledFramework.wrap(async, modelSpec).cached())
+        {
+            CountDownLatch latch = new CountDownLatch(1);
+            client.listenable().addListener((t, p, s, m) -> latch.countDown());
+
+            client.start();
+            complete(client.child("m").set(model));
+            Assert.assertTrue(timing.awaitLatch(latch));
+
+            // call 2 times in a row to validate CURATOR-546
+            Optional<ZNode<TestModel>> optZNode = 
client.cache().currentData(modelSpec.path().child("m"));
+            Assert.assertEquals(optZNode.orElseThrow(() -> new 
AssertionError("node is missing")).model(), model);
+            optZNode = client.cache().currentData(modelSpec.path().child("m"));
+            Assert.assertEquals(optZNode.orElseThrow(() -> new 
AssertionError("node is missing")).model(), model);
         }
     }
 

Reply via email to