Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 50d1b369fe6e2e1a9cfdb6b1e605cda69fd9505f 1 parent aae7719
Mike Wiederhold authored September 13, 2012 ingenthr committed September 17, 2012
24  src/main/java/net/spy/memcached/internal/OperationFuture.java
@@ -198,18 +198,26 @@ public void setCas(long inCas) {
198 198
 
199 199
  /**
200 200
    * Get the CAS for this operation.
201  
-   * If this is for an ASCII protocol configured client,
202  
-   * the exception Un
203 201
    *
204  
-   * @return the CAS for this operation or null
205  
-   * if unsuccessful.
  202
+   * @throws UnsupportedOperationException If this is for an ASCII protocol
  203
+   * configured client.
  204
+   * @return the CAS for this operation or null if unsuccessful.
206 205
    *
207 206
    */
208 207
   public Long getCas() {
209  
-    if (isDone() && getStatus().isSuccess()
210  
-            && (cas == null)) {
211  
-      throw new UnsupportedOperationException("ASCII Protocol"
212  
-              + " does not return a CAS value");
  208
+    if (cas == null) {
  209
+      try {
  210
+        get();
  211
+      } catch (InterruptedException e) {
  212
+        status = new OperationStatus(false, "Interrupted");
  213
+        Thread.currentThread().isInterrupted();
  214
+      } catch (ExecutionException e) {
  215
+        getLogger().warn("Error getting cas of operation", e);
  216
+      }
  217
+    }
  218
+    if (cas == null && status.isSuccess()) {
  219
+      throw new UnsupportedOperationException("This operation doesn't return"
  220
+          + "a cas value.");
213 221
     }
214 222
     return cas;
215 223
   }
1  src/test/java/net/spy/memcached/AsciiClientTest.java
@@ -80,7 +80,6 @@ public void testAsyncCASResponse() throws InterruptedException,
80 80
     CASValue<Object> getsRes = client.gets(key);
81 81
     OperationFuture<CASResponse> casRes = client.asyncCAS(key, getsRes.getCas(),
82 82
       key + "1");
83  
-    CASResponse innerCasRes = casRes.get();
84 83
     try {
85 84
       casRes.getCas();
86 85
       fail("Expected an UnsupportedOperationException");
2  src/test/java/net/spy/memcached/BinaryClientTest.java
@@ -93,7 +93,7 @@ public void testAsyncCASResponse() {
93 93
     OperationFuture<CASResponse> casRes = client.asyncCAS(key, getsRes.getCas(),
94 94
       key + "1");
95 95
     try {
96  
-      CASResponse innerCasRes = casRes.get();
  96
+      casRes.get();
97 97
       assertNotNull("OperationFuture is missing cas value.", casRes.getCas());
98 98
     } catch (InterruptedException ex) {
99 99
       fail("Interrupted while getting CASResponse");

0 notes on commit 50d1b36

Please sign in to comment.
Something went wrong with that request. Please try again.