CAS with non-existent key giving OK vs NOT_FOUND

If I submit a cas with a non-existent key I would expect to receive CASResponse.NOT_FOUND but am receiving CASResponse.OK instead. Is this a bug? The use case is a test we created for a cas operation on either a non-existent key or a key that has expired from the cache.

Couchbase Java client 1.2.0

cas operation used: public CASResponse cas(String key, long casId, int exp, Object value

test case:

String key = UUID.randomUUID().toString();
String value = “a value”;
int documentTtl = 3600; // seconds
long cas = 0;

CASResponse response= client.cas(key, cas, documentTtl, value);

assert(response == CASResponse.NOT_FOUND);

Debugging shows the response to be OK instead of NOT_FOUND

Update to make this a little more correct. Our test case for a key that did exist in CB and expired does properly return a CASResponse.NOT_FOUND but the case of a non-existent key is still returning OK where it should return NOT_FOUND.

Further update - I believe the OK vs NOT_FOUND is indeed a bug but it only happens when submitting a non-existent key and a cas value == 0. This is if anything a corner case that should not really ever happen as any cas retrieved from CB would be > 0.

cas value of 0 == cas wildcard and match any cas value.

This is arguably not the correct behavior. I don’t believe it is documented either. The documented behavior is to submit a long value for cas and if current cas != cas submitted then CASResponse.EXISTS should be returned instead of CASResponse.OK.

Then I would suggest you file a bug for the docs for the Java SDK to make it clear.

I just spent 30 minutes tracking down this answer… Plus one for updating Java SDK with information about CAS value == 0 being a wildcard, and the other doc to indicate that CAS value == 0 means you will never get NOT_FOUND.