Merge branch '2228-mailbox-client-manager-preliminaries' into 'master'

Preliminaries for mailbox client manager

See merge request briar/briar!1693
This commit is contained in:
Torsten Grote
2022-08-02 14:41:59 +00:00
19 changed files with 358 additions and 154 deletions

View File

@@ -1,6 +1,7 @@
package org.briarproject.bramble.api.mailbox; package org.briarproject.bramble.api.mailbox;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.nullsafety.NullSafety;
import java.util.List; import java.util.List;
@@ -75,4 +76,22 @@ public class MailboxProperties {
public MailboxFolderId getOutboxId() { public MailboxFolderId getOutboxId() {
return outboxId; return outboxId;
} }
@Override
public boolean equals(Object o) {
if (o instanceof MailboxProperties) {
MailboxProperties m = (MailboxProperties) o;
return owner == m.owner &&
onion.equals(m.onion) &&
authToken.equals(m.authToken) &&
NullSafety.equals(inboxId, m.inboxId) &&
NullSafety.equals(outboxId, m.outboxId);
}
return false;
}
@Override
public int hashCode() {
return authToken.hashCode();
}
} }

View File

@@ -32,9 +32,6 @@ public interface MailboxSettingsManager {
MailboxStatus getOwnMailboxStatus(Transaction txn) throws DbException; MailboxStatus getOwnMailboxStatus(Transaction txn) throws DbException;
void recordSuccessfulConnection(Transaction txn, long now)
throws DbException;
void recordSuccessfulConnection(Transaction txn, long now, void recordSuccessfulConnection(Transaction txn, long now,
List<MailboxVersion> versions) throws DbException; List<MailboxVersion> versions) throws DbException;
@@ -52,10 +49,8 @@ public interface MailboxSettingsManager {
* Called when Briar is paired with a mailbox * Called when Briar is paired with a mailbox
* *
* @param txn A read-write transaction * @param txn A read-write transaction
* @param ownOnion Our new mailbox's onion (56 base32 chars)
*/ */
void mailboxPaired(Transaction txn, String ownOnion, void mailboxPaired(Transaction txn, MailboxProperties p)
List<MailboxVersion> serverSupports)
throws DbException; throws DbException;
/** /**

View File

@@ -0,0 +1,36 @@
package org.briarproject.bramble.api.mailbox.event;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
/**
* An event that is broadcast when a mailbox is paired.
*/
@Immutable
@NotNullByDefault
public class MailboxPairedEvent extends Event {
private final MailboxProperties properties;
private final Map<ContactId, MailboxUpdateWithMailbox> localUpdates;
public MailboxPairedEvent(MailboxProperties properties,
Map<ContactId, MailboxUpdateWithMailbox> localUpdates) {
this.properties = properties;
this.localUpdates = localUpdates;
}
public MailboxProperties getProperties() {
return properties;
}
public Map<ContactId, MailboxUpdateWithMailbox> getLocalUpdates() {
return localUpdates;
}
}

View File

@@ -0,0 +1,28 @@
package org.briarproject.bramble.api.mailbox.event;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.mailbox.MailboxUpdate;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
/**
* An event that is broadcast when a mailbox is unpaired.
*/
@Immutable
@NotNullByDefault
public class MailboxUnpairedEvent extends Event {
private final Map<ContactId, MailboxUpdate> localUpdates;
public MailboxUnpairedEvent(Map<ContactId, MailboxUpdate> localUpdates) {
this.localUpdates = localUpdates;
}
public Map<ContactId, MailboxUpdate> getLocalUpdates() {
return localUpdates;
}
}

View File

@@ -338,6 +338,17 @@ public class TestUtils {
return false; return false;
} }
public static <E extends Event> E getEvent(Transaction txn,
Class<E> eventClass) {
for (CommitAction action : txn.getActions()) {
if (action instanceof EventAction) {
Event event = ((EventAction) action).getEvent();
if (eventClass.isInstance(event)) return eventClass.cast(event);
}
}
throw new AssertionError();
}
public static boolean isCryptoStrengthUnlimited() { public static boolean isCryptoStrengthUnlimited() {
try { try {
return Cipher.getMaxAllowedKeyLength("AES/CBC/PKCS5Padding") return Cipher.getMaxAllowedKeyLength("AES/CBC/PKCS5Padding")

View File

@@ -55,6 +55,10 @@ class ContactMailboxClient implements MailboxClient {
} }
if (uploadWorker != null) uploadWorker.destroy(); if (uploadWorker != null) uploadWorker.destroy();
if (downloadWorker != null) downloadWorker.destroy(); if (downloadWorker != null) downloadWorker.destroy();
// The connectivity checker belongs to the client, so it should be
// destroyed. The Tor reachability monitor is shared between clients,
// so it should not be destroyed
connectivityChecker.destroy();
} }
@Override @Override

View File

@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.mailbox.MailboxApi.ApiException; import org.briarproject.bramble.mailbox.MailboxApi.ApiException;
import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
@ThreadSafe @ThreadSafe
@NotNullByDefault @NotNullByDefault
@@ -13,6 +14,7 @@ class ContactMailboxConnectivityChecker extends ConnectivityCheckerImpl {
private final MailboxApi mailboxApi; private final MailboxApi mailboxApi;
@Inject
ContactMailboxConnectivityChecker(Clock clock, ContactMailboxConnectivityChecker(Clock clock,
MailboxApiCaller mailboxApiCaller, MailboxApi mailboxApi) { MailboxApiCaller mailboxApiCaller, MailboxApi mailboxApi) {
super(clock, mailboxApiCaller); super(clock, mailboxApiCaller);

View File

@@ -0,0 +1,21 @@
package org.briarproject.bramble.mailbox;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@NotNullByDefault
interface MailboxClientFactory {
/**
* Creates a client for communicating with a contact's mailbox.
*/
MailboxClient createContactMailboxClient(
TorReachabilityMonitor reachabilityMonitor);
/**
* Creates a client for communicating with our own mailbox.
*/
MailboxClient createOwnMailboxClient(
TorReachabilityMonitor reachabilityMonitor,
MailboxProperties properties);
}

View File

@@ -0,0 +1,42 @@
package org.briarproject.bramble.mailbox;
import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.inject.Inject;
import javax.inject.Provider;
@NotNullByDefault
class MailboxClientFactoryImpl implements MailboxClientFactory {
private final MailboxWorkerFactory workerFactory;
private final Provider<ContactMailboxConnectivityChecker>
contactCheckerProvider;
private final Provider<OwnMailboxConnectivityChecker> ownCheckerProvider;
@Inject
MailboxClientFactoryImpl(MailboxWorkerFactory workerFactory,
Provider<ContactMailboxConnectivityChecker> contactCheckerProvider,
Provider<OwnMailboxConnectivityChecker> ownCheckerProvider) {
this.workerFactory = workerFactory;
this.contactCheckerProvider = contactCheckerProvider;
this.ownCheckerProvider = ownCheckerProvider;
}
@Override
public MailboxClient createContactMailboxClient(
TorReachabilityMonitor reachabilityMonitor) {
ConnectivityChecker connectivityChecker = contactCheckerProvider.get();
return new ContactMailboxClient(workerFactory, connectivityChecker,
reachabilityMonitor);
}
@Override
public MailboxClient createOwnMailboxClient(
TorReachabilityMonitor reachabilityMonitor,
MailboxProperties properties) {
ConnectivityChecker connectivityChecker = ownCheckerProvider.get();
return new OwnMailboxClient(workerFactory, connectivityChecker,
reachabilityMonitor, properties);
}
}

View File

@@ -120,7 +120,8 @@ class MailboxPairingTaskImpl implements MailboxPairingTask {
db.transaction(false, txn -> { db.transaction(false, txn -> {
mailboxSettingsManager mailboxSettingsManager
.setOwnMailboxProperties(txn, ownerProperties); .setOwnMailboxProperties(txn, ownerProperties);
mailboxSettingsManager.recordSuccessfulConnection(txn, time); mailboxSettingsManager.recordSuccessfulConnection(txn, time,
ownerProperties.getServerSupports());
// A (possibly new) mailbox is paired. Reset message retransmission // A (possibly new) mailbox is paired. Reset message retransmission
// timers for contacts who doesn't have their own mailbox. This way, // timers for contacts who doesn't have their own mailbox. This way,
// data stranded on our old mailbox will be re-uploaded to our new. // data stranded on our old mailbox will be re-uploaded to our new.

View File

@@ -80,7 +80,7 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
encodeServerSupports(serverSupports, s); encodeServerSupports(serverSupports, s);
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE); settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
for (MailboxHook hook : hooks) { for (MailboxHook hook : hooks) {
hook.mailboxPaired(txn, p.getOnion(), p.getServerSupports()); hook.mailboxPaired(txn, p);
} }
} }
@@ -89,6 +89,10 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
Settings s = new Settings(); Settings s = new Settings();
s.put(SETTINGS_KEY_ONION, ""); s.put(SETTINGS_KEY_ONION, "");
s.put(SETTINGS_KEY_TOKEN, ""); s.put(SETTINGS_KEY_TOKEN, "");
s.put(SETTINGS_KEY_ATTEMPTS, "");
s.put(SETTINGS_KEY_LAST_ATTEMPT, "");
s.put(SETTINGS_KEY_LAST_SUCCESS, "");
s.put(SETTINGS_KEY_SERVER_SUPPORTS, "");
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE); settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
for (MailboxHook hook : hooks) { for (MailboxHook hook : hooks) {
hook.mailboxUnpaired(txn); hook.mailboxUnpaired(txn);
@@ -112,34 +116,18 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
serverSupports); serverSupports);
} }
@Override
public void recordSuccessfulConnection(Transaction txn, long now)
throws DbException {
recordSuccessfulConnection(txn, now, null);
}
@Override @Override
public void recordSuccessfulConnection(Transaction txn, long now, public void recordSuccessfulConnection(Transaction txn, long now,
@Nullable List<MailboxVersion> versions) throws DbException { List<MailboxVersion> versions) throws DbException {
Settings s = new Settings(); Settings s = new Settings();
// fetch version that the server supports first // record the successful connection
List<MailboxVersion> serverSupports;
if (versions == null) {
Settings oldSettings =
settingsManager.getSettings(txn, SETTINGS_NAMESPACE);
serverSupports = parseServerSupports(oldSettings);
} else {
serverSupports = versions;
// store new versions
encodeServerSupports(serverSupports, s);
}
// now record the successful connection
s.putLong(SETTINGS_KEY_LAST_ATTEMPT, now); s.putLong(SETTINGS_KEY_LAST_ATTEMPT, now);
s.putLong(SETTINGS_KEY_LAST_SUCCESS, now); s.putLong(SETTINGS_KEY_LAST_SUCCESS, now);
s.putInt(SETTINGS_KEY_ATTEMPTS, 0); s.putInt(SETTINGS_KEY_ATTEMPTS, 0);
encodeServerSupports(versions, s);
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE); settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
// broadcast status event // broadcast status event
MailboxStatus status = new MailboxStatus(now, now, 0, serverSupports); MailboxStatus status = new MailboxStatus(now, now, 0, versions);
txn.attach(new OwnMailboxConnectionStatusEvent(status)); txn.attach(new OwnMailboxConnectionStatusEvent(status));
} }

View File

@@ -25,6 +25,8 @@ import org.briarproject.bramble.api.mailbox.MailboxUpdate;
import org.briarproject.bramble.api.mailbox.MailboxUpdateManager; import org.briarproject.bramble.api.mailbox.MailboxUpdateManager;
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox; import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
import org.briarproject.bramble.api.mailbox.MailboxVersion; import org.briarproject.bramble.api.mailbox.MailboxVersion;
import org.briarproject.bramble.api.mailbox.event.MailboxPairedEvent;
import org.briarproject.bramble.api.mailbox.event.MailboxUnpairedEvent;
import org.briarproject.bramble.api.mailbox.event.RemoteMailboxUpdateEvent; import org.briarproject.bramble.api.mailbox.event.RemoteMailboxUpdateEvent;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Group;
@@ -38,6 +40,7 @@ import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.api.versioning.ClientVersioningManager; import org.briarproject.bramble.api.versioning.ClientVersioningManager;
import org.briarproject.bramble.api.versioning.ClientVersioningManager.ClientVersioningHook; import org.briarproject.bramble.api.versioning.ClientVersioningManager.ClientVersioningHook;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@@ -159,18 +162,25 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
} }
@Override @Override
public void mailboxPaired(Transaction txn, String ownOnion, public void mailboxPaired(Transaction txn, MailboxProperties p)
List<MailboxVersion> serverSupports) throws DbException { throws DbException {
Map<ContactId, MailboxUpdateWithMailbox> localUpdates = new HashMap<>();
for (Contact c : db.getContacts(txn)) { for (Contact c : db.getContacts(txn)) {
createAndSendUpdateWithMailbox(txn, c, serverSupports, ownOnion); MailboxUpdateWithMailbox u = createAndSendUpdateWithMailbox(txn, c,
p.getServerSupports(), p.getOnion());
localUpdates.put(c.getId(), u);
} }
txn.attach(new MailboxPairedEvent(p, localUpdates));
} }
@Override @Override
public void mailboxUnpaired(Transaction txn) throws DbException { public void mailboxUnpaired(Transaction txn) throws DbException {
Map<ContactId, MailboxUpdate> localUpdates = new HashMap<>();
for (Contact c : db.getContacts(txn)) { for (Contact c : db.getContacts(txn)) {
sendUpdateNoMailbox(txn, c); MailboxUpdate u = sendUpdateNoMailbox(txn, c);
localUpdates.put(c.getId(), u);
} }
txn.attach(new MailboxUnpairedEvent(localUpdates));
} }
@Override @Override
@@ -239,18 +249,19 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
* supported Mailbox API version(s). All of which the contact needs to * supported Mailbox API version(s). All of which the contact needs to
* communicate with our Mailbox. * communicate with our Mailbox.
*/ */
private void createAndSendUpdateWithMailbox(Transaction txn, Contact c, private MailboxUpdateWithMailbox createAndSendUpdateWithMailbox(
List<MailboxVersion> serverSupports, String ownOnion) Transaction txn, Contact c, List<MailboxVersion> serverSupports,
throws DbException { String ownOnion) throws DbException {
MailboxProperties properties = new MailboxProperties(ownOnion, MailboxProperties properties = new MailboxProperties(ownOnion,
new MailboxAuthToken(crypto.generateUniqueId().getBytes()), new MailboxAuthToken(crypto.generateUniqueId().getBytes()),
serverSupports, serverSupports,
new MailboxFolderId(crypto.generateUniqueId().getBytes()), new MailboxFolderId(crypto.generateUniqueId().getBytes()),
new MailboxFolderId(crypto.generateUniqueId().getBytes())); new MailboxFolderId(crypto.generateUniqueId().getBytes()));
MailboxUpdate u = MailboxUpdateWithMailbox u =
new MailboxUpdateWithMailbox(clientSupports, properties); new MailboxUpdateWithMailbox(clientSupports, properties);
Group g = getContactGroup(c); Group g = getContactGroup(c);
storeMessageReplaceLatest(txn, g.getId(), u); storeMessageReplaceLatest(txn, g.getId(), u);
return u;
} }
/** /**
@@ -259,11 +270,12 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
* Mailbox that they can use. It still includes the list of Mailbox API * Mailbox that they can use. It still includes the list of Mailbox API
* version(s) that we support as a client. * version(s) that we support as a client.
*/ */
private void sendUpdateNoMailbox(Transaction txn, Contact c) private MailboxUpdate sendUpdateNoMailbox(Transaction txn, Contact c)
throws DbException { throws DbException {
Group g = getContactGroup(c); Group g = getContactGroup(c);
MailboxUpdate u = new MailboxUpdate(clientSupports); MailboxUpdate u = new MailboxUpdate(clientSupports);
storeMessageReplaceLatest(txn, g.getId(), u); storeMessageReplaceLatest(txn, g.getId(), u);
return u;
} }
@Nullable @Nullable

View File

@@ -86,6 +86,10 @@ class OwnMailboxClient implements MailboxClient {
for (MailboxWorker worker : uploadWorkers) worker.destroy(); for (MailboxWorker worker : uploadWorkers) worker.destroy();
if (downloadWorker != null) downloadWorker.destroy(); if (downloadWorker != null) downloadWorker.destroy();
contactListWorker.destroy(); contactListWorker.destroy();
// The connectivity checker belongs to the client, so it should be
// destroyed. The Tor reachability monitor is shared between clients,
// so it should not be destroyed
connectivityChecker.destroy();
} }
@Override @Override

View File

@@ -14,6 +14,7 @@ import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.annotation.concurrent.ThreadSafe; import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger; import static java.util.logging.Logger.getLogger;
@@ -30,6 +31,7 @@ class OwnMailboxConnectivityChecker extends ConnectivityCheckerImpl {
private final TransactionManager db; private final TransactionManager db;
private final MailboxSettingsManager mailboxSettingsManager; private final MailboxSettingsManager mailboxSettingsManager;
@Inject
OwnMailboxConnectivityChecker(Clock clock, OwnMailboxConnectivityChecker(Clock clock,
MailboxApiCaller mailboxApiCaller, MailboxApiCaller mailboxApiCaller,
MailboxApi mailboxApi, MailboxApi mailboxApi,

View File

@@ -40,6 +40,8 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
@Test @Test
public void testStartAndDestroyWithNoContactsAssigned() { public void testStartAndDestroyWithNoContactsAssigned() {
client.start(); client.start();
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -54,6 +56,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
// When the client is destroyed, the worker should be destroyed // When the client is destroyed, the worker should be destroyed
expectDestroyWorker(uploadWorker); expectDestroyWorker(uploadWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -71,6 +74,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
client.deassignContactForUpload(contactId); client.deassignContactForUpload(contactId);
context.assertIsSatisfied(); context.assertIsSatisfied();
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -85,6 +89,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
// When the client is destroyed, the worker should be destroyed // When the client is destroyed, the worker should be destroyed
expectDestroyWorker(downloadWorker); expectDestroyWorker(downloadWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -102,6 +107,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
client.deassignContactForDownload(contactId); client.deassignContactForDownload(contactId);
context.assertIsSatisfied(); context.assertIsSatisfied();
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -128,4 +134,10 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
oneOf(worker).destroy(); oneOf(worker).destroy();
}}); }});
} }
private void expectDestroyConnectivityChecker() {
context.checking(new Expectations() {{
oneOf(connectivityChecker).destroy();
}});
}
} }

View File

@@ -110,7 +110,8 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
oneOf(db).transaction(with(false), withDbRunnable(txn)); oneOf(db).transaction(with(false), withDbRunnable(txn));
oneOf(mailboxSettingsManager).setOwnMailboxProperties( oneOf(mailboxSettingsManager).setOwnMailboxProperties(
with(txn), with(matches(ownerProperties))); with(txn), with(matches(ownerProperties)));
oneOf(mailboxSettingsManager).recordSuccessfulConnection(txn, time); oneOf(mailboxSettingsManager).recordSuccessfulConnection(txn, time,
ownerProperties.getServerSupports());
oneOf(db).getContacts(txn); oneOf(db).getContacts(txn);
will(returnValue(singletonList(contact1))); will(returnValue(singletonList(contact1)));
oneOf(mailboxUpdateManager).getRemoteUpdate(txn, oneOf(mailboxUpdateManager).getRemoteUpdate(txn,

View File

@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.mailbox.MailboxAuthToken; import org.briarproject.bramble.api.mailbox.MailboxAuthToken;
import org.briarproject.bramble.api.mailbox.MailboxProperties; import org.briarproject.bramble.api.mailbox.MailboxProperties;
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager; import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
import org.briarproject.bramble.api.mailbox.MailboxSettingsManager.MailboxHook;
import org.briarproject.bramble.api.mailbox.MailboxStatus; import org.briarproject.bramble.api.mailbox.MailboxStatus;
import org.briarproject.bramble.api.mailbox.MailboxVersion; import org.briarproject.bramble.api.mailbox.MailboxVersion;
import org.briarproject.bramble.api.mailbox.event.OwnMailboxConnectionStatusEvent; import org.briarproject.bramble.api.mailbox.event.OwnMailboxConnectionStatusEvent;
@@ -18,7 +19,6 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_ATTEMPTS; import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_ATTEMPTS;
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_LAST_ATTEMPT; import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_LAST_ATTEMPT;
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_LAST_SUCCESS; import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_LAST_SUCCESS;
@@ -27,10 +27,11 @@ import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTIN
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_TOKEN; import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_KEY_TOKEN;
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_NAMESPACE; import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_NAMESPACE;
import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_UPLOADS_NAMESPACE; import static org.briarproject.bramble.mailbox.MailboxSettingsManagerImpl.SETTINGS_UPLOADS_NAMESPACE;
import static org.briarproject.bramble.test.TestUtils.getEvent;
import static org.briarproject.bramble.test.TestUtils.getRandomId; import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.test.TestUtils.hasEvent;
import static org.briarproject.bramble.util.StringUtils.getRandomString; import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@@ -39,6 +40,7 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
private final SettingsManager settingsManager = private final SettingsManager settingsManager =
context.mock(SettingsManager.class); context.mock(SettingsManager.class);
private final MailboxHook hook = context.mock(MailboxHook.class);
private final MailboxSettingsManager manager = private final MailboxSettingsManager manager =
new MailboxSettingsManagerImpl(settingsManager); new MailboxSettingsManagerImpl(settingsManager);
@@ -47,6 +49,8 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
private final MailboxAuthToken token = new MailboxAuthToken(getRandomId()); private final MailboxAuthToken token = new MailboxAuthToken(getRandomId());
private final List<MailboxVersion> serverSupports = private final List<MailboxVersion> serverSupports =
asList(new MailboxVersion(1, 0), new MailboxVersion(1, 1)); asList(new MailboxVersion(1, 0), new MailboxVersion(1, 1));
private final MailboxProperties properties = new MailboxProperties(onion,
token, serverSupports);
private final int[] serverSupportsInts = {1, 0, 1, 1}; private final int[] serverSupportsInts = {1, 0, 1, 1};
private final ContactId contactId1 = new ContactId(random.nextInt()); private final ContactId contactId1 = new ContactId(random.nextInt());
private final ContactId contactId2 = new ContactId(random.nextInt()); private final ContactId contactId2 = new ContactId(random.nextInt());
@@ -98,17 +102,40 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
expectedSettings.put(SETTINGS_KEY_TOKEN, token.toString()); expectedSettings.put(SETTINGS_KEY_TOKEN, token.toString());
expectedSettings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS, expectedSettings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS,
serverSupportsInts); serverSupportsInts);
MailboxProperties properties = new MailboxProperties(onion, token,
serverSupports); manager.registerMailboxHook(hook);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(settingsManager).mergeSettings(txn, expectedSettings, oneOf(settingsManager).mergeSettings(txn, expectedSettings,
SETTINGS_NAMESPACE); SETTINGS_NAMESPACE);
oneOf(hook).mailboxPaired(txn, properties);
}}); }});
manager.setOwnMailboxProperties(txn, properties); manager.setOwnMailboxProperties(txn, properties);
} }
@Test
public void testRemovesProperties() throws Exception {
Transaction txn = new Transaction(null, false);
Settings expectedSettings = new Settings();
expectedSettings.put(SETTINGS_KEY_ONION, "");
expectedSettings.put(SETTINGS_KEY_TOKEN, "");
expectedSettings.put(SETTINGS_KEY_ATTEMPTS, "");
expectedSettings.put(SETTINGS_KEY_LAST_ATTEMPT, "");
expectedSettings.put(SETTINGS_KEY_LAST_SUCCESS, "");
expectedSettings.put(SETTINGS_KEY_SERVER_SUPPORTS, "");
manager.registerMailboxHook(hook);
context.checking(new Expectations() {{
oneOf(settingsManager).mergeSettings(txn, expectedSettings,
SETTINGS_NAMESPACE);
oneOf(hook).mailboxUnpaired(txn);
}});
manager.removeOwnMailboxProperties(txn);
}
@Test @Test
public void testReturnsDefaultStatusIfSettingsAreEmpty() throws Exception { public void testReturnsDefaultStatusIfSettingsAreEmpty() throws Exception {
Transaction txn = new Transaction(null, true); Transaction txn = new Transaction(null, true);
@@ -147,45 +174,26 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testRecordsSuccess() throws Exception { public void testRecordsSuccess() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Settings oldSettings = new Settings();
oldSettings
.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS, serverSupportsInts);
Settings expectedSettings = new Settings(); Settings expectedSettings = new Settings();
expectedSettings.putLong(SETTINGS_KEY_LAST_ATTEMPT, now); expectedSettings.putLong(SETTINGS_KEY_LAST_ATTEMPT, now);
expectedSettings.putLong(SETTINGS_KEY_LAST_SUCCESS, now); expectedSettings.putLong(SETTINGS_KEY_LAST_SUCCESS, now);
expectedSettings.putInt(SETTINGS_KEY_ATTEMPTS, 0); expectedSettings.putInt(SETTINGS_KEY_ATTEMPTS, 0);
expectedSettings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS,
context.checking(new Expectations() {{ serverSupportsInts);
oneOf(settingsManager).getSettings(txn, SETTINGS_NAMESPACE);
will(returnValue(oldSettings));
oneOf(settingsManager).mergeSettings(txn, expectedSettings,
SETTINGS_NAMESPACE);
}});
manager.recordSuccessfulConnection(txn, now);
assertTrue(hasEvent(txn, OwnMailboxConnectionStatusEvent.class));
}
@Test
public void testRecordsSuccessWithVersions() throws Exception {
Transaction txn = new Transaction(null, false);
List<MailboxVersion> versions = singletonList(new MailboxVersion(2, 1));
Settings expectedSettings = new Settings();
expectedSettings.putLong(SETTINGS_KEY_LAST_ATTEMPT, now);
expectedSettings.putLong(SETTINGS_KEY_LAST_SUCCESS, now);
expectedSettings.putInt(SETTINGS_KEY_ATTEMPTS, 0);
expectedSettings.putInt(SETTINGS_KEY_SERVER_SUPPORTS, 0);
int[] newVersionsInts = {2, 1};
expectedSettings
.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS, newVersionsInts);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(settingsManager).mergeSettings(txn, expectedSettings, oneOf(settingsManager).mergeSettings(txn, expectedSettings,
SETTINGS_NAMESPACE); SETTINGS_NAMESPACE);
}}); }});
manager.recordSuccessfulConnection(txn, now, versions); manager.recordSuccessfulConnection(txn, now, serverSupports);
hasEvent(txn, OwnMailboxConnectionStatusEvent.class); OwnMailboxConnectionStatusEvent e =
getEvent(txn, OwnMailboxConnectionStatusEvent.class);
MailboxStatus status = e.getStatus();
assertEquals(now, status.getTimeOfLastAttempt());
assertEquals(now, status.getTimeOfLastSuccess());
assertEquals(0, status.getAttemptsSinceSuccess());
assertFalse(status.hasProblem(now));
} }
@Test @Test

View File

@@ -3,6 +3,7 @@ package org.briarproject.bramble.mailbox;
import org.briarproject.bramble.api.client.ClientHelper; import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.client.ContactGroupFactory; import org.briarproject.bramble.api.client.ContactGroupFactory;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.crypto.CryptoComponent; import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.data.BdfDictionary; import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry; import org.briarproject.bramble.api.data.BdfEntry;
@@ -16,6 +17,8 @@ import org.briarproject.bramble.api.mailbox.MailboxSettingsManager;
import org.briarproject.bramble.api.mailbox.MailboxUpdate; import org.briarproject.bramble.api.mailbox.MailboxUpdate;
import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox; import org.briarproject.bramble.api.mailbox.MailboxUpdateWithMailbox;
import org.briarproject.bramble.api.mailbox.MailboxVersion; import org.briarproject.bramble.api.mailbox.MailboxVersion;
import org.briarproject.bramble.api.mailbox.event.MailboxPairedEvent;
import org.briarproject.bramble.api.mailbox.event.MailboxUnpairedEvent;
import org.briarproject.bramble.api.mailbox.event.RemoteMailboxUpdateEvent; import org.briarproject.bramble.api.mailbox.event.RemoteMailboxUpdateEvent;
import org.briarproject.bramble.api.sync.Group; import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
@@ -32,6 +35,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.CLIENT_ID; import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.CLIENT_ID;
import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.GROUP_KEY_SENT_CLIENT_SUPPORTS; import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.GROUP_KEY_SENT_CLIENT_SUPPORTS;
@@ -45,6 +49,7 @@ import static org.briarproject.bramble.api.mailbox.MailboxUpdateManager.PROP_KEY
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED; import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE; import static org.briarproject.bramble.api.sync.validation.IncomingMessageHook.DeliveryAction.ACCEPT_DO_NOT_SHARE;
import static org.briarproject.bramble.test.TestUtils.getContact; import static org.briarproject.bramble.test.TestUtils.getContact;
import static org.briarproject.bramble.test.TestUtils.getEvent;
import static org.briarproject.bramble.test.TestUtils.getGroup; import static org.briarproject.bramble.test.TestUtils.getGroup;
import static org.briarproject.bramble.test.TestUtils.getMailboxProperties; import static org.briarproject.bramble.test.TestUtils.getMailboxProperties;
import static org.briarproject.bramble.test.TestUtils.getMessage; import static org.briarproject.bramble.test.TestUtils.getMessage;
@@ -71,6 +76,11 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
private final MailboxSettingsManager mailboxSettingsManager = private final MailboxSettingsManager mailboxSettingsManager =
context.mock(MailboxSettingsManager.class); context.mock(MailboxSettingsManager.class);
private final Contact contact = getContact();
private final List<Contact> contacts = singletonList(contact);
private final Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final GroupId contactGroupId = contactGroup.getId();
private final Message message = getMessage(contactGroupId);
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION); private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
private final BdfDictionary propsDict; private final BdfDictionary propsDict;
private final BdfDictionary emptyPropsDict = new BdfDictionary(); private final BdfDictionary emptyPropsDict = new BdfDictionary();
@@ -78,7 +88,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
private final BdfList someClientSupports; private final BdfList someClientSupports;
private final List<MailboxVersion> newerClientSupportsList; private final List<MailboxVersion> newerClientSupportsList;
private final BdfList newerClientSupports; private final BdfList newerClientSupports;
private final List<MailboxVersion> someServerSupportsList;
private final BdfList someServerSupports; private final BdfList someServerSupports;
private final BdfList emptyServerSupports = new BdfList(); private final BdfList emptyServerSupports = new BdfList();
private final MailboxProperties updateProps; private final MailboxProperties updateProps;
@@ -100,8 +109,8 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
newerClientSupportsList.get(0).getMajor(), newerClientSupportsList.get(0).getMajor(),
newerClientSupportsList.get(0).getMinor())); newerClientSupportsList.get(0).getMinor()));
someServerSupportsList = singletonList(new MailboxVersion( List<MailboxVersion> someServerSupportsList =
rnd.nextInt(), rnd.nextInt())); singletonList(new MailboxVersion(rnd.nextInt(), rnd.nextInt()));
someServerSupports = BdfList.of(BdfList.of( someServerSupports = BdfList.of(BdfList.of(
someServerSupportsList.get(0).getMajor(), someServerSupportsList.get(0).getMajor(),
someServerSupportsList.get(0).getMinor())); someServerSupportsList.get(0).getMinor()));
@@ -135,8 +144,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testCreatesGroupsAtUnpairedStartup() throws Exception { public void testCreatesGroupsAtUnpairedStartup() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>(); Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>();
BdfDictionary sentDict = BdfDictionary.of(new BdfEntry( BdfDictionary sentDict = BdfDictionary.of(new BdfEntry(
GROUP_KEY_SENT_CLIENT_SUPPORTS, GROUP_KEY_SENT_CLIENT_SUPPORTS,
@@ -158,8 +165,8 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
contact.getId(), CLIENT_ID, MAJOR_VERSION); contact.getId(), CLIENT_ID, MAJOR_VERSION);
will(returnValue(SHARED)); will(returnValue(SHARED));
oneOf(db).setGroupVisibility(txn, contact.getId(), oneOf(db).setGroupVisibility(txn, contact.getId(),
contactGroup.getId(), SHARED); contactGroupId, SHARED);
oneOf(clientHelper).setContactId(txn, contactGroup.getId(), oneOf(clientHelper).setContactId(txn, contactGroupId,
contact.getId()); contact.getId());
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn); oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
will(returnValue(null)); will(returnValue(null));
@@ -167,9 +174,9 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
expectStoreMessage(txn, contactGroup.getId(), 1, someClientSupports, expectStoreMessage(txn, contactGroupId, 1, someClientSupports,
emptyServerSupports, emptyPropsDict); emptyServerSupports, emptyPropsDict);
oneOf(clientHelper).mergeGroupMetadata(txn, localGroup.getId(), oneOf(clientHelper).mergeGroupMetadata(txn, localGroup.getId(),
@@ -184,8 +191,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
public void testCreatesGroupsAndCreatesAndSendsAtPairedStartup() public void testCreatesGroupsAndCreatesAndSendsAtPairedStartup()
throws Exception { throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>(); Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>();
BdfDictionary sentDict = BdfDictionary.of(new BdfEntry( BdfDictionary sentDict = BdfDictionary.of(new BdfEntry(
GROUP_KEY_SENT_CLIENT_SUPPORTS, GROUP_KEY_SENT_CLIENT_SUPPORTS,
@@ -207,8 +212,8 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
contact.getId(), CLIENT_ID, MAJOR_VERSION); contact.getId(), CLIENT_ID, MAJOR_VERSION);
will(returnValue(SHARED)); will(returnValue(SHARED));
oneOf(db).setGroupVisibility(txn, contact.getId(), oneOf(db).setGroupVisibility(txn, contact.getId(),
contactGroup.getId(), SHARED); contactGroupId, SHARED);
oneOf(clientHelper).setContactId(txn, contactGroup.getId(), oneOf(clientHelper).setContactId(txn, contactGroupId,
contact.getId()); contact.getId());
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn); oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
will(returnValue(ownProps)); will(returnValue(ownProps));
@@ -222,9 +227,9 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
expectStoreMessage(txn, contactGroup.getId(), 1, someClientSupports, expectStoreMessage(txn, contactGroupId, 1, someClientSupports,
someServerSupports, propsDict); someServerSupports, propsDict);
oneOf(clientHelper).mergeGroupMetadata(txn, localGroup.getId(), oneOf(clientHelper).mergeGroupMetadata(txn, localGroup.getId(),
@@ -239,9 +244,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
public void testUnchangedClientSupportsOnSecondStartup() throws Exception { public void testUnchangedClientSupportsOnSecondStartup() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
Map<MessageId, BdfDictionary> emptyMessageMetadata = Map<MessageId, BdfDictionary> emptyMessageMetadata =
new LinkedHashMap<>(); new LinkedHashMap<>();
BdfDictionary sentDict = BdfDictionary.of(new BdfEntry( BdfDictionary sentDict = BdfDictionary.of(new BdfEntry(
@@ -264,8 +266,8 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
contact.getId(), CLIENT_ID, MAJOR_VERSION); contact.getId(), CLIENT_ID, MAJOR_VERSION);
will(returnValue(SHARED)); will(returnValue(SHARED));
oneOf(db).setGroupVisibility(txn, contact.getId(), oneOf(db).setGroupVisibility(txn, contact.getId(),
contactGroup.getId(), SHARED); contactGroupId, SHARED);
oneOf(clientHelper).setContactId(txn, contactGroup.getId(), oneOf(clientHelper).setContactId(txn, contactGroupId,
contact.getId()); contact.getId());
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn); oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
will(returnValue(null)); will(returnValue(null));
@@ -273,9 +275,9 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(emptyMessageMetadata)); will(returnValue(emptyMessageMetadata));
expectStoreMessage(txn, contactGroup.getId(), 1, someClientSupports, expectStoreMessage(txn, contactGroupId, 1, someClientSupports,
emptyServerSupports, emptyPropsDict); emptyServerSupports, emptyPropsDict);
oneOf(clientHelper).mergeGroupMetadata(txn, localGroup.getId(), oneOf(clientHelper).mergeGroupMetadata(txn, localGroup.getId(),
@@ -304,9 +306,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
throws Exception { throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
Map<MessageId, BdfDictionary> emptyMessageMetadata = Map<MessageId, BdfDictionary> emptyMessageMetadata =
new LinkedHashMap<>(); new LinkedHashMap<>();
BdfDictionary sentDict = BdfDictionary.of(new BdfEntry( BdfDictionary sentDict = BdfDictionary.of(new BdfEntry(
@@ -329,8 +328,8 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
contact.getId(), CLIENT_ID, MAJOR_VERSION); contact.getId(), CLIENT_ID, MAJOR_VERSION);
will(returnValue(SHARED)); will(returnValue(SHARED));
oneOf(db).setGroupVisibility(txn, contact.getId(), oneOf(db).setGroupVisibility(txn, contact.getId(),
contactGroup.getId(), SHARED); contactGroupId, SHARED);
oneOf(clientHelper).setContactId(txn, contactGroup.getId(), oneOf(clientHelper).setContactId(txn, contactGroupId,
contact.getId()); contact.getId());
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn); oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
will(returnValue(null)); will(returnValue(null));
@@ -338,9 +337,9 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(emptyMessageMetadata)); will(returnValue(emptyMessageMetadata));
expectStoreMessage(txn, contactGroup.getId(), 1, someClientSupports, expectStoreMessage(txn, contactGroupId, 1, someClientSupports,
emptyServerSupports, emptyPropsDict); emptyServerSupports, emptyPropsDict);
oneOf(clientHelper).mergeGroupMetadata(txn, localGroup.getId(), oneOf(clientHelper).mergeGroupMetadata(txn, localGroup.getId(),
@@ -384,7 +383,7 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
oneOf(clientHelper).getMessageAsList(txn, messageId); oneOf(clientHelper).getMessageAsList(txn, messageId);
will(returnValue(body)); will(returnValue(body));
@@ -397,9 +396,9 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
// storeMessageReplaceLatest() // storeMessageReplaceLatest()
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
expectStoreMessage(txn, contactGroup.getId(), 2, expectStoreMessage(txn, contactGroupId, 2,
newerClientSupports, someServerSupports, propsDict); newerClientSupports, someServerSupports, propsDict);
oneOf(db).removeMessage(txn, messageId); oneOf(db).removeMessage(txn, messageId);
@@ -415,8 +414,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
public void testCreatesContactGroupWhenAddingContactUnpaired() public void testCreatesContactGroupWhenAddingContactUnpaired()
throws Exception { throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>(); Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>();
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -429,8 +426,8 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
contact.getId(), CLIENT_ID, MAJOR_VERSION); contact.getId(), CLIENT_ID, MAJOR_VERSION);
will(returnValue(SHARED)); will(returnValue(SHARED));
oneOf(db).setGroupVisibility(txn, contact.getId(), oneOf(db).setGroupVisibility(txn, contact.getId(),
contactGroup.getId(), SHARED); contactGroupId, SHARED);
oneOf(clientHelper).setContactId(txn, contactGroup.getId(), oneOf(clientHelper).setContactId(txn, contactGroupId,
contact.getId()); contact.getId());
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn); oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
will(returnValue(null)); will(returnValue(null));
@@ -438,9 +435,9 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
expectStoreMessage(txn, contactGroup.getId(), 1, someClientSupports, expectStoreMessage(txn, contactGroupId, 1, someClientSupports,
emptyServerSupports, emptyPropsDict); emptyServerSupports, emptyPropsDict);
}}); }});
@@ -452,8 +449,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
public void testCreatesContactGroupAndCreatesAndSendsWhenAddingContactPaired() public void testCreatesContactGroupAndCreatesAndSendsWhenAddingContactPaired()
throws Exception { throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>(); Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>();
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -466,8 +461,8 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
contact.getId(), CLIENT_ID, MAJOR_VERSION); contact.getId(), CLIENT_ID, MAJOR_VERSION);
will(returnValue(SHARED)); will(returnValue(SHARED));
oneOf(db).setGroupVisibility(txn, contact.getId(), oneOf(db).setGroupVisibility(txn, contact.getId(),
contactGroup.getId(), SHARED); contactGroupId, SHARED);
oneOf(clientHelper).setContactId(txn, contactGroup.getId(), oneOf(clientHelper).setContactId(txn, contactGroupId,
contact.getId()); contact.getId());
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn); oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
will(returnValue(ownProps)); will(returnValue(ownProps));
@@ -481,9 +476,9 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
expectStoreMessage(txn, contactGroup.getId(), 1, someClientSupports, expectStoreMessage(txn, contactGroupId, 1, someClientSupports,
someServerSupports, propsDict); someServerSupports, propsDict);
}}); }});
@@ -494,8 +489,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testRemovesGroupWhenRemovingContact() throws Exception { public void testRemovesGroupWhenRemovingContact() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
@@ -512,9 +505,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
public void testDoesNotDeleteAnythingWhenFirstUpdateIsDelivered() public void testDoesNotDeleteAnythingWhenFirstUpdateIsDelivered()
throws Exception { throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
GroupId contactGroupId = new GroupId(getRandomId());
Message message = getMessage(contactGroupId);
BdfList body = BdfList.of(1, someClientSupports, someServerSupports, BdfList body = BdfList.of(1, someClientSupports, someServerSupports,
propsDict); propsDict);
Metadata meta = new Metadata(); Metadata meta = new Metadata();
@@ -549,16 +539,23 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MailboxUpdateManagerImpl t = createInstance(someClientSupportsList); MailboxUpdateManagerImpl t = createInstance(someClientSupportsList);
assertEquals(ACCEPT_DO_NOT_SHARE, assertEquals(ACCEPT_DO_NOT_SHARE,
t.incomingMessage(txn, message, meta)); t.incomingMessage(txn, message, meta));
assertTrue(hasEvent(txn, RemoteMailboxUpdateEvent.class));
RemoteMailboxUpdateEvent e =
getEvent(txn, RemoteMailboxUpdateEvent.class);
assertEquals(contact.getId(), e.getContact());
MailboxUpdate u = e.getMailboxUpdate();
assertTrue(u.hasMailbox());
MailboxUpdateWithMailbox uMailbox = (MailboxUpdateWithMailbox) u;
assertEquals(updateWithMailbox.getClientSupports(),
uMailbox.getClientSupports());
assertEquals(updateWithMailbox.getMailboxProperties(),
uMailbox.getMailboxProperties());
} }
@Test @Test
public void testDeletesOlderUpdateWhenUpdateIsDelivered() public void testDeletesOlderUpdateWhenUpdateIsDelivered()
throws Exception { throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
GroupId contactGroupId = new GroupId(getRandomId());
Message message = getMessage(contactGroupId);
BdfList body = BdfList.of(1, someClientSupports, someServerSupports, BdfList body = BdfList.of(1, someClientSupports, someServerSupports,
propsDict); propsDict);
Metadata meta = new Metadata(); Metadata meta = new Metadata();
@@ -601,14 +598,22 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MailboxUpdateManagerImpl t = createInstance(someClientSupportsList); MailboxUpdateManagerImpl t = createInstance(someClientSupportsList);
assertEquals(ACCEPT_DO_NOT_SHARE, assertEquals(ACCEPT_DO_NOT_SHARE,
t.incomingMessage(txn, message, meta)); t.incomingMessage(txn, message, meta));
assertTrue(hasEvent(txn, RemoteMailboxUpdateEvent.class));
RemoteMailboxUpdateEvent e =
getEvent(txn, RemoteMailboxUpdateEvent.class);
assertEquals(contact.getId(), e.getContact());
MailboxUpdate u = e.getMailboxUpdate();
assertTrue(u.hasMailbox());
MailboxUpdateWithMailbox uMailbox = (MailboxUpdateWithMailbox) u;
assertEquals(updateWithMailbox.getClientSupports(),
uMailbox.getClientSupports());
assertEquals(updateWithMailbox.getMailboxProperties(),
uMailbox.getMailboxProperties());
} }
@Test @Test
public void testDeletesObsoleteUpdateWhenDelivered() throws Exception { public void testDeletesObsoleteUpdateWhenDelivered() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
GroupId contactGroupId = new GroupId(getRandomId());
Message message = getMessage(contactGroupId);
Metadata meta = new Metadata(); Metadata meta = new Metadata();
BdfDictionary metaDictionary = BdfDictionary.of( BdfDictionary metaDictionary = BdfDictionary.of(
new BdfEntry(MSG_KEY_VERSION, 3), new BdfEntry(MSG_KEY_VERSION, 3),
@@ -635,16 +640,13 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MailboxUpdateManagerImpl t = createInstance(someClientSupportsList); MailboxUpdateManagerImpl t = createInstance(someClientSupportsList);
assertEquals(ACCEPT_DO_NOT_SHARE, assertEquals(ACCEPT_DO_NOT_SHARE,
t.incomingMessage(txn, message, meta)); t.incomingMessage(txn, message, meta));
assertFalse(hasEvent(txn, RemoteMailboxUpdateEvent.class)); assertFalse(hasEvent(txn, RemoteMailboxUpdateEvent.class));
} }
@Test @Test
public void testCreatesAndStoresLocalUpdateWithNewVersionOnPairing() public void testCreatesAndStoresLocalUpdateWithNewVersionOnPairing()
throws Exception { throws Exception {
Contact contact = getContact();
List<Contact> contacts = singletonList(contact);
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>(); Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>();
MessageId latestId = new MessageId(getRandomId()); MessageId latestId = new MessageId(getRandomId());
@@ -671,23 +673,31 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
expectStoreMessage(txn, contactGroup.getId(), 2, someClientSupports, expectStoreMessage(txn, contactGroupId, 2, someClientSupports,
someServerSupports, propsDict); someServerSupports, propsDict);
oneOf(db).removeMessage(txn, latestId); oneOf(db).removeMessage(txn, latestId);
}}); }});
MailboxUpdateManagerImpl t = createInstance(someClientSupportsList); MailboxUpdateManagerImpl t = createInstance(someClientSupportsList);
t.mailboxPaired(txn, ownProps.getOnion(), someServerSupportsList); t.mailboxPaired(txn, ownProps);
MailboxPairedEvent e = getEvent(txn, MailboxPairedEvent.class);
assertEquals(ownProps, e.getProperties());
Map<ContactId, MailboxUpdateWithMailbox> localUpdates =
e.getLocalUpdates();
assertEquals(singleton(contact.getId()), localUpdates.keySet());
MailboxUpdateWithMailbox u = localUpdates.get(contact.getId());
assertEquals(updateWithMailbox.getClientSupports(),
u.getClientSupports());
assertEquals(updateWithMailbox.getMailboxProperties(),
u.getMailboxProperties());
} }
@Test @Test
public void testStoresLocalUpdateNoMailboxWithNewVersionOnUnpairing() public void testStoresLocalUpdateNoMailboxWithNewVersionOnUnpairing()
throws Exception { throws Exception {
Contact contact = getContact();
List<Contact> contacts = singletonList(contact);
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>(); Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>();
@@ -709,22 +719,26 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
expectStoreMessage(txn, contactGroup.getId(), 2, someClientSupports, expectStoreMessage(txn, contactGroupId, 2, someClientSupports,
emptyServerSupports, emptyPropsDict); emptyServerSupports, emptyPropsDict);
oneOf(db).removeMessage(txn, latestId); oneOf(db).removeMessage(txn, latestId);
}}); }});
MailboxUpdateManagerImpl t = createInstance(someClientSupportsList); MailboxUpdateManagerImpl t = createInstance(someClientSupportsList);
t.mailboxUnpaired(txn); t.mailboxUnpaired(txn);
MailboxUnpairedEvent e = getEvent(txn, MailboxUnpairedEvent.class);
Map<ContactId, MailboxUpdate> localUpdates = e.getLocalUpdates();
assertEquals(singleton(contact.getId()), localUpdates.keySet());
MailboxUpdate u = localUpdates.get(contact.getId());
assertFalse(u.hasMailbox());
} }
@Test @Test
public void testGetRemoteUpdate() throws Exception { public void testGetRemoteUpdate() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
BdfDictionary metaDictionary = BdfDictionary.of( BdfDictionary metaDictionary = BdfDictionary.of(
new BdfEntry(MSG_KEY_VERSION, 1), new BdfEntry(MSG_KEY_VERSION, 1),
new BdfEntry(MSG_KEY_LOCAL, false) new BdfEntry(MSG_KEY_LOCAL, false)
@@ -742,7 +756,7 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
.createContactGroup(CLIENT_ID, MAJOR_VERSION, contact); .createContactGroup(CLIENT_ID, MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
oneOf(clientHelper).getMessageAsList(txn, messageId); oneOf(clientHelper).getMessageAsList(txn, messageId);
will(returnValue(body)); will(returnValue(body));
@@ -760,8 +774,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
public void testGetRemoteUpdateReturnsNullBecauseNoUpdate() public void testGetRemoteUpdateReturnsNullBecauseNoUpdate()
throws Exception { throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
Map<MessageId, BdfDictionary> emptyMessageMetadata = Map<MessageId, BdfDictionary> emptyMessageMetadata =
new LinkedHashMap<>(); new LinkedHashMap<>();
@@ -772,7 +784,7 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(emptyMessageMetadata)); will(returnValue(emptyMessageMetadata));
}}); }});
@@ -783,8 +795,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testGetRemoteUpdateNoMailbox() throws Exception { public void testGetRemoteUpdateNoMailbox() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
BdfDictionary metaDictionary = BdfDictionary.of( BdfDictionary metaDictionary = BdfDictionary.of(
new BdfEntry(MSG_KEY_VERSION, 1), new BdfEntry(MSG_KEY_VERSION, 1),
new BdfEntry(MSG_KEY_LOCAL, false) new BdfEntry(MSG_KEY_LOCAL, false)
@@ -802,7 +812,7 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
oneOf(clientHelper).getMessageAsList(txn, messageId); oneOf(clientHelper).getMessageAsList(txn, messageId);
will(returnValue(body)); will(returnValue(body));
@@ -819,8 +829,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testGetLocalUpdate() throws Exception { public void testGetLocalUpdate() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
BdfDictionary metaDictionary = BdfDictionary.of( BdfDictionary metaDictionary = BdfDictionary.of(
new BdfEntry(MSG_KEY_VERSION, 1), new BdfEntry(MSG_KEY_VERSION, 1),
new BdfEntry(MSG_KEY_LOCAL, true) new BdfEntry(MSG_KEY_LOCAL, true)
@@ -838,7 +846,7 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
oneOf(clientHelper).getMessageAsList(txn, messageId); oneOf(clientHelper).getMessageAsList(txn, messageId);
will(returnValue(body)); will(returnValue(body));
@@ -855,8 +863,6 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testGetLocalUpdateNoMailbox() throws Exception { public void testGetLocalUpdateNoMailbox() throws Exception {
Transaction txn = new Transaction(null, false); Transaction txn = new Transaction(null, false);
Contact contact = getContact();
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
BdfDictionary metaDictionary = BdfDictionary.of( BdfDictionary metaDictionary = BdfDictionary.of(
new BdfEntry(MSG_KEY_VERSION, 1), new BdfEntry(MSG_KEY_VERSION, 1),
new BdfEntry(MSG_KEY_LOCAL, true) new BdfEntry(MSG_KEY_LOCAL, true)
@@ -874,7 +880,7 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
contactGroup.getId()); contactGroupId);
will(returnValue(messageMetadata)); will(returnValue(messageMetadata));
oneOf(clientHelper).getMessageAsList(txn, messageId); oneOf(clientHelper).getMessageAsList(txn, messageId);
will(returnValue(body)); will(returnValue(body));

View File

@@ -50,6 +50,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
client.start(); client.start();
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -67,6 +68,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
// When the client is destroyed, the worker should be destroyed // When the client is destroyed, the worker should be destroyed
expectDestroyWorker(uploadWorker1); expectDestroyWorker(uploadWorker1);
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -87,6 +89,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
context.assertIsSatisfied(); context.assertIsSatisfied();
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -120,6 +123,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
context.assertIsSatisfied(); context.assertIsSatisfied();
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -137,6 +141,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
// When the client is destroyed, the worker should be destroyed // When the client is destroyed, the worker should be destroyed
expectDestroyWorker(downloadWorker); expectDestroyWorker(downloadWorker);
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -166,6 +171,7 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
context.assertIsSatisfied(); context.assertIsSatisfied();
expectDestroyWorker(contactListWorker); expectDestroyWorker(contactListWorker);
expectDestroyConnectivityChecker();
client.destroy(); client.destroy();
} }
@@ -205,4 +211,10 @@ public class OwnMailboxClientTest extends BrambleMockTestCase {
oneOf(worker).destroy(); oneOf(worker).destroy();
}}); }});
} }
private void expectDestroyConnectivityChecker() {
context.checking(new Expectations() {{
oneOf(connectivityChecker).destroy();
}});
}
} }