Added BB client intergration test (broken)

Fixed MsgID retrieval in BB server
Bulletin-Board-Client-phase_1
Arbel Deutsch Peled 2015-12-06 20:33:45 +02:00
parent a31d88bd12
commit 679d18f4a2
6 changed files with 170 additions and 11 deletions

View File

@ -1,5 +1,4 @@
subprojects { proj ->
proj.afterEvaluate {
// Used to generate initial maven-dir layout

View File

@ -102,7 +102,7 @@ public class SimpleBulletinBoardClient implements BulletinBoardClient {
.build())
.build();
int count = 0;
float count = 0;
for (String db : meerkatDBs) {
try {
@ -117,7 +117,7 @@ public class SimpleBulletinBoardClient implements BulletinBoardClient {
} catch (Exception e) {}
}
return count;
return count / ((float) meerkatDBs.size());
}
/**

View File

@ -0,0 +1,109 @@
import com.google.protobuf.ByteString;
import meerkat.bulletinboard.BulletinBoardClient;
import meerkat.bulletinboard.SimpleBulletinBoardClient;
import meerkat.comm.CommunicationException;
import meerkat.protobuf.BulletinBoardAPI.*;
import meerkat.protobuf.Crypto;
import meerkat.util.BulletinBoardMessageComparator;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
/**
* Created by Arbel Deutsch Peled on 05-Dec-15.
*/
public class BulletinBoardClientIntegrationTest {
private BulletinBoardClient bulletinBoardClient;
private static String PROP_GETTY_URL = "gretty.httpBaseURI";
private static String DEFAULT_BASE_URL = "http://localhost:8081";
private static String BASE_URL = System.getProperty(PROP_GETTY_URL, DEFAULT_BASE_URL);
@Before
public void init(){
bulletinBoardClient = new SimpleBulletinBoardClient();
List<String> testDB = new LinkedList<String>();
testDB.add(BASE_URL);
bulletinBoardClient.init(testDB);
}
@Test
public void postTest(){
byte[] b1 = {(byte) 1, (byte) 2, (byte) 3, (byte) 4};
byte[] b2 = {(byte) 11, (byte) 12, (byte) 13, (byte) 14};
byte[] b3 = {(byte) 21, (byte) 22, (byte) 23, (byte) 24};
byte[] b4 = {(byte) 4, (byte) 5, (byte) 100, (byte) -50, (byte) 0};
BulletinBoardMessage msg;
MessageFilterList filterList;
List<BulletinBoardMessage> msgList;
MessageID messageID;
Comparator<BulletinBoardMessage> msgComparator = new BulletinBoardMessageComparator();
msg = BulletinBoardMessage.newBuilder()
.setMsg(UnsignedBulletinBoardMessage.newBuilder()
.addTag("Signature")
.addTag("Trustee")
.setData(ByteString.copyFrom(b1))
.build())
.addSig(Crypto.Signature.newBuilder()
.setType(Crypto.SignatureType.DSA)
.setData(ByteString.copyFrom(b2))
.setSignerId(ByteString.copyFrom(b3))
.build())
.addSig(Crypto.Signature.newBuilder()
.setType(Crypto.SignatureType.ECDSA)
.setData(ByteString.copyFrom(b3))
.setSignerId(ByteString.copyFrom(b2))
.build())
.build();
try {
messageID = bulletinBoardClient.postMessage(msg);
} catch (CommunicationException e) {
System.err.println("Error posting to BB Server: " + e.getMessage());
assert false;
return;
}
assertThat(bulletinBoardClient.getRedundancy(messageID), is((float) 1.00));
filterList = MessageFilterList.newBuilder()
.addFilter(
MessageFilter.newBuilder()
.setType(FilterType.TAG)
.setTag("Signature")
.build()
)
// .addFilter(
// MessageFilter.newBuilder()
// .setType(FilterType.TAG)
// .setTag("Trustee")
// .build()
// )
.build();
msgList = bulletinBoardClient.readMessages(filterList);
assertThat(msgList.size(), is(1));
assertThat(msgComparator.compare(msgList.iterator().next(), msg), is(0));
}
}

View File

@ -2,9 +2,10 @@
plugins {
id "us.kirchmeier.capsule" version "1.0.1"
id 'com.google.protobuf' version '0.7.0'
id "org.akhikhl.gretty" version "1.2.4"
id 'org.akhikhl.gretty' version "1.2.4"
}
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
@ -45,7 +46,9 @@ dependencies {
// Jersey for RESTful API
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.22.+'
compile 'org.xerial:sqlite-jdbc:3.7.+'
// Servlets
compile 'javax.servlet:javax.servlet-api:3.0.+'
// Logging
compile 'org.slf4j:slf4j-api:1.7.7'
@ -68,13 +71,11 @@ test {
exclude '**/*IntegrationTest*'
}
task debugIntegrationTest(type: Test){
include '**/*IntegrationTest*'
debug = true
}
task integrationTest(type: Test) {
include '**/*IntegrationTest*'
// debug = true
outputs.upToDateWhen { false }
}
gretty {
@ -82,6 +83,7 @@ gretty {
contextPath = '/'
integrationTestTask = 'integrationTest'
loggingLevel = 'TRACE'
debugPort = 5006
}

View File

@ -167,7 +167,7 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer {
sqlSuffix += " LIMIT = ?";
break;
case FilterType.MSG_ID_VALUE:
sql += " MsgTableMsgId = ?";
sql += " MsgTable.MsgId = ?";
break;
case FilterType.SIGNER_ID_VALUE:
sql += " SignatureTable.SignerId = ?";

View File

@ -0,0 +1,49 @@
package meerkat.util;
import meerkat.protobuf.BulletinBoardAPI;
import meerkat.protobuf.BulletinBoardAPI.*;
import meerkat.protobuf.Crypto.*;
import java.util.Comparator;
import java.util.List;
/**
* Created by Arbel Deutsch Peled on 05-Dec-15.
* This class implements a comparison between BulletinBoardMessage instances that disregards:
* 1. The entry number (since this can be different between database instances)
* 2. The order of the signatures
*/
public class BulletinBoardMessageComparator implements Comparator<BulletinBoardMessage> {
/**
* Compare the messages
* @param msg1
* @param msg2
* @return 0 if the messages are equivalent (see above) and -1 otherwise.
*/
@Override
public int compare(BulletinBoardMessage msg1, BulletinBoardMessage msg2) {
List<Signature> msg1Sigs = msg1.getSigList();
List<Signature> msg2Sigs = msg2.getSigList();
// Compare unsigned message
if (!msg1.getMsg().equals(msg2.getMsg())){
return -1;
}
// Compare signatures
if (msg1Sigs.size() != msg2Sigs.size()){
return -1;
}
for (Signature sig : msg1Sigs){
if (!msg2Sigs.contains(sig)) {
return -1;
}
}
return 0;
}
}