Skip to content

Commit

Permalink
JCBC-119: Allow NULL for persist/replicate.
Browse files Browse the repository at this point in the history
This changeset adds the possibility of using null for persistTo
and/or replicateTo. It defaults to ZERO for both enums, which
are the defaults and are equal to "dont observe at all". Tests
are also attached.

Change-Id: I0d69c971792ad8118f5d9035ccf3e0d8bca0215b
Reviewed-on: http://review.couchbase.org/21421
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
  • Loading branch information
daschl authored and Michael Wiederhold committed Oct 15, 2012
1 parent b54d2ff commit 00a2138
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/couchbase/client/CouchbaseClient.java
Expand Up @@ -1370,6 +1370,10 @@ public boolean shutdown(long timeout, TimeUnit unit) {
* normally utilized through higher-level methods but can also be used
* directly.
*
* If persist is null, it will default to PersistTo.ZERO and if replicate is
* null, it will default to ReplicateTo.ZERO. This is the default behavior
* and is the same as not observing at all.
*
* @param key the key to observe.
* @param cas the CAS value for the key.
* @param persist the persistence settings.
Expand All @@ -1379,6 +1383,12 @@ public boolean shutdown(long timeout, TimeUnit unit) {
public void observePoll(String key, long cas, PersistTo persist,
ReplicateTo replicate, boolean isDelete) {
boolean persistMaster = false;
if(persist == null) {
persist = PersistTo.ZERO;
}
if(replicate == null) {
replicate = ReplicateTo.ZERO;
}
int persistReplica = persist.getValue();
int replicateTo = replicate.getValue();
int obsPolls = 0;
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/com/couchbase/client/CouchbaseClientTest.java
Expand Up @@ -40,6 +40,8 @@
import net.spy.memcached.internal.OperationFuture;
import org.junit.Ignore;

import static org.junit.Assert.assertTrue;

/**
* A CouchbaseClientTest.
*/
Expand Down Expand Up @@ -219,6 +221,30 @@ public void testStatsKey() throws Exception {
assertFalse(future.getStatus().isSuccess());
}

/**
* Tests if passing NULL for ReplicateTo and/or
* PersistTo correctly works and does not throw
* an exception.
*/
public void testNullObserve() throws Exception {
boolean success;
try {
success = true;
OperationFuture<Boolean> nullcheckOp =
(((CouchbaseClient)client).add("nullcheck", 0, "value", null, null));
nullcheckOp.get();
nullcheckOp =
(((CouchbaseClient)client).set("nullcheck", 0, "value1", null, null));
nullcheckOp.get();
nullcheckOp =
(((CouchbaseClient)client).replace("nullcheck", 0, "value1", null, null));
nullcheckOp.get();
} catch(NullPointerException ex) {
success = false;
}
assertTrue(success);
}

public void testGetStatsSlabs() throws Exception {
// Empty
}
Expand Down

0 comments on commit 00a2138

Please sign in to comment.