Successful full-project build.
Still untested Bulletin Board Client.Bulletin-Board-Client-phase_1
parent
975ad340be
commit
13733e6610
|
@ -77,52 +77,52 @@ public class BulletinClientWorker implements Callable<BulletinClientJobResult> {
|
||||||
WebTarget webTarget;
|
WebTarget webTarget;
|
||||||
Response response;
|
Response response;
|
||||||
|
|
||||||
job.shuffleAddresses(); // This is done to randomize the order of access to servers primarily for READ operations
|
|
||||||
|
|
||||||
String requestPath;
|
String requestPath;
|
||||||
Message msg;
|
Message msg;
|
||||||
|
|
||||||
|
Message payload = job.getPayload();
|
||||||
|
|
||||||
BulletinBoardMessageList msgList;
|
BulletinBoardMessageList msgList;
|
||||||
|
|
||||||
int count = 0; // Used to count number of servers which contain the required message in a GET_REDUNDANCY request.
|
int count = 0; // Used to count number of servers which contain the required message in a GET_REDUNDANCY request.
|
||||||
|
|
||||||
|
job.shuffleAddresses(); // This is done to randomize the order of access to servers primarily for READ operations
|
||||||
|
|
||||||
// Prepare the request.
|
// Prepare the request.
|
||||||
switch(job.getJobType()) {
|
switch(job.getJobType()) {
|
||||||
|
|
||||||
case POST_MESSAGE:
|
case POST_MESSAGE:
|
||||||
// Make sure the payload is a BulletinBoardMessage
|
// Make sure the payload is a BulletinBoardMessage
|
||||||
if (!(job.getPayload() instanceof BulletinBoardMessage)) {
|
if (!(payload instanceof BulletinBoardMessage)) {
|
||||||
throw new IllegalArgumentException("Cannot post an object that is not an instance of BulletinBoardMessage");
|
throw new IllegalArgumentException("Cannot post an object that is not an instance of BulletinBoardMessage");
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = job.getPayload();
|
msg = payload;
|
||||||
requestPath = Constants.POST_MESSAGE_PATH;
|
requestPath = Constants.POST_MESSAGE_PATH;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case READ_MESSAGES:
|
case READ_MESSAGES:
|
||||||
// Make sure the payload is a MessageFilterList
|
// Make sure the payload is a MessageFilterList
|
||||||
if (!(job.getPayload() instanceof MessageFilterList)) {
|
if (!(payload instanceof MessageFilterList)) {
|
||||||
throw new IllegalArgumentException("Read failed: an instance of MessageFilterList is required as payload for a READ_MESSAGES operation");
|
throw new IllegalArgumentException("Read failed: an instance of MessageFilterList is required as payload for a READ_MESSAGES operation");
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = job.getPayload();
|
msg = payload;
|
||||||
requestPath = Constants.READ_MESSAGES_PATH;
|
requestPath = Constants.READ_MESSAGES_PATH;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GET_REDUNDANCY:
|
case GET_REDUNDANCY:
|
||||||
// Make sure the payload is a BulletinBoardMessage
|
// Make sure the payload is a MessageId
|
||||||
if (!(job.getPayload() instanceof BulletinBoardMessage)) {
|
if (!(payload instanceof MessageID)) {
|
||||||
throw new IllegalArgumentException("Cannot search for an object that is not an instance of BulletinBoardMessage");
|
throw new IllegalArgumentException("Cannot search for an object that is not an instance of BulletinBoardMessage");
|
||||||
}
|
}
|
||||||
|
|
||||||
requestPath = Constants.READ_MESSAGES_PATH;
|
requestPath = Constants.READ_MESSAGES_PATH;
|
||||||
|
|
||||||
// Create a MsgID from the
|
|
||||||
digest.update((BulletinBoardMessage) job.getPayload());
|
|
||||||
msg = MessageFilterList.newBuilder()
|
msg = MessageFilterList.newBuilder()
|
||||||
.addFilter(MessageFilter.newBuilder()
|
.addFilter(MessageFilter.newBuilder()
|
||||||
.setType(FilterType.MSG_ID)
|
.setType(FilterType.MSG_ID)
|
||||||
.setId(ByteString.copyFrom(digest.digest()))
|
.setId(payload.toByteString())
|
||||||
.build()
|
.build()
|
||||||
).build();
|
).build();
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
|
import com.google.protobuf.Message;
|
||||||
import meerkat.bulletinboard.BulletinBoardClient;
|
import meerkat.bulletinboard.BulletinBoardClient;
|
||||||
import meerkat.bulletinboard.SimpleBulletinBoardClient;
|
import meerkat.bulletinboard.BulletinBoardClient.ClientCallback;
|
||||||
import meerkat.comm.CommunicationException;
|
import meerkat.bulletinboard.ThreadedBulletinBoardClient;
|
||||||
import meerkat.protobuf.BulletinBoardAPI.*;
|
import meerkat.protobuf.BulletinBoardAPI.*;
|
||||||
import meerkat.protobuf.Crypto;
|
import meerkat.protobuf.Crypto;
|
||||||
|
|
||||||
|
import meerkat.protobuf.Voting.*;
|
||||||
import meerkat.util.BulletinBoardMessageComparator;
|
import meerkat.util.BulletinBoardMessageComparator;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static java.lang.Thread.sleep;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.hamcrest.number.OrderingComparison.*;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -20,8 +27,74 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class BulletinBoardClientIntegrationTest {
|
public class BulletinBoardClientIntegrationTest {
|
||||||
|
|
||||||
|
private class PostCallback implements ClientCallback<Object>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCallback(Object msg) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleFailure(Throwable t) {
|
||||||
|
System.err.println(t.getCause() + "\n" + t.getMessage());
|
||||||
|
assert false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RedundancyCallback implements ClientCallback<Float>{
|
||||||
|
|
||||||
|
private float minRedundancy;
|
||||||
|
|
||||||
|
public RedundancyCallback(float minRedundancy) {
|
||||||
|
this.minRedundancy = minRedundancy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCallback(Float redundancy) {
|
||||||
|
assertThat(redundancy, greaterThanOrEqualTo(minRedundancy));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleFailure(Throwable t) {
|
||||||
|
System.err.println(t.getCause() + "\n" + t.getMessage());
|
||||||
|
assert false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ReadCallback implements ClientCallback<List<BulletinBoardMessage>>{
|
||||||
|
|
||||||
|
private List<BulletinBoardMessage> expectedMsgList;
|
||||||
|
|
||||||
|
public ReadCallback(List<BulletinBoardMessage> expectedMsgList) {
|
||||||
|
this.expectedMsgList = expectedMsgList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleCallback(List<BulletinBoardMessage> messages) {
|
||||||
|
BulletinBoardMessageComparator msgComparator = new BulletinBoardMessageComparator();
|
||||||
|
|
||||||
|
assertThat(messages.size(), is(expectedMsgList.size()));
|
||||||
|
|
||||||
|
Iterator<BulletinBoardMessage> expectedMessageIterator = expectedMsgList.iterator();
|
||||||
|
Iterator<BulletinBoardMessage> receivedMessageIterator = messages.iterator();
|
||||||
|
|
||||||
|
while (expectedMessageIterator.hasNext()) {
|
||||||
|
assertThat(msgComparator.compare(expectedMessageIterator.next(), receivedMessageIterator.next()), is(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleFailure(Throwable t) {
|
||||||
|
System.err.println(t.getCause() + "\n" + t.getMessage());
|
||||||
|
assert false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private BulletinBoardClient bulletinBoardClient;
|
private BulletinBoardClient bulletinBoardClient;
|
||||||
|
|
||||||
|
private PostCallback postCallback;
|
||||||
|
private RedundancyCallback redundancyCallback;
|
||||||
|
private ReadCallback readCallback;
|
||||||
|
|
||||||
private static String PROP_GETTY_URL = "gretty.httpBaseURI";
|
private static String PROP_GETTY_URL = "gretty.httpBaseURI";
|
||||||
private static String DEFAULT_BASE_URL = "http://localhost:8081";
|
private static String DEFAULT_BASE_URL = "http://localhost:8081";
|
||||||
private static String BASE_URL = System.getProperty(PROP_GETTY_URL, DEFAULT_BASE_URL);
|
private static String BASE_URL = System.getProperty(PROP_GETTY_URL, DEFAULT_BASE_URL);
|
||||||
|
@ -29,12 +102,18 @@ public class BulletinBoardClientIntegrationTest {
|
||||||
@Before
|
@Before
|
||||||
public void init(){
|
public void init(){
|
||||||
|
|
||||||
bulletinBoardClient = new SimpleBulletinBoardClient();
|
bulletinBoardClient = new ThreadedBulletinBoardClient();
|
||||||
|
|
||||||
List<String> testDB = new LinkedList<String>();
|
List<String> testDB = new LinkedList<String>();
|
||||||
testDB.add(BASE_URL);
|
testDB.add(BASE_URL);
|
||||||
|
|
||||||
bulletinBoardClient.init(testDB);
|
bulletinBoardClient.init(BulletinBoardClientParams.newBuilder()
|
||||||
|
.addBulletinBoardAddress("http://localhost:8081")
|
||||||
|
.setMinRedundancy((float) 1.0)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
postCallback = new PostCallback();
|
||||||
|
redundancyCallback = new RedundancyCallback((float) 1.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,15 +152,15 @@ public class BulletinBoardClientIntegrationTest {
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
messageID = bulletinBoardClient.postMessage(msg,postCallback);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
messageID = bulletinBoardClient.postMessage(msg);
|
sleep(2000);
|
||||||
} catch (CommunicationException e) {
|
} catch (InterruptedException e) {
|
||||||
System.err.println("Error posting to BB Server: " + e.getMessage());
|
e.printStackTrace();
|
||||||
assert false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(bulletinBoardClient.getRedundancy(messageID), is((float) 1.00));
|
bulletinBoardClient.getRedundancy(messageID,redundancyCallback);
|
||||||
|
|
||||||
filterList = MessageFilterList.newBuilder()
|
filterList = MessageFilterList.newBuilder()
|
||||||
.addFilter(
|
.addFilter(
|
||||||
|
@ -90,19 +169,20 @@ public class BulletinBoardClientIntegrationTest {
|
||||||
.setTag("Signature")
|
.setTag("Signature")
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
// .addFilter(
|
.addFilter(
|
||||||
// MessageFilter.newBuilder()
|
MessageFilter.newBuilder()
|
||||||
// .setType(FilterType.TAG)
|
.setType(FilterType.TAG)
|
||||||
// .setTag("Trustee")
|
.setTag("Trustee")
|
||||||
// .build()
|
.build()
|
||||||
// )
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
msgList = bulletinBoardClient.readMessages(filterList);
|
msgList = new LinkedList<BulletinBoardMessage>();
|
||||||
|
msgList.add(msg);
|
||||||
|
|
||||||
assertThat(msgList.size(), is(1));
|
readCallback = new ReadCallback(msgList);
|
||||||
|
|
||||||
assertThat(msgComparator.compare(msgList.iterator().next(), msg), is(0));
|
bulletinBoardClient.readMessages(filterList, readCallback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue