Support getConfig

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

Branch: refs/heads/CURATOR-3.0
Commit: 3d0fdbac0c337c26dce3e733b4ad0441911cc2c8
Parents: 6222282
Author: randgalt <randg...@apache.org>
Authored: Thu Jan 5 16:14:08 2017 -0500
Committer: randgalt <randg...@apache.org>
Committed: Thu Jan 5 16:14:08 2017 -0500

----------------------------------------------------------------------
 .../curator/x/crimps/async/AsyncCrimps.java      | 19 ++++++++++++++++++-
 .../x/crimps/async/CrimpedEnsembleableImpl.java  | 16 +++++++++++++---
 .../curator/x/crimps/async/TestCrimps.java       | 15 +++++++++++++++
 3 files changed, 46 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/3d0fdbac/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/AsyncCrimps.java
----------------------------------------------------------------------
diff --git 
a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/AsyncCrimps.java
 
b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/AsyncCrimps.java
index b9a330c..d4c1545 100644
--- 
a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/AsyncCrimps.java
+++ 
b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/AsyncCrimps.java
@@ -103,6 +103,23 @@ public class AsyncCrimps
         return build(builder, statSupplier);
     }
 
+    public CrimpedEnsembleable 
ensemble(Backgroundable<ErrorListenerEnsembleable<byte[]>> builder)
+    {
+        CrimpedBackgroundCallback<byte[]> callback = new 
CrimpedBackgroundCallback<>(dataSupplier);
+
+        Ensembleable<byte[]> main;
+        if ( unhandledErrorListener != null )
+        {
+            main = 
builder.inBackground(callback).withUnhandledErrorListener(unhandledErrorListener);
+        }
+        else
+        {
+            main = builder.inBackground(callback);
+        }
+
+        return new CrimpedEnsembleableImpl(main, callback);
+    }
+
     public CrimpedEnsembleable 
ensemble(Backgroundable<ErrorListenerReconfigBuilderMain> builder, List<String> 
newMembers)
     {
         CrimpedBackgroundCallback<byte[]> callback = new 
CrimpedBackgroundCallback<>(dataSupplier);
@@ -117,7 +134,7 @@ public class AsyncCrimps
             main = builder.inBackground(callback);
         }
 
-        return new CrimpedEnsembleableImpl(main.withNewMembers(newMembers), 
callback);
+        return new 
CrimpedEnsembleableImpl((Statable<ConfigureEnsembleable>)main.withNewMembers(newMembers),
 callback);
     }
 
     public CrimpedEnsembleable 
ensemble(Backgroundable<ErrorListenerReconfigBuilderMain> builder, List<String> 
joining, List<String> leaving)

http://git-wip-us.apache.org/repos/asf/curator/blob/3d0fdbac/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleableImpl.java
----------------------------------------------------------------------
diff --git 
a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleableImpl.java
 
b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleableImpl.java
index 116ce56..035e9bf 100644
--- 
a/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleableImpl.java
+++ 
b/curator-x-crimps/src/main/java/org/apache/curator/x/crimps/async/CrimpedEnsembleableImpl.java
@@ -28,6 +28,7 @@ class CrimpedEnsembleableImpl implements CrimpedEnsembleable
 {
     private final CrimpedBackgroundCallback<byte[]> callback;
     private final Statable<ConfigureEnsembleable> configBuilder;
+    private Ensembleable<byte[]> ensembleable;
     private ConfigureEnsembleable configureEnsembleable;
 
     CrimpedEnsembleableImpl(Statable<ConfigureEnsembleable> configBuilder, 
CrimpedBackgroundCallback<byte[]> callback)
@@ -35,26 +36,35 @@ class CrimpedEnsembleableImpl implements CrimpedEnsembleable
         this.configBuilder = configBuilder;
         this.callback = callback;
         configureEnsembleable = configBuilder.storingStatIn(new Stat());
+        ensembleable = configureEnsembleable;
+    }
+
+    CrimpedEnsembleableImpl(Ensembleable<byte[]> ensembleable, 
CrimpedBackgroundCallback<byte[]> callback)
+    {
+        this.ensembleable = ensembleable;
+        this.configBuilder = null;
+        this.callback = callback;
+        configureEnsembleable = null;
     }
 
     @Override
     public CompletionStage<byte[]> forEnsemble() throws Exception
     {
-        configureEnsembleable.forEnsemble();
+        ensembleable.forEnsemble();
         return callback;
     }
 
     @Override
     public CrimpedConfigEnsembleable storingStatIn(Stat stat)
     {
-        configureEnsembleable = configBuilder.storingStatIn(stat);
+        ensembleable = configureEnsembleable = 
configBuilder.storingStatIn(stat);
         return this;
     }
 
     @Override
     public Ensembleable<CompletionStage<byte[]>> fromConfig(long config) 
throws Exception
     {
-        configureEnsembleable.fromConfig(config);
+        ensembleable = configureEnsembleable.fromConfig(config);
         return this;
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/3d0fdbac/curator-x-crimps/src/test/java/org/apache/curator/x/crimps/async/TestCrimps.java
----------------------------------------------------------------------
diff --git 
a/curator-x-crimps/src/test/java/org/apache/curator/x/crimps/async/TestCrimps.java
 
b/curator-x-crimps/src/test/java/org/apache/curator/x/crimps/async/TestCrimps.java
index 7f5647a..2a0ac00 100644
--- 
a/curator-x-crimps/src/test/java/org/apache/curator/x/crimps/async/TestCrimps.java
+++ 
b/curator-x-crimps/src/test/java/org/apache/curator/x/crimps/async/TestCrimps.java
@@ -107,6 +107,21 @@ public class TestCrimps extends BaseClassForTests
         }
     }
 
+    @Test
+    public void testGetConfig() throws Exception
+    {
+        try ( CuratorFramework client = 
CuratorFrameworkFactory.newClient(server.getConnectString(), new 
RetryOneTime(1)) )
+        {
+            client.start();
+
+            CompletionStage<byte[]> f = 
async.ensemble(client.getConfig()).forEnsemble();
+            complete(f.handle((data, e) -> {
+                Assert.assertNotNull(data);
+                return null;
+            }));
+        }
+    }
+
     public void assertException(CompletionStage<?> f, KeeperException.Code 
code) throws Exception
     {
         complete(f.handle((value, e) -> {

Reply via email to