Commit bc610edd authored by Lily Tsai's avatar Lily Tsai

added es batch test

parent cd3b19a8
Subproject commit 9d89587c13406c3fd4a52ac1f6b3067ccc3405c8 Subproject commit eb462f82708dc82b5c57333b5d5d608a9bc15bc5
...@@ -43,7 +43,7 @@ import java.util.List; ...@@ -43,7 +43,7 @@ import java.util.List;
* *
**/ **/
public class EncounterBasedCommunication { public class EncounterBasedCommunication {
public static final long CHANGE_EPOCH_TIME = 15*60000; public static final long CHANGE_EPOCH_TIME = 2*60000;
public static final long SCAN_BATCH_INTERVAL = (long) (2*60000); public static final long SCAN_BATCH_INTERVAL = (long) (2*60000);
public static final int REQUEST_ENABLE_BT = 1; public static final int REQUEST_ENABLE_BT = 1;
public static final int REQUEST_ACCESS_FINE_LOCATION = 2; public static final int REQUEST_ACCESS_FINE_LOCATION = 2;
......
...@@ -185,7 +185,7 @@ public class EncounterEntriesBridge extends AbstractEncountersBridge<MEncounterE ...@@ -185,7 +185,7 @@ public class EncounterEntriesBridge extends AbstractEncountersBridge<MEncounterE
} }
public List<MEncounterEntry> getConfirmedEntriesAfterTime(long timestamp) { public List<MEncounterEntry> getConfirmedEntriesAfterTime(long timestamp) {
final String[] selectionArgs = new String[] { String.valueOf(timestamp), String.valueOf(timestamp) }; final String[] selectionArgs = new String[] { String.valueOf(timestamp) };
String whereClause = "(" + PEncounterEntries.Columns.timestampEnd + " > ? OR " String whereClause = "(" + PEncounterEntries.Columns.timestampEnd + " > ? OR "
+ PEncounterEntries.Columns.timestampEnd + " = -1)" + PEncounterEntries.Columns.timestampEnd + " = -1)"
+ " AND " + PEncounterEntries.Columns.sharedSecret + " IS NOT NULL"; + " AND " + PEncounterEntries.Columns.sharedSecret + " IS NOT NULL";
......
...@@ -527,6 +527,7 @@ public class ESClient { ...@@ -527,6 +527,7 @@ public class ESClient {
// set the cursor to continue // set the cursor to continue
continuationCursor = r.getBody().getCursor(); continuationCursor = r.getBody().getCursor();
for (CommentView comment : r.getBody().getData()) { for (CommentView comment : r.getBody().getData()) {
System.out.println("Comments: Got message! " + comment.getText());
msgs.add(new ESMessage(comment.getText(), "", comment.getTopicHandle(), msgs.add(new ESMessage(comment.getText(), "", comment.getTopicHandle(),
esuser_client.isMe(comment.getUser().getUserHandle()), esuser_client.isMe(comment.getUser().getUserHandle()),
comment.getCommentHandle(), true, comment.getCreatedTime().getMillis())); comment.getCommentHandle(), true, comment.getCreatedTime().getMillis()));
......
...@@ -9,6 +9,7 @@ import org.mpisws.embeddedsocial.batchactions.DeleteTopicAction; ...@@ -9,6 +9,7 @@ import org.mpisws.embeddedsocial.batchactions.DeleteTopicAction;
import org.mpisws.embeddedsocial.batchactions.FindUniqueTopicAction; import org.mpisws.embeddedsocial.batchactions.FindUniqueTopicAction;
import org.mpisws.embeddedsocial.batchactions.GetBuildAction; import org.mpisws.embeddedsocial.batchactions.GetBuildAction;
import org.mpisws.embeddedsocial.batchactions.SubscribeTopicAction; import org.mpisws.embeddedsocial.batchactions.SubscribeTopicAction;
import org.mpisws.helpers.Coder;
import org.mpisws.helpers.Identifier; import org.mpisws.helpers.Identifier;
import java.io.IOException; import java.io.IOException;
...@@ -22,219 +23,30 @@ import okhttp3.Response; ...@@ -22,219 +23,30 @@ import okhttp3.Response;
import static java.lang.System.exit; import static java.lang.System.exit;
import static org.mpisws.embeddedsocial.ESClient.baseURL; import static org.mpisws.embeddedsocial.ESClient.baseURL;
import static org.mpisws.helpers.Utils.hexStringToByteArray;
/** /**
* Created by tslilyai on 3/24/18. * Created by tslilyai on 3/24/18.
*/ */
public class TestBatchClient { public class TestBatchClient {
static final String auth = "SocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzalNIRVUzNTA4ZVxuR29vZ2xlXG4xMTY4Njc1MTE0MDIxMzc1NzcxNTkiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQxODQ4MTQ0fQ.PTz69j2BuJB0bROiMK-b6zkpL9VOME0fhGjMPjkrkjQ"; static final String auth = "SocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzalNjZHFzN0paYVxuR29vZ2xlXG4xMTAyMDM3NjQyMDI5ODI4NDk3NTYiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQ3Mzg1NTA0fQ.DhURO4E5-BEFz_dWMdHZHQLq-E_fZf62_si-UlqF3Ko";
static final String topicHandle = "3gcpdys3KfY";
static final String ss = "0E31177095EE530101D89573C8261C14F51A3877D4676F74478F5CAF";
public static void main(String[] args) { public static void main(String[] args) {
int k = 6;
//getBuilds(k);
ESClient.getInstance().setESCredentials("user", auth); ESClient.getInstance().setESCredentials("user", auth);
ESClient.getInstance().setESAPIKey("2e5a1cc8-5eab-4dbd-8d6d-6a84eab23374"); ESClient.getInstance().setESAPIKey("2e5a1cc8-5eab-4dbd-8d6d-6a84eab23374");
List<Pair<Identifier, Identifier>> titles = new ArrayList<>();
for (int i = 0; i < k; i++) {
titles.add(new ImmutablePair<>(new Identifier(String.valueOf(System.currentTimeMillis()).getBytes()),
new Identifier(String.valueOf(System.currentTimeMillis()).getBytes())));
}
for (int i = 0; i < 10; i++) {
System.out.println("Running test " + i);
Thread t = new Thread(new FindCreateSubscribeTopicsRunnable(titles));
t.start();
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
exit(0);
}
private static class FindCreateSubscribeTopicsRunnable implements Runnable {
private final List<String> foundTopics;
private final List<Pair<Identifier, Identifier>> toCreateTopics;
private final List<Pair<Identifier, Identifier>> titleTextPairs;
protected List<String> topicHandles;
public boolean doneExecuting = false;
public FindCreateSubscribeTopicsRunnable(List<Pair<Identifier, Identifier>> titleTextPairs) {
this.foundTopics = new ArrayList<>(titleTextPairs.size());
this.toCreateTopics = new ArrayList<>(titleTextPairs.size());
for (int i = 0; i < titleTextPairs.size(); i++) {
foundTopics.add(null);
toCreateTopics.add(null);
}
this.titleTextPairs = titleTextPairs;
}
@Override
public void run() {
Response resp;
ConcurrentLinkedQueue<TopicView> toDeleteTopics = new ConcurrentLinkedQueue<>();
EmbeddedSocialBatchedClientImpl batchOps;
CountDownLatch latch;
int batchSize = (int) titleTextPairs.stream().filter(s -> s != null).count();
/* ------------------------------------BATCH 1: FIND --------------------------------------------------------*/
if (batchSize > 0) {
batchOps = new EmbeddedSocialBatchedClientImpl.Builder()
.batchSize(batchSize)
.baseUrl(baseURL)
.build();
latch = new CountDownLatch(batchSize);
// find the topics
for (int i = 0; i < titleTextPairs.size(); i++) {
if (titleTextPairs.get(i) != null) {
Pair<Identifier, Identifier> titleTextPair = titleTextPairs.get(i);
new FindUniqueTopicAction(batchOps, latch, i, auth, titleTextPair.getLeft(), titleTextPair.getRight(),
toDeleteTopics, toCreateTopics, foundTopics)
.addToBatch();
}
}
try {
resp = batchOps.issueBatch();
System.out.println("BATCH 1: Issued find-topics batch of size " + batchSize + " : " + resp.isSuccessful());
latch.await();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
/* ------------------------------------BATCH 2: CREATE (and DELETE) --------------------------------------------------------*/
batchSize = toDeleteTopics.size() + toCreateTopics.size();
if (batchSize > 0) {
batchOps = new EmbeddedSocialBatchedClientImpl.Builder()
.batchSize(batchSize)
.baseUrl(baseURL)
.build();
latch = new CountDownLatch(batchSize);
// (1) delete all repeated topics
for (TopicView tv : toDeleteTopics) {
new DeleteTopicAction(batchOps, latch, auth, tv.getTopicHandle()).addToBatch();
}
// (2) create all nonexisting topics new Thread( () -> {
for (int i = 0; i < titleTextPairs.size(); i++) { System.out.println("Starting!");
if (toCreateTopics.get(i) != null) { List<ESMessage> messages = ESClient.getInstance().getMessagesOnTopic(topicHandle);
new CreateTopicAction(batchOps, latch, i, auth, toCreateTopics.get(i).getLeft(), toCreateTopics.get(i).getRight(), foundTopics) for (ESMessage msg : messages) {
.addToBatch(); System.out.println(Coder.decrypt(msg.getMsgText(), hexStringToByteArray(ss)));
}
}
try {
resp = batchOps.issueBatch();
System.out.println("BATCH 2: Create/Delete " + batchSize + " : " + resp.isSuccessful());
latch.await();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
} }
}).start();
/* ------------------------------------BATCH 3: REFIND IF CREATED TO MAKE SURE NO RACE CONDITION----------------------------------*/
toDeleteTopics.clear();
batchSize = 0;
for (Pair<Identifier, Identifier> topic : toCreateTopics) {
if (topic != null) {
batchSize++;
}
}
if (batchSize > 0) {
batchOps = new EmbeddedSocialBatchedClientImpl.Builder()
.batchSize(batchSize)
.baseUrl(baseURL)
.build();
latch = new CountDownLatch(batchSize);
// make sure that only we created the topics
// we shouldn't want to create again so skip that step (if the topic doesn't exist then we failed and we'll try again later)
for (int i = 0; i < titleTextPairs.size(); i++) {
if (toCreateTopics.get(i) != null) {
Pair<Identifier, Identifier> titleTextPair = titleTextPairs.get(i);
new FindUniqueTopicAction(batchOps, latch, i, auth, titleTextPair.getLeft(), titleTextPair.getRight(),
toDeleteTopics, null, foundTopics)
.addToBatch();
}
}
try {
resp = batchOps.issueBatch();
System.out.println("BATCH 3: find-topics " + batchSize + " : " + resp.isSuccessful());
latch.await();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
/* ------------------------------------BATCH 4: DELETE EXTRA TOPICS --------------------------------------------------------*/
batchSize = toDeleteTopics.size();
if (batchSize > 0) {
batchOps = new EmbeddedSocialBatchedClientImpl.Builder()
.batchSize(batchSize)
.baseUrl(baseURL)
.build();
latch = new CountDownLatch(batchSize);
// delete all repeated topics
for (TopicView tv : toDeleteTopics) {
new DeleteTopicAction(batchOps, latch, auth, tv.getTopicHandle()).addToBatch();
}
try {
resp = batchOps.issueBatch();
System.out.println("BATCH 4: delete topics " + batchSize + " : " + resp.isSuccessful());
latch.await();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
/* ------------------------------------BATCH 5: SUBSCRIBE --------------------------------------------------------*/
batchSize = 0;
for (int i = 0; i < titleTextPairs.size(); i++) {
if (foundTopics.get(i) != null)
batchSize++;
}
if (batchSize > 0) {
batchOps = new EmbeddedSocialBatchedClientImpl.Builder()
.batchSize(batchSize)
.baseUrl(baseURL)
.build();
latch = new CountDownLatch(batchSize);
for (int i = 0; i < titleTextPairs.size(); i++) {
if (foundTopics.get(i) != null) {
new SubscribeTopicAction(batchOps, latch, i, auth, foundTopics)
.addToBatch();
}
}
try {
resp = batchOps.issueBatch();
System.out.println("BATCH 5: subscribe topics " + batchSize + " : " + resp.isSuccessful());
latch.await();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
/* BATCH 6: POST MESSAGES ON BAD TOPIC HANDLES */
List<ESMessage> msgsToPost = new LinkedList<>();
String badTopicHandle ="3%00j%00e%00E%00a%00_%002%00P%00o%00B%00B%00";
String badData = "xlMWN0tyZ0kz1KuOlw3NpcaelNgEztsWei0ZCYHEQS+DViAAWEfbX+qPYH+yuonZ";
for (int i = 0; i < 10; i++)
msgsToPost.add(new ESMessage(badData, badTopicHandle, null, true, null, true, -1));
ESClient.getInstance().sendMsgs(msgsToPost);
System.out.println("BATCH 6: send bad messages");
topicHandles = foundTopics;
synchronized(this) {
doneExecuting = true;
notifyAll();
}
}
} }
public static void getBuilds(int k) { public static void getBuilds(int k) {
org.mpisws.embeddedsocial.EmbeddedSocialBatchedClientImpl batchOps = new EmbeddedSocialBatchedClientImpl.Builder() org.mpisws.embeddedsocial.EmbeddedSocialBatchedClientImpl batchOps = new EmbeddedSocialBatchedClientImpl.Builder()
.batchSize(k) .batchSize(k)
......
...@@ -29,7 +29,7 @@ import java.util.UUID; ...@@ -29,7 +29,7 @@ import java.util.UUID;
*/ */
public class SimulationClientBT { public class SimulationClientBT {
Context context; Context context;
protected static final int NUM_SIMULATED_DEVICES = 30; protected static final int NUM_SIMULATED_DEVICES = 100;
protected static final int NUM_SIMULATED_EPOCHS = 10; protected static final int NUM_SIMULATED_EPOCHS = 10;
private static final String TAG = SimulationClientBT.class.getSimpleName(); private static final String TAG = SimulationClientBT.class.getSimpleName();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment