Repository: curator Updated Branches: refs/heads/CURATOR-3.0 20c6955b1 -> 5ff8aaae8
Fixed CURATOR-329 - SharedValue.start() method does not update to current value if version of value currently stored in zookeeper is 0 Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/f12f35d0 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/f12f35d0 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/f12f35d0 Branch: refs/heads/CURATOR-3.0 Commit: f12f35d0f78198e1f9f89a8cf3dafc7b07404220 Parents: d63e06e Author: Algirdas Rascius <[email protected]> Authored: Tue May 24 16:45:45 2016 +0300 Committer: Algirdas Rascius <[email protected]> Committed: Tue May 24 16:45:45 2016 +0300 ---------------------------------------------------------------------- .../framework/recipes/shared/SharedValue.java | 4 ++- .../recipes/shared/TestSharedCount.java | 27 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/f12f35d0/curator-recipes/src/main/java/org/apache/curator/framework/recipes/shared/SharedValue.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/shared/SharedValue.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/shared/SharedValue.java index 17a2943..dddc471 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/shared/SharedValue.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/shared/SharedValue.java @@ -44,6 +44,8 @@ import java.util.concurrent.atomic.AtomicReference; */ public class SharedValue implements Closeable, SharedValueReader { + private static final int UNINITIALIZED_VERSION = -1; + private final Logger log = LoggerFactory.getLogger(getClass()); private final ListenerContainer<SharedValueListener> listeners = new ListenerContainer<SharedValueListener>(); private final CuratorFramework client; @@ -91,7 +93,7 @@ public class SharedValue implements Closeable, SharedValueReader this.client = client; this.path = PathUtils.validatePath(path); this.seedValue = Arrays.copyOf(seedValue, seedValue.length); - currentValue = new AtomicReference<VersionedValue<byte[]>>(new VersionedValue<byte[]>(0, Arrays.copyOf(seedValue, seedValue.length))); + currentValue = new AtomicReference<VersionedValue<byte[]>>(new VersionedValue<byte[]>(UNINITIALIZED_VERSION, Arrays.copyOf(seedValue, seedValue.length))); } @Override http://git-wip-us.apache.org/repos/asf/curator/blob/f12f35d0/curator-recipes/src/test/java/org/apache/curator/framework/recipes/shared/TestSharedCount.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/shared/TestSharedCount.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/shared/TestSharedCount.java index 659154a..a1f4d8c 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/shared/TestSharedCount.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/shared/TestSharedCount.java @@ -256,4 +256,31 @@ public class TestSharedCount extends BaseClassForTests CloseableUtils.closeQuietly(client1); } } + + + @Test + public void testMultiClientDifferentSeed() throws Exception + { + CuratorFramework client1 = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); + CuratorFramework client2 = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); + SharedCount count1 = new SharedCount(client1, "/count", 10); + SharedCount count2 = new SharedCount(client2, "/count", 20); + try + { + client1.start(); + client2.start(); + count1.start(); + count2.start(); + + Assert.assertEquals(count1.getCount(), 10); + Assert.assertEquals(count2.getCount(), 10); + } + finally + { + CloseableUtils.closeQuietly(count2); + CloseableUtils.closeQuietly(count1); + CloseableUtils.closeQuietly(client2); + CloseableUtils.closeQuietly(client1); + } + } }
