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;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.nullsafety.NullSafety;
import java.util.List;
@@ -75,4 +76,22 @@ public class MailboxProperties {
public MailboxFolderId getOutboxId() {
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;
void recordSuccessfulConnection(Transaction txn, long now)
throws DbException;
void recordSuccessfulConnection(Transaction txn, long now,
List<MailboxVersion> versions) throws DbException;
@@ -52,10 +49,8 @@ public interface MailboxSettingsManager {
* Called when Briar is paired with a mailbox
*
* @param txn A read-write transaction
* @param ownOnion Our new mailbox's onion (56 base32 chars)
*/
void mailboxPaired(Transaction txn, String ownOnion,
List<MailboxVersion> serverSupports)
void mailboxPaired(Transaction txn, MailboxProperties p)
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;
}
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() {
try {
return Cipher.getMaxAllowedKeyLength("AES/CBC/PKCS5Padding")

View File

@@ -55,6 +55,10 @@ class ContactMailboxClient implements MailboxClient {
}
if (uploadWorker != null) uploadWorker.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

View File

@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.system.Clock;
import org.briarproject.bramble.mailbox.MailboxApi.ApiException;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
@ThreadSafe
@NotNullByDefault
@@ -13,6 +14,7 @@ class ContactMailboxConnectivityChecker extends ConnectivityCheckerImpl {
private final MailboxApi mailboxApi;
@Inject
ContactMailboxConnectivityChecker(Clock clock,
MailboxApiCaller mailboxApiCaller, MailboxApi mailboxApi) {
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 -> {
mailboxSettingsManager
.setOwnMailboxProperties(txn, ownerProperties);
mailboxSettingsManager.recordSuccessfulConnection(txn, time);
mailboxSettingsManager.recordSuccessfulConnection(txn, time,
ownerProperties.getServerSupports());
// A (possibly new) mailbox is paired. Reset message retransmission
// 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.

View File

@@ -80,7 +80,7 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
encodeServerSupports(serverSupports, s);
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
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();
s.put(SETTINGS_KEY_ONION, "");
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);
for (MailboxHook hook : hooks) {
hook.mailboxUnpaired(txn);
@@ -112,34 +116,18 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
serverSupports);
}
@Override
public void recordSuccessfulConnection(Transaction txn, long now)
throws DbException {
recordSuccessfulConnection(txn, now, null);
}
@Override
public void recordSuccessfulConnection(Transaction txn, long now,
@Nullable List<MailboxVersion> versions) throws DbException {
List<MailboxVersion> versions) throws DbException {
Settings s = new Settings();
// fetch version that the server supports first
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
// record the successful connection
s.putLong(SETTINGS_KEY_LAST_ATTEMPT, now);
s.putLong(SETTINGS_KEY_LAST_SUCCESS, now);
s.putInt(SETTINGS_KEY_ATTEMPTS, 0);
encodeServerSupports(versions, s);
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
// broadcast status event
MailboxStatus status = new MailboxStatus(now, now, 0, serverSupports);
MailboxStatus status = new MailboxStatus(now, now, 0, versions);
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.MailboxUpdateWithMailbox;
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.nullsafety.NotNullByDefault;
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.ClientVersioningHook;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -159,18 +162,25 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
}
@Override
public void mailboxPaired(Transaction txn, String ownOnion,
List<MailboxVersion> serverSupports) throws DbException {
public void mailboxPaired(Transaction txn, MailboxProperties p)
throws DbException {
Map<ContactId, MailboxUpdateWithMailbox> localUpdates = new HashMap<>();
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
public void mailboxUnpaired(Transaction txn) throws DbException {
Map<ContactId, MailboxUpdate> localUpdates = new HashMap<>();
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
@@ -239,18 +249,19 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
* supported Mailbox API version(s). All of which the contact needs to
* communicate with our Mailbox.
*/
private void createAndSendUpdateWithMailbox(Transaction txn, Contact c,
List<MailboxVersion> serverSupports, String ownOnion)
throws DbException {
private MailboxUpdateWithMailbox createAndSendUpdateWithMailbox(
Transaction txn, Contact c, List<MailboxVersion> serverSupports,
String ownOnion) throws DbException {
MailboxProperties properties = new MailboxProperties(ownOnion,
new MailboxAuthToken(crypto.generateUniqueId().getBytes()),
serverSupports,
new MailboxFolderId(crypto.generateUniqueId().getBytes()),
new MailboxFolderId(crypto.generateUniqueId().getBytes()));
MailboxUpdate u =
MailboxUpdateWithMailbox u =
new MailboxUpdateWithMailbox(clientSupports, properties);
Group g = getContactGroup(c);
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
* version(s) that we support as a client.
*/
private void sendUpdateNoMailbox(Transaction txn, Contact c)
private MailboxUpdate sendUpdateNoMailbox(Transaction txn, Contact c)
throws DbException {
Group g = getContactGroup(c);
MailboxUpdate u = new MailboxUpdate(clientSupports);
storeMessageReplaceLatest(txn, g.getId(), u);
return u;
}
@Nullable

View File

@@ -86,6 +86,10 @@ class OwnMailboxClient implements MailboxClient {
for (MailboxWorker worker : uploadWorkers) worker.destroy();
if (downloadWorker != null) downloadWorker.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

View File

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

View File

@@ -40,6 +40,8 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
@Test
public void testStartAndDestroyWithNoContactsAssigned() {
client.start();
expectDestroyConnectivityChecker();
client.destroy();
}
@@ -54,6 +56,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
// When the client is destroyed, the worker should be destroyed
expectDestroyWorker(uploadWorker);
expectDestroyConnectivityChecker();
client.destroy();
}
@@ -71,6 +74,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
client.deassignContactForUpload(contactId);
context.assertIsSatisfied();
expectDestroyConnectivityChecker();
client.destroy();
}
@@ -85,6 +89,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
// When the client is destroyed, the worker should be destroyed
expectDestroyWorker(downloadWorker);
expectDestroyConnectivityChecker();
client.destroy();
}
@@ -102,6 +107,7 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
client.deassignContactForDownload(contactId);
context.assertIsSatisfied();
expectDestroyConnectivityChecker();
client.destroy();
}
@@ -128,4 +134,10 @@ public class ContactMailboxClientTest extends BrambleMockTestCase {
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(mailboxSettingsManager).setOwnMailboxProperties(
with(txn), with(matches(ownerProperties)));
oneOf(mailboxSettingsManager).recordSuccessfulConnection(txn, time);
oneOf(mailboxSettingsManager).recordSuccessfulConnection(txn, time,
ownerProperties.getServerSupports());
oneOf(db).getContacts(txn);
will(returnValue(singletonList(contact1)));
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.MailboxProperties;
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.MailboxVersion;
import org.briarproject.bramble.api.mailbox.event.OwnMailboxConnectionStatusEvent;
@@ -18,7 +19,6 @@ import java.util.List;
import java.util.Random;
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_LAST_ATTEMPT;
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_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.hasEvent;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -39,6 +40,7 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
private final SettingsManager settingsManager =
context.mock(SettingsManager.class);
private final MailboxHook hook = context.mock(MailboxHook.class);
private final MailboxSettingsManager manager =
new MailboxSettingsManagerImpl(settingsManager);
@@ -47,6 +49,8 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
private final MailboxAuthToken token = new MailboxAuthToken(getRandomId());
private final List<MailboxVersion> serverSupports =
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 ContactId contactId1 = 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.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS,
serverSupportsInts);
MailboxProperties properties = new MailboxProperties(onion, token,
serverSupports);
manager.registerMailboxHook(hook);
context.checking(new Expectations() {{
oneOf(settingsManager).mergeSettings(txn, expectedSettings,
SETTINGS_NAMESPACE);
oneOf(hook).mailboxPaired(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
public void testReturnsDefaultStatusIfSettingsAreEmpty() throws Exception {
Transaction txn = new Transaction(null, true);
@@ -147,45 +174,26 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
@Test
public void testRecordsSuccess() throws Exception {
Transaction txn = new Transaction(null, false);
Settings oldSettings = new Settings();
oldSettings
.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS, serverSupportsInts);
Settings expectedSettings = new Settings();
expectedSettings.putLong(SETTINGS_KEY_LAST_ATTEMPT, now);
expectedSettings.putLong(SETTINGS_KEY_LAST_SUCCESS, now);
expectedSettings.putInt(SETTINGS_KEY_ATTEMPTS, 0);
context.checking(new Expectations() {{
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);
expectedSettings.putIntArray(SETTINGS_KEY_SERVER_SUPPORTS,
serverSupportsInts);
context.checking(new Expectations() {{
oneOf(settingsManager).mergeSettings(txn, expectedSettings,
SETTINGS_NAMESPACE);
}});
manager.recordSuccessfulConnection(txn, now, versions);
hasEvent(txn, OwnMailboxConnectionStatusEvent.class);
manager.recordSuccessfulConnection(txn, now, serverSupports);
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

View File

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

View File

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