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 2016/04/21 03:13:20 UTC
[21/33] curator git commit: Expand CuratorTransactionResult to hold
an error and include it in background multi calls
Expand CuratorTransactionResult to hold an error and include it in background multi calls
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/8ef32cc2
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/8ef32cc2
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/8ef32cc2
Branch: refs/heads/CURATOR-299
Commit: 8ef32cc275f94a10576fc1a963d9f8db50ad382f
Parents: 50550ee
Author: randgalt <ra...@apache.org>
Authored: Wed Mar 2 14:41:31 2016 -0500
Committer: randgalt <ra...@apache.org>
Committed: Wed Mar 2 14:41:31 2016 -0500
----------------------------------------------------------------------
.../transaction/CuratorTransactionResult.java | 18 +++++++++++
.../framework/imps/CuratorTransactionImpl.java | 10 +++++-
.../framework/imps/TestTransactionsNew.java | 34 ++++++++++++++++++++
3 files changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/8ef32cc2/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/CuratorTransactionResult.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/CuratorTransactionResult.java b/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/CuratorTransactionResult.java
index 8d8dc2d..ba75791 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/CuratorTransactionResult.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/CuratorTransactionResult.java
@@ -20,6 +20,7 @@
package org.apache.curator.framework.api.transaction;
import com.google.common.base.Predicate;
+import org.apache.zookeeper.OpResult;
import org.apache.zookeeper.data.Stat;
/**
@@ -31,6 +32,7 @@ public class CuratorTransactionResult
private final String forPath;
private final String resultPath;
private final Stat resultStat;
+ private final int error;
/**
* Utility that can be passed to Google Guava to find a particular result. E.g.
@@ -56,10 +58,16 @@ public class CuratorTransactionResult
public CuratorTransactionResult(OperationType type, String forPath, String resultPath, Stat resultStat)
{
+ this(type, forPath, resultPath, resultStat, 0);
+ }
+
+ public CuratorTransactionResult(OperationType type, String forPath, String resultPath, Stat resultStat, int error)
+ {
this.forPath = forPath;
this.resultPath = resultPath;
this.resultStat = resultStat;
this.type = type;
+ this.error = error;
}
/**
@@ -103,4 +111,14 @@ public class CuratorTransactionResult
{
return resultStat;
}
+
+ /**
+ * Returns the operation generated error or <code>0</code> i.e. {@link OpResult.ErrorResult#getErr()}
+ *
+ * @return error or 0
+ */
+ public int getError()
+ {
+ return error;
+ }
}
http://git-wip-us.apache.org/repos/asf/curator/blob/8ef32cc2/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorTransactionImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorTransactionImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorTransactionImpl.java
index 424ecc6..34dc6e1 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorTransactionImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorTransactionImpl.java
@@ -158,6 +158,7 @@ class CuratorTransactionImpl implements CuratorTransaction, CuratorTransactionBr
{
String resultPath = null;
Stat resultStat = null;
+ int error = 0;
switch ( opResult.getType() )
{
default:
@@ -179,9 +180,16 @@ class CuratorTransactionImpl implements CuratorTransaction, CuratorTransactionBr
resultStat = setDataResult.getStat();
break;
}
+
+ case ZooDefs.OpCode.error:
+ {
+ OpResult.ErrorResult errorResult = (OpResult.ErrorResult)opResult;
+ error = errorResult.getErr();
+ break;
+ }
}
- return new CuratorTransactionResult(metadata.getType(), metadata.getForPath(), resultPath, resultStat);
+ return new CuratorTransactionResult(metadata.getType(), metadata.getForPath(), resultPath, resultStat, error);
}
private List<OpResult> doOperation() throws Exception
http://git-wip-us.apache.org/repos/asf/curator/blob/8ef32cc2/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java
index eaf94f8..4974739 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java
@@ -30,6 +30,7 @@ import org.apache.curator.framework.api.transaction.CuratorTransactionResult;
import org.apache.curator.framework.api.transaction.OperationType;
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.apache.zookeeper.KeeperException;
@@ -39,11 +40,44 @@ import org.testng.annotations.Test;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
public class TestTransactionsNew extends BaseClassForTests
{
@Test
+ public void testErrors() throws Exception
+ {
+ CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
+ try
+ {
+ client.start();
+ CuratorOp createOp1 = client.transactionOp().create().forPath("/bar");
+ CuratorOp createOp2 = client.transactionOp().create().forPath("/z/blue");
+ final BlockingQueue<CuratorEvent> callbackQueue = new LinkedBlockingQueue<>();
+ BackgroundCallback callback = new BackgroundCallback()
+ {
+ @Override
+ public void processResult(CuratorFramework client, CuratorEvent event) throws Exception
+ {
+ callbackQueue.add(event);
+ }
+ };
+ client.transaction().inBackground(callback).forOperations(createOp1, createOp2);
+ CuratorEvent event = callbackQueue.poll(new Timing().milliseconds(), TimeUnit.MILLISECONDS);
+ Assert.assertNotNull(event);
+ Assert.assertNotNull(event.getOpResults());
+ Assert.assertEquals(event.getOpResults().size(), 2);
+ Assert.assertEquals(event.getOpResults().get(0).getError(), KeeperException.Code.OK.intValue());
+ Assert.assertEquals(event.getOpResults().get(1).getError(), KeeperException.Code.NONODE.intValue());
+ }
+ finally
+ {
+ CloseableUtils.closeQuietly(client);
+ }
+ }
+
+ @Test
public void testCheckVersion() throws Exception
{
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));