Permalink
Browse files

added new test for cancelling pull replication

  • Loading branch information...
mschoch committed Oct 11, 2011
1 parent 7b763a8 commit 5a93d11269dec8e5a95c3aba7addbac86537f6ad
Binary file not shown.
Binary file not shown.
@@ -17,6 +17,7 @@
ArrayList<String> result = new ArrayList<String>();
result.add("com.couchbase.androidtester.workloads.impl.CreateDocuments");
result.add("com.couchbase.androidtester.workloads.impl.CRUDDocuments");
+ result.add("com.couchbase.androidtester.workloads.impl.CancelPullReplication");
return result;
}
@@ -4,6 +4,7 @@
import java.util.Map;
import org.ektorp.CouchDbConnector;
+import org.ektorp.UpdateConflictException;
import android.util.Log;
@@ -43,7 +44,11 @@ protected String performWork() {
//update
documentRead.put("updated", "true");
- couchDbConnector.update(documentRead);
+ try {
+ couchDbConnector.update(documentRead);
+ } catch (UpdateConflictException e) {
+ Log.v(CouchbaseAndroidTesterActivity.TAG, "Update Conflict", e);
+ }
progress++;
//delete
@@ -0,0 +1,88 @@
+package com.couchbase.androidtester.workloads.impl;
+
+import org.ektorp.DbAccessException;
+import org.ektorp.ReplicationCommand;
+import org.ektorp.ReplicationStatus;
+
+import android.util.Log;
+
+import com.couchbase.androidtester.CouchbaseAndroidTesterActivity;
+import com.couchbase.androidtester.workloads.CouchbaseWorkload;
+
+public class CancelPullReplication extends CouchbaseWorkload {
+
+ public static final String DATABASE_NAME = "workload";
+
+ @Override
+ protected String performWork() {
+
+ couchDbInstance.createConnector(DATABASE_NAME, true);
+
+
+ Thread replicate = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+
+ ReplicationCommand pullReplicationCommand = new ReplicationCommand.Builder()
+ .source("http://couchbase.iriscouch.com/grocery-sync")
+ .target(DATABASE_NAME)
+ .build();
+
+ Log.v(CouchbaseAndroidTesterActivity.TAG, "Starting Replication");
+ ReplicationStatus status;
+ try {
+ status = couchDbInstance.replicate(pullReplicationCommand);
+ Log.v(CouchbaseAndroidTesterActivity.TAG, "Finished Replication: " + status.isOk());
+ } catch (DbAccessException e) {
+ Log.v(CouchbaseAndroidTesterActivity.TAG, "Replication Error: ", e);
+ }
+
+ }
+ });
+
+ Thread replicateCancel = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+
+ ReplicationCommand pullReplicationCancelCommand = new ReplicationCommand.Builder()
+ .source("http://couchbase.iriscouch.com/grocery-sync")
+ .target(DATABASE_NAME)
+ .cancel(true)
+ .build();
+
+ Log.v(CouchbaseAndroidTesterActivity.TAG, "Starting Replication Cancelation");
+ ReplicationStatus status;
+ try {
+ status = couchDbInstance.replicate(pullReplicationCancelCommand);
+ Log.v(CouchbaseAndroidTesterActivity.TAG, "Finished Replication Cancelation: " + status.isOk());
+ } catch (DbAccessException e) {
+ Log.v(CouchbaseAndroidTesterActivity.TAG, "Replication Cancellation Error: ", e);
+ }
+
+ }
+ });
+
+
+ try {
+ replicate.start();
+ //wait 2 seconds
+ Thread.sleep(2 * 1000);
+ replicateCancel.start();
+
+ //wait for these threads to finish to end workload
+ replicateCancel.join();
+ replicate.join();
+ } catch (InterruptedException e) {
+ Log.v(CouchbaseAndroidTesterActivity.TAG, "Thread was interuppted");
+ }
+
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return "Cancel Pull Replication";
+ }
+}

0 comments on commit 5a93d11

Please sign in to comment.