diff --git a/bulletin-board-client/src/main/java/meerkat/bulletinboard/LocalBulletinBoardClient.java b/bulletin-board-client/src/main/java/meerkat/bulletinboard/LocalBulletinBoardClient.java index 109d5ed..8e2284c 100644 --- a/bulletin-board-client/src/main/java/meerkat/bulletinboard/LocalBulletinBoardClient.java +++ b/bulletin-board-client/src/main/java/meerkat/bulletinboard/LocalBulletinBoardClient.java @@ -500,7 +500,7 @@ public class LocalBulletinBoardClient implements DeletableSubscriptionBulletinBo MessagePoster poster = new MessagePoster(msg); poster.call(); - digest.update(msg); + digest.update(msg.getMsg()); return digest.digestAsMessageID(); } diff --git a/bulletin-board-client/src/main/java/meerkat/bulletinboard/SimpleBulletinBoardSynchronizer.java b/bulletin-board-client/src/main/java/meerkat/bulletinboard/SimpleBulletinBoardSynchronizer.java index f7e9baa..97b6d01 100644 --- a/bulletin-board-client/src/main/java/meerkat/bulletinboard/SimpleBulletinBoardSynchronizer.java +++ b/bulletin-board-client/src/main/java/meerkat/bulletinboard/SimpleBulletinBoardSynchronizer.java @@ -26,8 +26,11 @@ public class SimpleBulletinBoardSynchronizer implements BulletinBoardSynchronize private List> syncStatusCallbacks; private static final MessageFilterList EMPTY_FILTER = MessageFilterList.getDefaultInstance(); - private static final int SLEEP_INTERVAL = 10000; // 10 Seconds - private static final int WAIT_CAP = 300000; // 5 minutes wait before deciding that the sync has failed fatally + private static final int DEFAULT_SLEEP_INTERVAL = 10000; // 10 Seconds + private static final int DEFAULT_WAIT_CAP = 300000; // 5 minutes wait before deciding that the sync has failed fatally + + private final int SLEEP_INTERVAL; + private final int WAIT_CAP; private Semaphore semaphore; @@ -123,6 +126,7 @@ public class SimpleBulletinBoardSynchronizer implements BulletinBoardSynchronize if (result.size() == 0) { newStatus = SyncStatus.SYNCHRONIZED; + semaphore.release(); } else{ // Upload messages @@ -181,8 +185,14 @@ public class SimpleBulletinBoardSynchronizer implements BulletinBoardSynchronize } - public SimpleBulletinBoardSynchronizer() { + public SimpleBulletinBoardSynchronizer(int sleepInterval, int waitCap) { this.syncStatus = SyncStatus.STOPPED; + this.SLEEP_INTERVAL = sleepInterval; + this.WAIT_CAP = waitCap; + } + + public SimpleBulletinBoardSynchronizer() { + this(DEFAULT_SLEEP_INTERVAL, DEFAULT_WAIT_CAP); } private synchronized void updateSyncStatus(SyncStatus newStatus) { @@ -257,11 +267,7 @@ public class SimpleBulletinBoardSynchronizer implements BulletinBoardSynchronize do { - if (syncStatus == SyncStatus.PENDING || syncStatus == SyncStatus.SERVER_ERROR) { - - localClient.readMessages(EMPTY_FILTER, callback); - - } + localClient.readMessages(EMPTY_FILTER, callback); try { @@ -272,7 +278,6 @@ public class SimpleBulletinBoardSynchronizer implements BulletinBoardSynchronize // We expect an interruption when the upload will complete } - } while (syncStatus == SyncStatus.PENDING); // Database is synced. Wait for new data. diff --git a/bulletin-board-client/src/test/java/meerkat/bulletinboard/BulletinBoardSynchronizerTest.java b/bulletin-board-client/src/test/java/meerkat/bulletinboard/BulletinBoardSynchronizerTest.java index a3ace28..1813641 100644 --- a/bulletin-board-client/src/test/java/meerkat/bulletinboard/BulletinBoardSynchronizerTest.java +++ b/bulletin-board-client/src/test/java/meerkat/bulletinboard/BulletinBoardSynchronizerTest.java @@ -42,6 +42,9 @@ public class BulletinBoardSynchronizerTest { private static final int THREAD_NUM = 3; private static final int SUBSCRIPTION_INTERVAL = 1000; + private static final int SYNC_SLEEP_INTERVAL = 100; + private static final int SYNC_WAIT_CAP = 200; + private DeletableSubscriptionBulletinBoardClient localClient; private AsyncBulletinBoardClient remoteClient; @@ -70,6 +73,7 @@ public class BulletinBoardSynchronizerTest { signerIDs = new ByteString[1]; signers[0] = new GenericBatchDigitalSignature(new ECDSASignature()); + signerIDs[0] = signers[0].getSignerID(); InputStream keyStream = BulletinBoardSynchronizerTest.class.getResourceAsStream(KEYFILE_EXAMPLE); char[] password = KEYFILE_PASSWORD1.toCharArray(); @@ -122,7 +126,7 @@ public class BulletinBoardSynchronizerTest { THREAD_NUM, SUBSCRIPTION_INTERVAL); - synchronizer = new SimpleBulletinBoardSynchronizer(); + synchronizer = new SimpleBulletinBoardSynchronizer(SYNC_SLEEP_INTERVAL, SYNC_WAIT_CAP); synchronizer.init(localClient, remoteClient); semaphore = new Semaphore(0); @@ -200,15 +204,19 @@ public class BulletinBoardSynchronizerTest { int[] expectedCounts = {2,0}; synchronizer.subscribeToRemainingMessagesCount(new MessageCountCallback(expectedCounts)); - Thread t = new Thread(synchronizer); - t.run(); + Thread syncThread = new Thread(synchronizer); + syncThread.start(); - semaphore.acquire(); + semaphore.acquire(2); synchronizer.stop(); - t.join(); + syncThread.join(); - assertThat("Exception thrown by Synchronizer: " + thrown.get(0).getMessage(), thrown.size() == 0); + if (thrown.size() > 0) { + for (Throwable t : thrown) + System.err.println(t.getMessage()); + assertThat("Exception thrown by Synchronizer: " + thrown.get(0).getMessage(), false); + } List msgList = remoteClient.readMessages(MessageFilterList.newBuilder() .addFilter(MessageFilter.newBuilder() diff --git a/bulletin-board-client/src/test/java/meerkat/bulletinboard/GenericSubscriptionClientTester.java b/bulletin-board-client/src/test/java/meerkat/bulletinboard/GenericSubscriptionClientTester.java index 4a5fe62..52da797 100644 --- a/bulletin-board-client/src/test/java/meerkat/bulletinboard/GenericSubscriptionClientTester.java +++ b/bulletin-board-client/src/test/java/meerkat/bulletinboard/GenericSubscriptionClientTester.java @@ -16,8 +16,6 @@ import java.security.cert.CertificateException; import java.util.*; import java.util.concurrent.Semaphore; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; /** @@ -187,10 +185,8 @@ public class GenericSubscriptionClientTester { public void subscriptionTest() throws SignatureException, CommunicationException { - final int FIRST_POST_ID = 201; - final int SECOND_POST_ID = 202; final String COMMON_TAG = "SUBSCRIPTION_TEST"; - + List tags = new LinkedList<>(); tags.add(COMMON_TAG); diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/H2QueryProvider.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/H2QueryProvider.java index f68548e..55faa8f 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/H2QueryProvider.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/H2QueryProvider.java @@ -231,7 +231,7 @@ public class H2QueryProvider implements BulletinBoardSQLServer.SQLQueryProvider BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.Driver"); - dataSource.setUrl("jdbc:h2:~/" + dbName); + dataSource.setUrl("jdbc:h2:mem:" + dbName); return dataSource;