Permalink
Browse files

JCBC-80: Adding a unit test for persist and no stale

This changeset adds an integration test for the persistence
requirements in combination with stale=false.

Change-Id: I6ed681ab7dbc0ff131ef3a0d271cfad43bdc539e
Reviewed-on: http://review.couchbase.org/21444
Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
  • Loading branch information...
1 parent c1eabf5 commit df5b6a53bbd61ca8daf64d56919e79d81870355e @daschl daschl committed Oct 9, 2012
Showing with 49 additions and 0 deletions.
  1. +49 −0 src/test/java/com/couchbase/client/ViewTest.java
@@ -40,6 +40,7 @@
import com.couchbase.client.protocol.views.ViewResponse;
import com.couchbase.client.protocol.views.ViewRow;
import java.net.URI;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -49,6 +50,8 @@
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
+import net.spy.memcached.PersistTo;
+import net.spy.memcached.ReplicateTo;
import net.spy.memcached.TestConfig;
import net.spy.memcached.ops.OperationStatus;
import org.apache.http.HttpResponse;
@@ -64,6 +67,7 @@
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
/**
* A CouchbaseClientTest.
@@ -76,9 +80,11 @@
private static final Map<String, Object> ITEMS;
public static final String DESIGN_DOC_W_REDUCE = "doc_with_view";
public static final String DESIGN_DOC_WO_REDUCE = "doc_without_view";
+ public static final String DESIGN_DOC_OBSERVE = "doc_observe";
public static final String VIEW_NAME_W_REDUCE = "view_with_reduce";
public static final String VIEW_NAME_WO_REDUCE = "view_without_reduce";
public static final String VIEW_NAME_FOR_DATED = "view_emitting_dated";
+ public static final String VIEW_NAME_OBSERVE = "view_staletest";
static {
ITEMS = new HashMap<String, Object>();
@@ -123,6 +129,14 @@ public static void before() throws Exception {
+ "\"reduce\":\"_sum\" }}}";
c.asyncHttpPut(docUri, view);
+ // Create the view for oberserve integration test.
+ docUri = "/default/_design/" + TestingClient.MODE_PREFIX
+ + DESIGN_DOC_OBSERVE;
+ view = "{\"language\":\"javascript\",\"views\":{\""
+ + VIEW_NAME_OBSERVE + "\":{\"map\":\"function (doc, meta) {"
+ + " if(doc.type == \\\"observetest\\\") { emit(meta.id, null); } }\"}}}";
+ c.asyncHttpPut(docUri, view);
+
docUri = "/default/_design/" + TestingClient.MODE_PREFIX
+ DESIGN_DOC_WO_REDUCE;
String view2 = "{\"language\":\"javascript\",\"views\":{\""
@@ -173,6 +187,9 @@ public static void after() throws Exception {
c.asyncHttpDelete("/default/_design/" + TestingClient.MODE_PREFIX
+ DESIGN_DOC_WO_REDUCE).get();
+
+ c.asyncHttpDelete("/default/_design/" + TestingClient.MODE_PREFIX
+ + DESIGN_DOC_OBSERVE).get();
}
private static String generateDoc(String type, String small, String large) {
@@ -700,4 +717,36 @@ public void testInvalidDesignDocHandling() {
assertNull(views);
}
+ /**
+ * This test case acts as an integration test to verify that adding
+ * data with the given integrity constraints in combination with the
+ * stale=false query return the correct dataset.
+ */
+ @Test
+ public void testObserveWithStaleFalse()
+ throws InterruptedException, ExecutionException {
+ int docAmount = 500;
+ for (int i = 1; i <= docAmount; i++) {
+ String value = "{\"type\":\"observetest\",\"value\":"+i+"}";
+ client.set("observetest"+i, 0, value, PersistTo.MASTER, ReplicateTo.ONE);
+ }
+
+ Query query = new Query().setStale(Stale.FALSE);
+ View view = client.getView(DESIGN_DOC_OBSERVE, VIEW_NAME_OBSERVE);
+
+ HttpFuture<ViewResponse> future = client.asyncQuery(view, query);
+
+ ViewResponse response = future.get();
+ assert response != null : future.getStatus();
+
+ Iterator<ViewRow> iterator = response.iterator();
+ List<ViewRow> returnedRows = new ArrayList<ViewRow>();
+ while (iterator.hasNext()) {
+ ViewRow row = iterator.next();
+ returnedRows.add(row);
+ }
+
+ assertEquals(docAmount, returnedRows.size());
+ }
+
}

0 comments on commit df5b6a5

Please sign in to comment.