From cc2888483de408b97b79e0b67bf5ec3ffe07306e Mon Sep 17 00:00:00 2001 From: Arbel Deutsch Peled Date: Sun, 26 Jun 2016 14:32:30 +0300 Subject: [PATCH] Threaded Client integration tests passing --- .../ThreadedBulletinBoardClient.java | 11 +++- .../MultiServerBeginBatchWorker.java | 2 +- .../MultiServerCloseBatchWorker.java | 60 +++++++++++++++++-- .../MultiServerPostBatchDataWorker.java | 2 +- .../SingleServerBeginBatchWorker.java | 7 ++- .../GenericBulletinBoardClientTester.java | 28 +++++++-- .../LocalBulletinBoardClientTest.java | 4 +- ...dedBulletinBoardClientIntegrationTest.java | 4 +- 8 files changed, 98 insertions(+), 20 deletions(-) diff --git a/bulletin-board-client/src/main/java/meerkat/bulletinboard/ThreadedBulletinBoardClient.java b/bulletin-board-client/src/main/java/meerkat/bulletinboard/ThreadedBulletinBoardClient.java index 5c1cab4..b549a2e 100644 --- a/bulletin-board-client/src/main/java/meerkat/bulletinboard/ThreadedBulletinBoardClient.java +++ b/bulletin-board-client/src/main/java/meerkat/bulletinboard/ThreadedBulletinBoardClient.java @@ -160,11 +160,18 @@ public class ThreadedBulletinBoardClient extends SimpleBulletinBoardClient imple } @Override - public void closeBatch(BatchIdentifier payload, Timestamp timestamp, Iterable signatures, FutureCallback callback) { + public void closeBatch(BatchIdentifier payload, Timestamp timestamp, Iterable signatures, FutureCallback callback) + throws IllegalArgumentException{ + + if (!(payload instanceof MultiServerBatchIdentifier)) { + throw new IllegalArgumentException("Error: batch identifier supplied was not created by this class."); + } + + MultiServerBatchIdentifier identifier = (MultiServerBatchIdentifier) payload; // Create job MultiServerCloseBatchWorker worker = - new MultiServerCloseBatchWorker(clients, minAbsoluteRedundancy, payload, timestamp, signatures, POST_MESSAGE_RETRY_NUM, callback); + new MultiServerCloseBatchWorker(clients, minAbsoluteRedundancy, identifier, timestamp, signatures, POST_MESSAGE_RETRY_NUM, callback); // Submit job executorService.submit(worker); diff --git a/bulletin-board-client/src/main/java/meerkat/bulletinboard/workers/multiserver/MultiServerBeginBatchWorker.java b/bulletin-board-client/src/main/java/meerkat/bulletinboard/workers/multiserver/MultiServerBeginBatchWorker.java index 793fc6e..7d64946 100644 --- a/bulletin-board-client/src/main/java/meerkat/bulletinboard/workers/multiserver/MultiServerBeginBatchWorker.java +++ b/bulletin-board-client/src/main/java/meerkat/bulletinboard/workers/multiserver/MultiServerBeginBatchWorker.java @@ -46,7 +46,7 @@ public class MultiServerBeginBatchWorker extends MultiServerWorker { +public class MultiServerCloseBatchWorker extends MultiServerWorker { private final Timestamp timestamp; - private final Iterable signatures; + private final Iterable signatures; - public MultiServerCloseBatchWorker(List clients, int minServers, - BatchIdentifier payload, Timestamp timestamp, Iterable signatures, + public MultiServerCloseBatchWorker(List clients, + int minServers, MultiServerBatchIdentifier payload, Timestamp timestamp, Iterable signatures, int maxRetry, FutureCallback futureCallback) { super(clients, minServers, payload, maxRetry, futureCallback); @@ -28,8 +34,50 @@ public class MultiServerCloseBatchWorker extends MultiServerGenericPostWorker identifierIterator = payload.getIdentifiers().iterator(); + + // Iterate through client + + for (SingleServerBulletinBoardClient client : clients) { + + if (identifierIterator.hasNext()) { + + // Fetch the batch identifier supplied by the specific client (may be null if batch open failed on client + + BatchIdentifier identifier = identifierIterator.next(); + + if (identifier != null) { + + // Post the data with the matching identifier to the client + client.closeBatch(identifier, timestamp, signatures, this); + + } else { + + // Count servers with no batch identifier as failed + maxFailedServers.decrementAndGet(); + + } + + } + + } + + } + + @Override + public void onSuccess(Boolean result) { + if (minServers.decrementAndGet() <= 0){ + succeed(result); + } + } + + @Override + public void onFailure(Throwable t) { + if (maxFailedServers.decrementAndGet() <= 0){ + fail(t); + } } diff --git a/bulletin-board-client/src/main/java/meerkat/bulletinboard/workers/multiserver/MultiServerPostBatchDataWorker.java b/bulletin-board-client/src/main/java/meerkat/bulletinboard/workers/multiserver/MultiServerPostBatchDataWorker.java index 052b625..8ef5931 100644 --- a/bulletin-board-client/src/main/java/meerkat/bulletinboard/workers/multiserver/MultiServerPostBatchDataWorker.java +++ b/bulletin-board-client/src/main/java/meerkat/bulletinboard/workers/multiserver/MultiServerPostBatchDataWorker.java @@ -40,7 +40,7 @@ public class MultiServerPostBatchDataWorker extends MultiServerWorker() { + @Override + public void onSuccess(Boolean result) { + jobSemaphore.release(); + } + + @Override + public void onFailure(Throwable t) { + genericHandleFailure(t); + } + }); } @@ -429,7 +444,12 @@ public class GenericBulletinBoardClientTester { final int CHUNK_SIZE = 99; final int TAG_NUM = 8; - final BulletinBoardMessage msg = generator.generateRandomMessage(signers, BATCH_LENGTH, TAG_NUM); + final Timestamp timestamp = Timestamp.newBuilder() + .setSeconds(7776151) + .setNanos(252616) + .build(); + + final BulletinBoardMessage msg = generator.generateRandomMessage(signers, timestamp, BATCH_LENGTH, TAG_NUM); // Post batch diff --git a/bulletin-board-client/src/test/java/meerkat/bulletinboard/LocalBulletinBoardClientTest.java b/bulletin-board-client/src/test/java/meerkat/bulletinboard/LocalBulletinBoardClientTest.java index 1804c77..56392d7 100644 --- a/bulletin-board-client/src/test/java/meerkat/bulletinboard/LocalBulletinBoardClientTest.java +++ b/bulletin-board-client/src/test/java/meerkat/bulletinboard/LocalBulletinBoardClientTest.java @@ -81,9 +81,9 @@ public class LocalBulletinBoardClientTest { } @Test - public void postTest() { + public void testPost() { - clientTest.postTest(); + clientTest.testPost(); } diff --git a/bulletin-board-client/src/test/java/meerkat/bulletinboard/ThreadedBulletinBoardClientIntegrationTest.java b/bulletin-board-client/src/test/java/meerkat/bulletinboard/ThreadedBulletinBoardClientIntegrationTest.java index 1a95e95..dd47354 100644 --- a/bulletin-board-client/src/test/java/meerkat/bulletinboard/ThreadedBulletinBoardClientIntegrationTest.java +++ b/bulletin-board-client/src/test/java/meerkat/bulletinboard/ThreadedBulletinBoardClientIntegrationTest.java @@ -66,9 +66,9 @@ public class ThreadedBulletinBoardClientIntegrationTest { } @Test - public void postTest() { + public void testPost() { - clientTest.postTest(); + clientTest.testPost(); }