You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2017/02/09 18:36:19 UTC
[20/47] curator git commit: let the testing begin
let the testing begin
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/177cca65
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/177cca65
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/177cca65
Branch: refs/heads/CURATOR-3.0
Commit: 177cca658f902bc0e79599b2f698d73cdf08e3be
Parents: 394eb90
Author: randgalt <ra...@apache.org>
Authored: Fri Jan 6 13:51:47 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Fri Jan 6 13:51:47 2017 -0500
----------------------------------------------------------------------
.../x/async/details/AsyncCreateBuilderImpl.java | 4 +-
.../async/details/AsyncSetDataBuilderImpl.java | 2 +-
.../curator/x/async/TestBasicOperations.java | 110 +++++++++++++++++++
3 files changed, 113 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/177cca65/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCreateBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCreateBuilderImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCreateBuilderImpl.java
index 53a44b7..fb52154 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCreateBuilderImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCreateBuilderImpl.java
@@ -33,7 +33,7 @@ import java.util.List;
import java.util.Objects;
import java.util.Set;
-import static org.apache.curator.x.async.details.BackgroundProcs.pathProc;
+import static org.apache.curator.x.async.details.BackgroundProcs.nameProc;
import static org.apache.curator.x.async.details.BackgroundProcs.safeCall;
class AsyncCreateBuilderImpl implements AsyncCreateBuilder
@@ -128,7 +128,7 @@ class AsyncCreateBuilderImpl implements AsyncCreateBuilder
private AsyncStage<String> internalForPath(String path, byte[] data, boolean useData)
{
- BuilderCommon<String> common = new BuilderCommon<>(unhandledErrorListener, false, pathProc);
+ BuilderCommon<String> common = new BuilderCommon<>(unhandledErrorListener, false, nameProc);
CreateBuilderImpl builder = new CreateBuilderImpl(client,
createMode,
common.backgrounding,
http://git-wip-us.apache.org/repos/asf/curator/blob/177cca65/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncSetDataBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncSetDataBuilderImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncSetDataBuilderImpl.java
index eb05666..9216af9 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncSetDataBuilderImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncSetDataBuilderImpl.java
@@ -80,6 +80,6 @@ class AsyncSetDataBuilderImpl implements AsyncSetDataBuilder
{
BuilderCommon<Stat> common = new BuilderCommon<>(unhandledErrorListener, false, statProc);
SetDataBuilderImpl builder = new SetDataBuilderImpl(client, common.backgrounding, version, compressed);
- return safeCall(common.internalCallback, () -> useData ? builder.forPath(path) : builder.forPath(path, data));
+ return safeCall(common.internalCallback, () -> useData ? builder.forPath(path, data) : builder.forPath(path));
}
}
http://git-wip-us.apache.org/repos/asf/curator/blob/177cca65/curator-x-async/src/test/java/org/apache/curator/x/async/TestBasicOperations.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/test/java/org/apache/curator/x/async/TestBasicOperations.java b/curator-x-async/src/test/java/org/apache/curator/x/async/TestBasicOperations.java
new file mode 100644
index 0000000..a87b3f0
--- /dev/null
+++ b/curator-x-async/src/test/java/org/apache/curator/x/async/TestBasicOperations.java
@@ -0,0 +1,110 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.async;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.RetryOneTime;
+import org.apache.curator.test.BaseClassForTests;
+import org.apache.curator.test.Timing;
+import org.apache.curator.utils.CloseableUtils;
+import org.apache.zookeeper.CreateMode;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
+import java.util.function.BiFunction;
+
+public class TestBasicOperations extends BaseClassForTests
+{
+ private static final Timing timing = new Timing();
+ private AsyncCuratorFramework client;
+
+ @BeforeMethod
+ @Override
+ public void setup() throws Exception
+ {
+ super.setup();
+
+ CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(timing.milliseconds()));
+ client.start();
+ this.client = AsyncCuratorFramework.wrap(client);
+ }
+
+ @AfterMethod
+ @Override
+ public void teardown() throws Exception
+ {
+ CloseableUtils.closeQuietly(client.unwrap());
+
+ super.teardown();
+ }
+
+ @Test
+ public void testCrud()
+ {
+ AsyncStage<String> createStage = client.create().forPath("/test", "one".getBytes());
+ complete(createStage, (path, e) -> {
+ Assert.assertEquals(path, "/test");
+ return null;
+ });
+
+ AsyncStage<byte[]> getStage = client.getData().forPath("/test");
+ complete(getStage, (data, e) -> {
+ Assert.assertEquals(data, "one".getBytes());
+ return null;
+ });
+
+ CompletionStage<byte[]> combinedStage = client.setData().forPath("/test", "new".getBytes()).thenCompose(
+ __ -> client.getData().forPath("/test"));
+ complete(combinedStage, (data, e) -> {
+ Assert.assertEquals(data, "new".getBytes());
+ return null;
+ });
+
+ CompletionStage<Void> combinedDelete = client.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/deleteme").thenCompose(
+ path -> client.delete().forPath(path));
+ complete(combinedDelete, (v, e) -> {
+ Assert.assertNull(e);
+ return null;
+ });
+ }
+
+ private <T, U> void complete(CompletionStage<T> stage, BiFunction<? super T, Throwable, ? extends U> handler)
+ {
+ try
+ {
+ stage.handle(handler).toCompletableFuture().get();
+ }
+ catch ( InterruptedException e )
+ {
+ Thread.interrupted();
+ }
+ catch ( ExecutionException e )
+ {
+ if ( e.getCause() instanceof AssertionError )
+ {
+ throw (AssertionError)e.getCause();
+ }
+ Assert.fail("get() failed", e);
+ }
+ }
+}