[core] Re-add message counter and put debug output behind flag

This commit is contained in:
Torsten Grote
2018-11-02 11:57:36 -03:00
parent 93a6bf2f52
commit 5cc8c268ca

View File

@@ -61,6 +61,7 @@ import java.io.IOException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@@ -76,6 +77,7 @@ import static org.briarproject.bramble.api.sync.ValidationManager.State.PENDING;
import static org.briarproject.bramble.test.TestPluginConfigModule.MAX_LATENCY; import static org.briarproject.bramble.test.TestPluginConfigModule.MAX_LATENCY;
import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.util.LogUtils.logException; import static org.briarproject.bramble.util.LogUtils.logException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@@ -86,6 +88,7 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(BriarIntegrationTest.class.getName()); Logger.getLogger(BriarIntegrationTest.class.getName());
private static final boolean DEBUG = false;
@Nullable @Nullable
protected ContactId contactId1From2, contactId2From1; protected ContactId contactId1From2, contactId2From1;
@@ -135,6 +138,7 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
protected C c0, c1, c2; protected C c0, c1, c2;
private final Semaphore messageSemaphore = new Semaphore(0); private final Semaphore messageSemaphore = new Semaphore(0);
private final AtomicInteger messageCounter = new AtomicInteger(0);
private final File testDir = TestUtils.getTestDirectory(); private final File testDir = TestUtils.getTestDirectory();
private final String AUTHOR0 = "Author 0"; private final String AUTHOR0 = "Author 0";
private final String AUTHOR1 = "Author 1"; private final String AUTHOR1 = "Author 1";
@@ -237,12 +241,14 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
if (event.getState() == DELIVERED) { if (event.getState() == DELIVERED) {
LOG.info("Delivered new message " LOG.info("Delivered new message "
+ event.getMessageId()); + event.getMessageId());
messageCounter.addAndGet(1);
loadAndLogMessage(event.getMessageId()); loadAndLogMessage(event.getMessageId());
deliveryWaiter.resume(); deliveryWaiter.resume();
} else if (event.getState() == INVALID || } else if (event.getState() == INVALID ||
event.getState() == PENDING) { event.getState() == PENDING) {
LOG.info("Validated new " + event.getState().name() + LOG.info("Validated new " + event.getState().name() +
" message " + event.getMessageId()); " message " + event.getMessageId());
messageCounter.addAndGet(1);
loadAndLogMessage(event.getMessageId()); loadAndLogMessage(event.getMessageId());
validationWaiter.resume(); validationWaiter.resume();
} }
@@ -252,12 +258,14 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
private void loadAndLogMessage(MessageId id) { private void loadAndLogMessage(MessageId id) {
executor.execute(() -> { executor.execute(() -> {
try { if (DEBUG) {
BdfList body = clientHelper.getMessageAsList(id); try {
LOG.info("Contents of " + id + ":\n" BdfList body = clientHelper.getMessageAsList(id);
+ BdfStringUtils.toString(body)); LOG.info("Contents of " + id + ":\n"
} catch (DbException | FormatException e) { + BdfStringUtils.toString(body));
logException(LOG, WARNING, e); } catch (DbException | FormatException e) {
logException(LOG, WARNING, e);
}
} }
messageSemaphore.release(); messageSemaphore.release();
}); });
@@ -399,6 +407,7 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
} else { } else {
validationWaiter.await(TIMEOUT, num); validationWaiter.await(TIMEOUT, num);
} }
assertEquals("Messages delivered", num, messageCounter.getAndSet(0));
try { try {
messageSemaphore.tryAcquire(num, TIMEOUT, MILLISECONDS); messageSemaphore.tryAcquire(num, TIMEOUT, MILLISECONDS);
} catch (InterruptedException e) { } catch (InterruptedException e) {