Permalink
Browse files

JCBC-110: Fix getCas function in operation future

We need to wait for the operation to complete if we call getCas
and the operation is not finished otherwise calling this function
will incorrectly throw an exception.

Change-Id: Iefd90f04f8ebdeaf569b69be6dea7deac03a2c80
Reviewed-on: http://review.couchbase.org/20848
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: Matt Ingenthron <matt@couchbase.com>
  • Loading branch information...
mikewied authored and ingenthr committed Sep 14, 2012
1 parent aae7719 commit 50d1b369fe6e2e1a9cfdb6b1e605cda69fd9505f
@@ -198,18 +198,26 @@ public void setCas(long inCas) {
/**
* Get the CAS for this operation.
- * If this is for an ASCII protocol configured client,
- * the exception Un
*
- * @return the CAS for this operation or null
- * if unsuccessful.
+ * @throws UnsupportedOperationException If this is for an ASCII protocol
+ * configured client.
+ * @return the CAS for this operation or null if unsuccessful.
*
*/
public Long getCas() {
- if (isDone() && getStatus().isSuccess()
- && (cas == null)) {
- throw new UnsupportedOperationException("ASCII Protocol"
- + " does not return a CAS value");
+ if (cas == null) {
+ try {
+ get();
+ } catch (InterruptedException e) {
+ status = new OperationStatus(false, "Interrupted");
+ Thread.currentThread().isInterrupted();
+ } catch (ExecutionException e) {
+ getLogger().warn("Error getting cas of operation", e);
+ }
+ }
+ if (cas == null && status.isSuccess()) {
+ throw new UnsupportedOperationException("This operation doesn't return"
+ + "a cas value.");
}
return cas;
}
@@ -80,7 +80,6 @@ public void testAsyncCASResponse() throws InterruptedException,
CASValue<Object> getsRes = client.gets(key);
OperationFuture<CASResponse> casRes = client.asyncCAS(key, getsRes.getCas(),
key + "1");
- CASResponse innerCasRes = casRes.get();
try {
casRes.getCas();
fail("Expected an UnsupportedOperationException");
@@ -93,7 +93,7 @@ public void testAsyncCASResponse() {
OperationFuture<CASResponse> casRes = client.asyncCAS(key, getsRes.getCas(),
key + "1");
try {
- CASResponse innerCasRes = casRes.get();
+ casRes.get();
assertNotNull("OperationFuture is missing cas value.", casRes.getCas());
} catch (InterruptedException ex) {
fail("Interrupted while getting CASResponse");

0 comments on commit 50d1b36

Please sign in to comment.