Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added code to log time of workload and added calendar workload

  • Loading branch information...
commit 6cb6a7a6196124b7b43a10d81e3ebaf7f04faf9d 1 parent 7530dbd
@mschoch mschoch authored
View
2  default.properties → project.properties
@@ -4,7 +4,7 @@
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
+# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
View
9 src/com/couchbase/androidtester/workloads/CouchbaseWorkload.java
@@ -5,6 +5,9 @@
import android.content.Context;
import android.os.AsyncTask;
+import android.util.Log;
+
+import com.couchbase.androidtester.CouchbaseAndroidTesterActivity;
public abstract class CouchbaseWorkload {
@@ -81,7 +84,11 @@ public boolean isIndeterminate() {
@Override
protected String doInBackground(Void... params) {
- return performWork();
+ long start = System.currentTimeMillis();
+ String result = performWork();
+ long end = System.currentTimeMillis();
+ Log.v(CouchbaseAndroidTesterActivity.TAG, "" + getName() + " completed in " + (end - start) + "ms");
+ return result;
}
@Override
View
1  src/com/couchbase/androidtester/workloads/WorkloadHelper.java
@@ -20,6 +20,7 @@
result.add("com.couchbase.androidtester.workloads.impl.CancelPullReplication");
result.add("com.couchbase.androidtester.workloads.impl.PhotoShare");
result.add("com.couchbase.androidtester.workloads.impl.ContinuousReplication");
+ result.add("com.couchbase.androidtester.workloads.impl.Calendar");
return result;
}
View
103 src/com/couchbase/androidtester/workloads/impl/Calendar.java
@@ -0,0 +1,103 @@
+package com.couchbase.androidtester.workloads.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import com.couchbase.androidtester.workloads.CouchbaseWorkload;
+
+public class Calendar extends CouchbaseWorkload {
+
+ private static int numberOfEvents = 1000;
+ private static int delayBetweenPosts = 1000;
+
+ public Calendar() {
+ indeterminate = false;
+ total = numberOfEvents;
+ }
+
+ @Override
+ protected String performWork() {
+
+ int calendarEventsCreated = 0;
+
+ while(!task.isCancelled() && (calendarEventsCreated < numberOfEvents)) {
+
+ //create a calendar item
+ String id = UUID.randomUUID().toString();
+ Map<String,Object> document = documentTemplate(id);
+ couchDbConnector.create(document);
+ calendarEventsCreated++;
+
+ //wait
+ try {
+ Thread.sleep(delayBetweenPosts);
+ } catch (InterruptedException e) {
+ //ignore
+ }
+
+ //update the calendar item
+ document = cancelEvent(document);
+ couchDbConnector.update(document);
+
+ progress++;
+ task.publishWorkProgress("Processed Even " + calendarEventsCreated);
+
+
+ //wait some more
+ try {
+ Thread.sleep(delayBetweenPosts);
+ } catch (InterruptedException e) {
+ //ignore
+ }
+
+ }
+
+
+ String resultMessage = "" + calendarEventsCreated + " events created";
+
+ if(task.isCancelled()) {
+ resultMessage = "Cancelled Calendar Usage after " + resultMessage;
+ }
+ else {
+ resultMessage = "Finished Calendar Usage " + resultMessage;
+ }
+ progress = 0;
+ return resultMessage;
+
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Map<String, Object> cancelEvent(Map<String, Object> document) {
+ Map<String, Object> data = (Map<String,Object>)document.get("data");
+ data.put("status", "canceled");
+ document.put("data", data);
+ return document;
+ }
+
+ protected HashMap<String, Object> documentTemplate(String id) {
+ HashMap<String, Object> when = new HashMap<String, Object>();
+ when.put("start", "2010-04-17T15:00:00.000Z");
+ when.put("end", "2010-04-17T17:00:00.000Z");
+
+
+ HashMap<String, Object> data = new HashMap<String, Object>();
+ data.put("title", "CouchConf");
+ data.put("details", "Join us at a CouchConf near you!");
+ data.put("transparency", "opaque");
+ data.put("status", "confirmed");
+ data.put("location", "New York, NY");
+ data.put("when", when);
+
+ HashMap<String, Object> result = new HashMap<String, Object>();
+ result.put("_id", id);
+ result.put("data", data);
+ return result;
+ }
+
+ @Override
+ public String getName() {
+ return "Calendar Usage";
+ }
+
+}

0 comments on commit 6cb6a7a

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