Merge branch '2289-client-for-contacts-mailbox' into 'master'

Mailbox client for a contact's mailbox

Closes #2289

See merge request briar/briar!1674
This commit is contained in:
Torsten Grote
2022-06-22 17:09:37 +00:00
21 changed files with 449 additions and 93 deletions

View File

@@ -0,0 +1,122 @@
package org.briarproject.bramble.mailbox;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static java.util.logging.Logger.getLogger;
@ThreadSafe
@NotNullByDefault
class ContactMailboxClient implements MailboxClient {
private static final Logger LOG =
getLogger(ContactMailboxClient.class.getName());
private final MailboxWorkerFactory workerFactory;
private final ConnectivityChecker connectivityChecker;
private final TorReachabilityMonitor reachabilityMonitor;
private final Object lock = new Object();
@GuardedBy("lock")
@Nullable
private MailboxWorker uploadWorker = null, downloadWorker = null;
@Inject
ContactMailboxClient(MailboxWorkerFactory workerFactory,
ConnectivityChecker connectivityChecker,
TorReachabilityMonitor reachabilityMonitor) {
this.workerFactory = workerFactory;
this.connectivityChecker = connectivityChecker;
this.reachabilityMonitor = reachabilityMonitor;
}
@Override
public void start() {
LOG.info("Started");
// Nothing to do until contact is assigned
}
@Override
public void destroy() {
LOG.info("Destroyed");
MailboxWorker uploadWorker, downloadWorker;
synchronized (lock) {
uploadWorker = this.uploadWorker;
this.uploadWorker = null;
downloadWorker = this.downloadWorker;
this.downloadWorker = null;
}
if (uploadWorker != null) uploadWorker.destroy();
if (downloadWorker != null) downloadWorker.destroy();
}
@Override
public void assignContactForUpload(ContactId contactId,
MailboxProperties properties, MailboxFolderId folderId) {
LOG.info("Contact assigned for upload");
if (properties.isOwner()) throw new IllegalArgumentException();
// For a contact's mailbox we should always be uploading to the outbox
// assigned to us by the contact
if (!folderId.equals(properties.getOutboxId())) {
throw new IllegalArgumentException();
}
MailboxWorker uploadWorker = workerFactory.createUploadWorker(
connectivityChecker, properties, folderId, contactId);
synchronized (lock) {
if (this.uploadWorker != null) throw new IllegalStateException();
this.uploadWorker = uploadWorker;
}
uploadWorker.start();
}
@Override
public void deassignContactForUpload(ContactId contactId) {
LOG.info("Contact deassigned for upload");
MailboxWorker uploadWorker;
synchronized (lock) {
uploadWorker = this.uploadWorker;
this.uploadWorker = null;
}
if (uploadWorker != null) uploadWorker.destroy();
}
@Override
public void assignContactForDownload(ContactId contactId,
MailboxProperties properties, MailboxFolderId folderId) {
LOG.info("Contact assigned for download");
if (properties.isOwner()) throw new IllegalArgumentException();
// For a contact's mailbox we should always be downloading from the
// inbox assigned to us by the contact
if (!folderId.equals(properties.getInboxId())) {
throw new IllegalArgumentException();
}
MailboxWorker downloadWorker =
workerFactory.createDownloadWorkerForContactMailbox(
connectivityChecker, reachabilityMonitor, properties);
synchronized (lock) {
if (this.downloadWorker != null) throw new IllegalStateException();
this.downloadWorker = downloadWorker;
}
downloadWorker.start();
}
@Override
public void deassignContactForDownload(ContactId contactId) {
LOG.info("Contact deassigned for download");
MailboxWorker downloadWorker;
synchronized (lock) {
downloadWorker = this.downloadWorker;
this.downloadWorker = null;
}
if (downloadWorker != null) downloadWorker.destroy();
}
}

View File

@@ -90,7 +90,7 @@ class ContactMailboxDownloadWorker implements MailboxWorker,
LOG.info("Started"); LOG.info("Started");
synchronized (lock) { synchronized (lock) {
// Don't allow the worker to be reused // Don't allow the worker to be reused
if (state != State.CREATED) throw new IllegalStateException(); if (state != State.CREATED) return;
state = State.CONNECTIVITY_CHECK; state = State.CONNECTIVITY_CHECK;
} }
// Avoid leaking observer in case destroy() is called concurrently // Avoid leaking observer in case destroy() is called concurrently

View File

@@ -0,0 +1,46 @@
package org.briarproject.bramble.mailbox;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe
@NotNullByDefault
interface MailboxClient {
/**
* Asynchronously starts the client.
*/
void start();
/**
* Destroys the client and its workers, cancelling any pending tasks or
* retries.
*/
void destroy();
/**
* Assigns a contact to the client for upload.
*/
void assignContactForUpload(ContactId c, MailboxProperties properties,
MailboxFolderId folderId);
/**
* Deassigns a contact from the client for upload.
*/
void deassignContactForUpload(ContactId c);
/**
* Assigns a contact to the client for download.
*/
void assignContactForDownload(ContactId c, MailboxProperties properties,
MailboxFolderId folderId);
/**
* Deassigns a contact from the client for download.
*/
void deassignContactForDownload(ContactId c);
}

View File

@@ -52,6 +52,7 @@ public class MailboxModule {
} }
@Provides @Provides
@Singleton
MailboxSettingsManager provideMailboxSettingsManager( MailboxSettingsManager provideMailboxSettingsManager(
MailboxSettingsManagerImpl mailboxSettingsManager) { MailboxSettingsManagerImpl mailboxSettingsManager) {
return mailboxSettingsManager; return mailboxSettingsManager;
@@ -114,4 +115,10 @@ public class MailboxModule {
} }
return mailboxFileManager; return mailboxFileManager;
} }
@Provides
MailboxWorkerFactory provideMailboxWorkerFactory(
MailboxWorkerFactoryImpl mailboxWorkerFactory) {
return mailboxWorkerFactory;
}
} }

View File

@@ -20,13 +20,13 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject; import javax.inject.Inject;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty; import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
@Immutable @ThreadSafe
@NotNullByDefault @NotNullByDefault
class MailboxSettingsManagerImpl implements MailboxSettingsManager { class MailboxSettingsManagerImpl implements MailboxSettingsManager {

View File

@@ -147,7 +147,7 @@ class MailboxUploadWorker implements MailboxWorker, ConnectivityObserver,
LOG.info("Started"); LOG.info("Started");
synchronized (lock) { synchronized (lock) {
// Don't allow the worker to be reused // Don't allow the worker to be reused
if (state != State.CREATED) throw new IllegalStateException(); if (state != State.CREATED) return;
state = State.CHECKING_FOR_DATA; state = State.CHECKING_FOR_DATA;
} }
ioExecutor.execute(this::checkForDataToSend); ioExecutor.execute(this::checkForDataToSend);

View File

@@ -0,0 +1,27 @@
package org.briarproject.bramble.mailbox;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe
@NotNullByDefault
interface MailboxWorkerFactory {
MailboxWorker createUploadWorker(ConnectivityChecker connectivityChecker,
MailboxProperties properties, MailboxFolderId folderId,
ContactId contactId);
MailboxWorker createDownloadWorkerForContactMailbox(
ConnectivityChecker connectivityChecker,
TorReachabilityMonitor reachabilityMonitor,
MailboxProperties properties);
MailboxWorker createDownloadWorkerForOwnMailbox(
ConnectivityChecker connectivityChecker,
TorReachabilityMonitor reachabilityMonitor,
MailboxProperties properties);
}

View File

@@ -0,0 +1,81 @@
package org.briarproject.bramble.mailbox;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.event.EventBus;
import org.briarproject.bramble.api.lifecycle.IoExecutor;
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.api.system.TaskScheduler;
import java.util.concurrent.Executor;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
@Immutable
@NotNullByDefault
class MailboxWorkerFactoryImpl implements MailboxWorkerFactory {
private final Executor ioExecutor;
private final DatabaseComponent db;
private final Clock clock;
private final TaskScheduler taskScheduler;
private final EventBus eventBus;
private final MailboxApiCaller mailboxApiCaller;
private final MailboxApi mailboxApi;
private final MailboxFileManager mailboxFileManager;
@Inject
MailboxWorkerFactoryImpl(@IoExecutor Executor ioExecutor,
DatabaseComponent db,
Clock clock,
TaskScheduler taskScheduler,
EventBus eventBus,
MailboxApiCaller mailboxApiCaller,
MailboxApi mailboxApi,
MailboxFileManager mailboxFileManager) {
this.ioExecutor = ioExecutor;
this.db = db;
this.clock = clock;
this.taskScheduler = taskScheduler;
this.eventBus = eventBus;
this.mailboxApiCaller = mailboxApiCaller;
this.mailboxApi = mailboxApi;
this.mailboxFileManager = mailboxFileManager;
}
@Override
public MailboxWorker createUploadWorker(
ConnectivityChecker connectivityChecker,
MailboxProperties properties, MailboxFolderId folderId,
ContactId contactId) {
MailboxUploadWorker worker = new MailboxUploadWorker(ioExecutor, db,
clock, taskScheduler, eventBus, connectivityChecker,
mailboxApiCaller, mailboxApi, mailboxFileManager,
properties, folderId, contactId);
eventBus.addListener(worker);
return worker;
}
@Override
public MailboxWorker createDownloadWorkerForContactMailbox(
ConnectivityChecker connectivityChecker,
TorReachabilityMonitor reachabilityMonitor,
MailboxProperties properties) {
return new ContactMailboxDownloadWorker(connectivityChecker,
reachabilityMonitor, mailboxApiCaller, mailboxApi,
mailboxFileManager, properties);
}
@Override
public MailboxWorker createDownloadWorkerForOwnMailbox(
ConnectivityChecker connectivityChecker,
TorReachabilityMonitor reachabilityMonitor,
MailboxProperties properties) {
// TODO
throw new UnsupportedOperationException();
}
}

View File

@@ -17,7 +17,6 @@ import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.transport.KeyManager; import org.briarproject.bramble.api.transport.KeyManager;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.DbExpectations; import org.briarproject.bramble.test.DbExpectations;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.Collection; import java.util.Collection;
@@ -63,13 +62,9 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
private final long timestamp = System.currentTimeMillis(); private final long timestamp = System.currentTimeMillis();
private final boolean alice = new Random().nextBoolean(); private final boolean alice = new Random().nextBoolean();
private ContactManagerImpl contactManager; private final ContactManagerImpl contactManager =
new ContactManagerImpl(db, keyManager, identityManager,
@Before pendingContactFactory);
public void setUp() {
contactManager = new ContactManagerImpl(db, keyManager,
identityManager, pendingContactFactory);
}
@Test @Test
public void testAddContact() throws Exception { public void testAddContact() throws Exception {

View File

@@ -2,7 +2,6 @@ package org.briarproject.bramble.data;
import org.briarproject.bramble.test.BrambleTestCase; import org.briarproject.bramble.test.BrambleTestCase;
import org.briarproject.bramble.util.StringUtils; import org.briarproject.bramble.util.StringUtils;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@@ -17,14 +16,8 @@ import static org.junit.Assert.assertArrayEquals;
public class BdfWriterImplTest extends BrambleTestCase { public class BdfWriterImplTest extends BrambleTestCase {
private ByteArrayOutputStream out = null; private final ByteArrayOutputStream out = new ByteArrayOutputStream();
private BdfWriterImpl w = null; private final BdfWriterImpl w = new BdfWriterImpl(out);
@Before
public void setUp() {
out = new ByteArrayOutputStream();
w = new BdfWriterImpl(out);
}
@Test @Test
public void testWriteNull() throws IOException { public void testWriteNull() throws IOException {

View File

@@ -14,7 +14,6 @@ import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.DbExpectations; import org.briarproject.bramble.test.DbExpectations;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
@@ -41,13 +40,8 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
private final KeyPair handshakeKeyPair = private final KeyPair handshakeKeyPair =
new KeyPair(handshakePublicKey, handshakePrivateKey); new KeyPair(handshakePublicKey, handshakePrivateKey);
private IdentityManagerImpl identityManager; private final IdentityManagerImpl identityManager =
new IdentityManagerImpl(db, crypto, authorFactory, clock);
@Before
public void setUp() {
identityManager =
new IdentityManagerImpl(db, crypto, authorFactory, clock);
}
@Test @Test
public void testOpenDatabaseIdentityRegistered() throws Exception { public void testOpenDatabaseIdentityRegistered() throws Exception {

View File

@@ -10,7 +10,6 @@ import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.DbExpectations; import org.briarproject.bramble.test.DbExpectations;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@@ -34,12 +33,8 @@ public class LifecycleManagerImplTest extends BrambleMockTestCase {
private final SecretKey dbKey = getSecretKey(); private final SecretKey dbKey = getSecretKey();
private LifecycleManagerImpl lifecycleManager; private final LifecycleManagerImpl lifecycleManager =
new LifecycleManagerImpl(db, eventBus, clock);
@Before
public void setUp() {
lifecycleManager = new LifecycleManagerImpl(db, eventBus, clock);
}
@Test @Test
public void testOpenDatabaseHooksAreCalledAtStartup() throws Exception { public void testOpenDatabaseHooksAreCalledAtStartup() throws Exception {

View File

@@ -0,0 +1,131 @@
package org.briarproject.bramble.mailbox;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.mailbox.MailboxFolderId;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.test.BrambleMockTestCase;
import org.jmock.Expectations;
import org.junit.Test;
import static org.briarproject.bramble.api.mailbox.MailboxConstants.CLIENT_SUPPORTS;
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
import static org.briarproject.bramble.test.TestUtils.getContactId;
import static org.briarproject.bramble.test.TestUtils.getMailboxProperties;
public class ContactMailboxClientTest extends BrambleMockTestCase {
private final MailboxWorkerFactory workerFactory =
context.mock(MailboxWorkerFactory.class);
private final ConnectivityChecker connectivityChecker =
context.mock(ConnectivityChecker.class);
private final TorReachabilityMonitor reachabilityMonitor =
context.mock(TorReachabilityMonitor.class);
private final MailboxWorker uploadWorker =
context.mock(MailboxWorker.class, "uploadWorker");
private final MailboxWorker downloadWorker =
context.mock(MailboxWorker.class, "downloadWorker");
private final MailboxProperties properties =
getMailboxProperties(false, CLIENT_SUPPORTS);
private final MailboxFolderId inboxId =
requireNonNull(properties.getInboxId());
private final MailboxFolderId outboxId =
requireNonNull(properties.getOutboxId());
private final ContactId contactId = getContactId();
private final ContactMailboxClient client =
new ContactMailboxClient(workerFactory, connectivityChecker,
reachabilityMonitor);
@Test
public void testStartAndDestroyWithNoContactsAssigned() {
client.start();
client.destroy();
}
@Test
public void testAssignContactForUploadAndDestroyClient() {
client.start();
// When the contact is assigned, the worker should be created and
// started
expectCreateAndStartUploadWorker();
client.assignContactForUpload(contactId, properties, outboxId);
// When the client is destroyed, the worker should be destroyed
expectDestroyWorker(uploadWorker);
client.destroy();
}
@Test
public void testAssignAndDeassignContactForUpload() {
client.start();
// When the contact is assigned, the worker should be created and
// started
expectCreateAndStartUploadWorker();
client.assignContactForUpload(contactId, properties, outboxId);
// When the contact is deassigned, the worker should be destroyed
expectDestroyWorker(uploadWorker);
client.deassignContactForUpload(contactId);
context.assertIsSatisfied();
client.destroy();
}
@Test
public void assignContactForDownloadAndDestroyClient() {
client.start();
// When the contact is assigned, the worker should be created and
// started
expectCreateAndStartDownloadWorker();
client.assignContactForDownload(contactId, properties, inboxId);
// When the client is destroyed, the worker should be destroyed
expectDestroyWorker(downloadWorker);
client.destroy();
}
@Test
public void assignAndDeassignContactForDownload() {
client.start();
// When the contact is assigned, the worker should be created and
// started
expectCreateAndStartDownloadWorker();
client.assignContactForDownload(contactId, properties, inboxId);
// When the contact is deassigned, the worker should be destroyed
expectDestroyWorker(downloadWorker);
client.deassignContactForDownload(contactId);
context.assertIsSatisfied();
client.destroy();
}
private void expectCreateAndStartUploadWorker() {
context.checking(new Expectations() {{
oneOf(workerFactory).createUploadWorker(connectivityChecker,
properties, outboxId, contactId);
will(returnValue(uploadWorker));
oneOf(uploadWorker).start();
}});
}
private void expectCreateAndStartDownloadWorker() {
context.checking(new Expectations() {{
oneOf(workerFactory).createDownloadWorkerForContactMailbox(
connectivityChecker, reachabilityMonitor, properties);
will(returnValue(downloadWorker));
oneOf(downloadWorker).start();
}});
}
private void expectDestroyWorker(MailboxWorker worker) {
context.checking(new Expectations() {{
oneOf(worker).destroy();
}});
}
}

View File

@@ -12,7 +12,6 @@ import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.CaptureArgumentAction; import org.briarproject.bramble.test.CaptureArgumentAction;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.jmock.lib.action.DoAllAction; import org.jmock.lib.action.DoAllAction;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@@ -38,13 +37,9 @@ public class TorReachabilityMonitorImplTest extends BrambleMockTestCase {
private final TorReachabilityObserver observer = private final TorReachabilityObserver observer =
context.mock(TorReachabilityObserver.class); context.mock(TorReachabilityObserver.class);
private TorReachabilityMonitorImpl monitor; private final TorReachabilityMonitorImpl monitor =
new TorReachabilityMonitorImpl(ioExecutor, taskScheduler,
@Before pluginManager, eventBus);
public void setUp() {
monitor = new TorReachabilityMonitorImpl(ioExecutor, taskScheduler,
pluginManager, eventBus);
}
@Test @Test
public void testSchedulesTaskWhenStartedIfTorIsActive() { public void testSchedulesTaskWhenStartedIfTorIsActive() {

View File

@@ -26,7 +26,6 @@ import org.briarproject.bramble.test.ImmediateExecutor;
import org.briarproject.bramble.test.RunAction; import org.briarproject.bramble.test.RunAction;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.jmock.imposters.ByteBuddyClassImposteriser; import org.jmock.imposters.ByteBuddyClassImposteriser;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.security.SecureRandom; import java.security.SecureRandom;
@@ -59,22 +58,18 @@ public class PollerImplTest extends BrambleMockTestCase {
private final SecureRandom random; private final SecureRandom random;
private final Executor ioExecutor = new ImmediateExecutor(); private final Executor ioExecutor = new ImmediateExecutor();
private final Executor wakefulIoExecutor = new ImmediateExecutor();
private final TransportId transportId = getTransportId(); private final TransportId transportId = getTransportId();
private final ContactId contactId = getContactId(); private final ContactId contactId = getContactId();
private final TransportProperties properties = new TransportProperties(); private final TransportProperties properties = new TransportProperties();
private final int pollingInterval = 60 * 1000; private final int pollingInterval = 60 * 1000;
private final long now = System.currentTimeMillis(); private final long now = System.currentTimeMillis();
private PollerImpl poller; private final PollerImpl poller;
public PollerImplTest() { public PollerImplTest() {
context.setImposteriser(ByteBuddyClassImposteriser.INSTANCE); context.setImposteriser(ByteBuddyClassImposteriser.INSTANCE);
random = context.mock(SecureRandom.class); random = context.mock(SecureRandom.class);
} Executor wakefulIoExecutor = new ImmediateExecutor();
@Before
public void setUp() {
poller = new PollerImpl(ioExecutor, wakefulIoExecutor, scheduler, poller = new PollerImpl(ioExecutor, wakefulIoExecutor, scheduler,
connectionManager, connectionRegistry, pluginManager, connectionManager, connectionRegistry, pluginManager,
transportPropertyManager, random, clock); transportPropertyManager, random, clock);

View File

@@ -12,7 +12,6 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
import org.briarproject.bramble.api.properties.TransportProperties; import org.briarproject.bramble.api.properties.TransportProperties;
import org.briarproject.bramble.api.settings.Settings; import org.briarproject.bramble.api.settings.Settings;
import org.briarproject.bramble.test.BrambleTestCase; import org.briarproject.bramble.test.BrambleTestCase;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
@@ -46,13 +45,11 @@ public class LanTcpPluginTest extends BrambleTestCase {
private final Backoff backoff = new TestBackoff(); private final Backoff backoff = new TestBackoff();
private final ExecutorService ioExecutor = newCachedThreadPool(); private final ExecutorService ioExecutor = newCachedThreadPool();
private final Callback callback = new Callback();
private Callback callback = null; private final LanTcpPlugin plugin;
private LanTcpPlugin plugin = null;
@Before public LanTcpPluginTest() {
public void setUp() {
callback = new Callback();
plugin = new LanTcpPlugin(ioExecutor, ioExecutor, backoff, callback, plugin = new LanTcpPlugin(ioExecutor, ioExecutor, backoff, callback,
0, 0, 1000) { 0, 0, 1000) {
@Override @Override

View File

@@ -34,7 +34,6 @@ import org.briarproject.bramble.test.DbExpectations;
import org.briarproject.bramble.test.ImmediateExecutor; import org.briarproject.bramble.test.ImmediateExecutor;
import org.briarproject.bramble.test.PredicateMatcher; import org.briarproject.bramble.test.PredicateMatcher;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.Random; import java.util.Random;
@@ -93,14 +92,10 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
getTransportProperties(3); getTransportProperties(3);
private final boolean alice = new Random().nextBoolean(); private final boolean alice = new Random().nextBoolean();
private RendezvousPollerImpl rendezvousPoller; private final RendezvousPollerImpl rendezvousPoller =
new RendezvousPollerImpl(ioExecutor, scheduler, db,
@Before identityManager, transportCrypto, rendezvousCrypto,
public void setUp() { pluginManager, connectionManager, eventBus, clock);
rendezvousPoller = new RendezvousPollerImpl(ioExecutor, scheduler, db,
identityManager, transportCrypto, rendezvousCrypto,
pluginManager, connectionManager, eventBus, clock);
}
@Test @Test
public void testAddsPendingContactsAndSchedulesPollingAtStartup() public void testAddsPendingContactsAndSchedulesPollingAtStartup()

View File

@@ -14,7 +14,6 @@ import org.briarproject.bramble.api.sync.SyncRecordReader;
import org.briarproject.bramble.api.sync.Versions; import org.briarproject.bramble.api.sync.Versions;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@@ -44,12 +43,8 @@ public class SyncRecordReaderImplTest extends BrambleMockTestCase {
context.mock(MessageFactory.class); context.mock(MessageFactory.class);
private final RecordReader recordReader = context.mock(RecordReader.class); private final RecordReader recordReader = context.mock(RecordReader.class);
private SyncRecordReader reader; private final SyncRecordReader reader =
new SyncRecordReaderImpl(messageFactory, recordReader);
@Before
public void setUp() {
reader = new SyncRecordReaderImpl(messageFactory, recordReader);
}
@Test @Test
public void testNoFormatExceptionIfAckIsMaximumSize() throws Exception { public void testNoFormatExceptionIfAckIsMaximumSize() throws Exception {

View File

@@ -20,7 +20,6 @@ import org.briarproject.bramble.api.sync.validation.MessageValidator;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.DbExpectations; import org.briarproject.bramble.test.DbExpectations;
import org.briarproject.bramble.test.ImmediateExecutor; import org.briarproject.bramble.test.ImmediateExecutor;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@@ -70,11 +69,10 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
private final MessageContext validResultWithDependencies = private final MessageContext validResultWithDependencies =
new MessageContext(metadata, singletonList(messageId1)); new MessageContext(metadata, singletonList(messageId1));
private ValidationManagerImpl vm; private final ValidationManagerImpl vm =
new ValidationManagerImpl(db, dbExecutor, validationExecutor);
@Before public ValidationManagerImplTest() {
public void setUp() {
vm = new ValidationManagerImpl(db, dbExecutor, validationExecutor);
vm.registerMessageValidator(clientId, majorVersion, validator); vm.registerMessageValidator(clientId, majorVersion, validator);
vm.registerIncomingMessageHook(clientId, majorVersion, hook); vm.registerIncomingMessageHook(clientId, majorVersion, hook);
} }

View File

@@ -22,7 +22,6 @@ import org.hamcrest.Description;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.jmock.api.Action; import org.jmock.api.Action;
import org.jmock.api.Invocation; import org.jmock.api.Invocation;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
@@ -72,13 +71,9 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
private final SecretKey rootKey = getSecretKey(); private final SecretKey rootKey = getSecretKey();
private final Random random = new Random(); private final Random random = new Random();
private TransportKeyManager transportKeyManager; private final TransportKeyManager transportKeyManager =
new TransportKeyManagerImpl(db, transportCrypto, dbExecutor,
@Before scheduler, clock, transportId, maxLatency);
public void setUp() {
transportKeyManager = new TransportKeyManagerImpl(db, transportCrypto,
dbExecutor, scheduler, clock, transportId, maxLatency);
}
@Test @Test
public void testKeysAreUpdatedAtStartup() throws Exception { public void testKeysAreUpdatedAtStartup() throws Exception {

View File

@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.plugin.PluginCallback;
import org.briarproject.bramble.api.properties.TransportProperties; import org.briarproject.bramble.api.properties.TransportProperties;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
@@ -25,12 +24,8 @@ public class ModemPluginTest extends BrambleMockTestCase {
private final PluginCallback callback = context.mock(PluginCallback.class); private final PluginCallback callback = context.mock(PluginCallback.class);
private final Modem modem = context.mock(Modem.class); private final Modem modem = context.mock(Modem.class);
private ModemPlugin plugin; private final ModemPlugin plugin =
new ModemPlugin(modemFactory, serialPortList, callback, 0);
@Before
public void setUp() {
plugin = new ModemPlugin(modemFactory, serialPortList, callback, 0);
}
@Test @Test
public void testModemCreation() throws Exception { public void testModemCreation() throws Exception {