From 33ef09a6bf2ab063faeb048a8e01ad69b95db3f5 Mon Sep 17 00:00:00 2001
From: akwizgran <akwizgran@users.sourceforge.net>
Date: Tue, 19 Jan 2016 15:50:29 +0000
Subject: [PATCH] Implement Service interface rather than extending it.

Whether or not a class needs to run as a service is an implementation decision.
---
 .../AndroidNotificationManagerImpl.java       |   5 +-
 .../android/AndroidNotificationManager.java   |   3 +-
 .../api/plugins/PluginManager.java            |   7 +-
 .../api/sync/MessageValidator.java            |   3 +-
 .../api/sync/ValidationManager.java           |   4 +-
 .../api/transport/KeyManager.java             |   3 +-
 .../forum/ForumPostValidator.java             |   3 +-
 .../messaging/PrivateMessageValidator.java    |   3 +-
 .../plugins/PluginManagerImpl.java            |   5 +-
 .../sync/ValidationManagerImpl.java           |   4 +-
 .../transport/KeyManagerImpl.java             |   5 +-
 .../sync/SimplexMessagingIntegrationTest.java | 117 ++++++++++--------
 12 files changed, 90 insertions(+), 72 deletions(-)

diff --git a/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java b/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java
index 8a5bcba15e..ca3ed6a4ce 100644
--- a/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java
+++ b/briar-android/src/org/briarproject/android/AndroidNotificationManagerImpl.java
@@ -25,6 +25,7 @@ import org.briarproject.api.event.EventListener;
 import org.briarproject.api.event.MessageValidatedEvent;
 import org.briarproject.api.event.SettingsUpdatedEvent;
 import org.briarproject.api.forum.ForumManager;
+import org.briarproject.api.lifecycle.Service;
 import org.briarproject.api.messaging.MessagingManager;
 import org.briarproject.api.sync.ClientId;
 import org.briarproject.api.sync.GroupId;
@@ -46,7 +47,7 @@ import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
 import static java.util.logging.Level.WARNING;
 
 class AndroidNotificationManagerImpl implements AndroidNotificationManager,
-		EventListener {
+		Service, EventListener {
 
 	private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3;
 	private static final int FORUM_POST_NOTIFICATION_ID = 4;
@@ -91,6 +92,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
 		appContext = app.getApplicationContext();
 	}
 
+	@Override
 	public boolean start() {
 		eventBus.addListener(this);
 		loadSettings();
@@ -110,6 +112,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
 		});
 	}
 
+	@Override
 	public boolean stop() {
 		eventBus.removeListener(this);
 		clearNotifications();
diff --git a/briar-api/src/org/briarproject/api/android/AndroidNotificationManager.java b/briar-api/src/org/briarproject/api/android/AndroidNotificationManager.java
index ed3223c4b7..3aad189dc3 100644
--- a/briar-api/src/org/briarproject/api/android/AndroidNotificationManager.java
+++ b/briar-api/src/org/briarproject/api/android/AndroidNotificationManager.java
@@ -1,10 +1,9 @@
 package org.briarproject.api.android;
 
-import org.briarproject.api.lifecycle.Service;
 import org.briarproject.api.sync.GroupId;
 
 /** Manages notifications for private messages and forum posts. */
-public interface AndroidNotificationManager extends Service {
+public interface AndroidNotificationManager {
 
 	void showPrivateMessageNotification(GroupId g);
 
diff --git a/briar-api/src/org/briarproject/api/plugins/PluginManager.java b/briar-api/src/org/briarproject/api/plugins/PluginManager.java
index efc336cf02..35248962d6 100644
--- a/briar-api/src/org/briarproject/api/plugins/PluginManager.java
+++ b/briar-api/src/org/briarproject/api/plugins/PluginManager.java
@@ -1,16 +1,15 @@
 package org.briarproject.api.plugins;
 
-import java.util.Collection;
-
 import org.briarproject.api.TransportId;
-import org.briarproject.api.lifecycle.Service;
 import org.briarproject.api.plugins.duplex.DuplexPlugin;
 
+import java.util.Collection;
+
 /**
  * Responsible for starting transport plugins at startup, stopping them at
  * shutdown, and providing access to plugins for exchanging invitations.
  */
-public interface PluginManager extends Service {
+public interface PluginManager {
 
 	/**
 	 * Returns the plugin for the given transport, or null if no such plugin
diff --git a/briar-api/src/org/briarproject/api/sync/MessageValidator.java b/briar-api/src/org/briarproject/api/sync/MessageValidator.java
index d318421a47..d3d7ef520a 100644
--- a/briar-api/src/org/briarproject/api/sync/MessageValidator.java
+++ b/briar-api/src/org/briarproject/api/sync/MessageValidator.java
@@ -1,9 +1,8 @@
 package org.briarproject.api.sync;
 
 import org.briarproject.api.db.Metadata;
-import org.briarproject.api.lifecycle.Service;
 
-public interface MessageValidator extends Service {
+public interface MessageValidator {
 
 	/**
 	 * Validates the given message and returns its metadata if the message
diff --git a/briar-api/src/org/briarproject/api/sync/ValidationManager.java b/briar-api/src/org/briarproject/api/sync/ValidationManager.java
index 729e96ddcc..ee1d7e9672 100644
--- a/briar-api/src/org/briarproject/api/sync/ValidationManager.java
+++ b/briar-api/src/org/briarproject/api/sync/ValidationManager.java
@@ -1,12 +1,10 @@
 package org.briarproject.api.sync;
 
-import org.briarproject.api.lifecycle.Service;
-
 /**
  * Responsible for managing message validators and passing them messages to
  * validate.
  */
-public interface ValidationManager extends Service {
+public interface ValidationManager {
 
 	/** Sets the message validator for the given client. */
 	void setMessageValidator(ClientId c, MessageValidator v);
diff --git a/briar-api/src/org/briarproject/api/transport/KeyManager.java b/briar-api/src/org/briarproject/api/transport/KeyManager.java
index e2f76f081b..32800d7af4 100644
--- a/briar-api/src/org/briarproject/api/transport/KeyManager.java
+++ b/briar-api/src/org/briarproject/api/transport/KeyManager.java
@@ -3,7 +3,6 @@ package org.briarproject.api.transport;
 import org.briarproject.api.TransportId;
 import org.briarproject.api.contact.ContactId;
 import org.briarproject.api.crypto.SecretKey;
-import org.briarproject.api.lifecycle.Service;
 
 import java.util.Collection;
 
@@ -11,7 +10,7 @@ import java.util.Collection;
  * Responsible for managing transport keys and recognising the pseudo-random
  * tags of incoming streams.
  */
-public interface KeyManager extends Service {
+public interface KeyManager {
 
 	/**
 	 * Informs the key manager that a new contact has been added. Derives and
diff --git a/briar-core/src/org/briarproject/forum/ForumPostValidator.java b/briar-core/src/org/briarproject/forum/ForumPostValidator.java
index 205b290f47..5f321d33dc 100644
--- a/briar-core/src/org/briarproject/forum/ForumPostValidator.java
+++ b/briar-core/src/org/briarproject/forum/ForumPostValidator.java
@@ -15,6 +15,7 @@ import org.briarproject.api.data.MetadataEncoder;
 import org.briarproject.api.data.ObjectReader;
 import org.briarproject.api.db.Metadata;
 import org.briarproject.api.identity.Author;
+import org.briarproject.api.lifecycle.Service;
 import org.briarproject.api.sync.Message;
 import org.briarproject.api.sync.MessageId;
 import org.briarproject.api.sync.MessageValidator;
@@ -36,7 +37,7 @@ import static org.briarproject.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
 import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
 import static org.briarproject.forum.ForumManagerImpl.CLIENT_ID;
 
-class ForumPostValidator implements MessageValidator {
+class ForumPostValidator implements MessageValidator, Service {
 
 	private static final Logger LOG =
 			Logger.getLogger(ForumPostValidator.class.getName());
diff --git a/briar-core/src/org/briarproject/messaging/PrivateMessageValidator.java b/briar-core/src/org/briarproject/messaging/PrivateMessageValidator.java
index a3b4919380..c97c66b6af 100644
--- a/briar-core/src/org/briarproject/messaging/PrivateMessageValidator.java
+++ b/briar-core/src/org/briarproject/messaging/PrivateMessageValidator.java
@@ -7,6 +7,7 @@ import org.briarproject.api.data.BdfReader;
 import org.briarproject.api.data.BdfReaderFactory;
 import org.briarproject.api.data.MetadataEncoder;
 import org.briarproject.api.db.Metadata;
+import org.briarproject.api.lifecycle.Service;
 import org.briarproject.api.sync.Message;
 import org.briarproject.api.sync.MessageId;
 import org.briarproject.api.sync.MessageValidator;
@@ -25,7 +26,7 @@ import static org.briarproject.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
 import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
 import static org.briarproject.messaging.MessagingManagerImpl.CLIENT_ID;
 
-class PrivateMessageValidator implements MessageValidator {
+class PrivateMessageValidator implements MessageValidator, Service {
 
 	private static final Logger LOG =
 			Logger.getLogger(PrivateMessageValidator.class.getName());
diff --git a/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java b/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java
index abdf165780..0625b2d246 100644
--- a/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java
+++ b/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java
@@ -10,6 +10,7 @@ import org.briarproject.api.event.EventBus;
 import org.briarproject.api.event.TransportDisabledEvent;
 import org.briarproject.api.event.TransportEnabledEvent;
 import org.briarproject.api.lifecycle.IoExecutor;
+import org.briarproject.api.lifecycle.Service;
 import org.briarproject.api.plugins.ConnectionManager;
 import org.briarproject.api.plugins.Plugin;
 import org.briarproject.api.plugins.PluginCallback;
@@ -46,7 +47,7 @@ import javax.inject.Inject;
 import static java.util.logging.Level.INFO;
 import static java.util.logging.Level.WARNING;
 
-class PluginManagerImpl implements PluginManager {
+class PluginManagerImpl implements PluginManager, Service {
 
 	private static final Logger LOG =
 			Logger.getLogger(PluginManagerImpl.class.getName());
@@ -88,6 +89,7 @@ class PluginManagerImpl implements PluginManager {
 		duplexPlugins = new CopyOnWriteArrayList<DuplexPlugin>();
 	}
 
+	@Override
 	public boolean start() {
 		// Instantiate and start the simplex plugins
 		LOG.info("Starting simplex plugins");
@@ -115,6 +117,7 @@ class PluginManagerImpl implements PluginManager {
 		return true;
 	}
 
+	@Override
 	public boolean stop() {
 		// Stop the poller
 		LOG.info("Stopping poller");
diff --git a/briar-core/src/org/briarproject/sync/ValidationManagerImpl.java b/briar-core/src/org/briarproject/sync/ValidationManagerImpl.java
index 68040be941..d3e8612661 100644
--- a/briar-core/src/org/briarproject/sync/ValidationManagerImpl.java
+++ b/briar-core/src/org/briarproject/sync/ValidationManagerImpl.java
@@ -14,6 +14,7 @@ import org.briarproject.api.event.Event;
 import org.briarproject.api.event.EventBus;
 import org.briarproject.api.event.EventListener;
 import org.briarproject.api.event.MessageAddedEvent;
+import org.briarproject.api.lifecycle.Service;
 import org.briarproject.api.sync.ClientId;
 import org.briarproject.api.sync.GroupId;
 import org.briarproject.api.sync.Message;
@@ -30,7 +31,8 @@ import java.util.logging.Logger;
 import static java.util.logging.Level.WARNING;
 import static org.briarproject.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
 
-class ValidationManagerImpl implements ValidationManager, EventListener {
+class ValidationManagerImpl implements ValidationManager, Service,
+		EventListener {
 
 	private static final Logger LOG =
 			Logger.getLogger(ValidationManagerImpl.class.getName());
diff --git a/briar-core/src/org/briarproject/transport/KeyManagerImpl.java b/briar-core/src/org/briarproject/transport/KeyManagerImpl.java
index c36e844d2e..aa50d8e5f6 100644
--- a/briar-core/src/org/briarproject/transport/KeyManagerImpl.java
+++ b/briar-core/src/org/briarproject/transport/KeyManagerImpl.java
@@ -13,6 +13,7 @@ import org.briarproject.api.event.EventBus;
 import org.briarproject.api.event.EventListener;
 import org.briarproject.api.event.TransportAddedEvent;
 import org.briarproject.api.event.TransportRemovedEvent;
+import org.briarproject.api.lifecycle.Service;
 import org.briarproject.api.system.Clock;
 import org.briarproject.api.system.Timer;
 import org.briarproject.api.transport.KeyManager;
@@ -29,7 +30,7 @@ import javax.inject.Inject;
 
 import static java.util.logging.Level.WARNING;
 
-class KeyManagerImpl implements KeyManager, EventListener {
+class KeyManagerImpl implements KeyManager, Service, EventListener {
 
 	private static final Logger LOG =
 			Logger.getLogger(KeyManagerImpl.class.getName());
@@ -55,6 +56,7 @@ class KeyManagerImpl implements KeyManager, EventListener {
 		managers = new ConcurrentHashMap<TransportId, TransportKeyManager>();
 	}
 
+	@Override
 	public boolean start() {
 		eventBus.addListener(this);
 		try {
@@ -68,6 +70,7 @@ class KeyManagerImpl implements KeyManager, EventListener {
 		return true;
 	}
 
+	@Override
 	public boolean stop() {
 		eventBus.removeListener(this);
 		return true;
diff --git a/briar-tests/src/org/briarproject/sync/SimplexMessagingIntegrationTest.java b/briar-tests/src/org/briarproject/sync/SimplexMessagingIntegrationTest.java
index 3a7be3b74b..07eb61d57a 100644
--- a/briar-tests/src/org/briarproject/sync/SimplexMessagingIntegrationTest.java
+++ b/briar-tests/src/org/briarproject/sync/SimplexMessagingIntegrationTest.java
@@ -5,7 +5,6 @@ import com.google.inject.Injector;
 
 import org.briarproject.BriarTestCase;
 import org.briarproject.TestDatabaseModule;
-import org.briarproject.TestLifecycleModule;
 import org.briarproject.TestSystemModule;
 import org.briarproject.TestUtils;
 import org.briarproject.api.TransportId;
@@ -21,6 +20,7 @@ import org.briarproject.api.identity.Author;
 import org.briarproject.api.identity.AuthorId;
 import org.briarproject.api.identity.IdentityManager;
 import org.briarproject.api.identity.LocalAuthor;
+import org.briarproject.api.lifecycle.LifecycleManager;
 import org.briarproject.api.messaging.MessagingManager;
 import org.briarproject.api.messaging.PrivateMessage;
 import org.briarproject.api.messaging.PrivateMessageFactory;
@@ -40,6 +40,7 @@ import org.briarproject.data.DataModule;
 import org.briarproject.db.DatabaseModule;
 import org.briarproject.event.EventModule;
 import org.briarproject.identity.IdentityModule;
+import org.briarproject.lifecycle.LifecycleModule;
 import org.briarproject.messaging.MessagingModule;
 import org.briarproject.plugins.ImmediateExecutor;
 import org.briarproject.transport.TransportModule;
@@ -78,17 +79,17 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
 
 	@Before
 	public void setUp() {
-		testDir.mkdirs();
+		assertTrue(testDir.mkdirs());
 		alice = createInjector(aliceDir);
 		bob = createInjector(bobDir);
 	}
 
 	private Injector createInjector(File dir) {
 		return Guice.createInjector(new TestDatabaseModule(dir),
-				new TestLifecycleModule(), new TestSystemModule(),
-				new ContactModule(), new CryptoModule(), new DatabaseModule(),
-				new DataModule(), new EventModule(), new IdentityModule(),
-				new SyncModule(), new MessagingModule(), new TransportModule());
+				new TestSystemModule(), new ContactModule(), new CryptoModule(),
+				new DatabaseModule(), new DataModule(), new EventModule(),
+				new IdentityModule(), new LifecycleModule(),
+				new MessagingModule(), new SyncModule(), new TransportModule());
 	}
 
 	@Test
@@ -97,35 +98,44 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
 	}
 
 	private byte[] write() throws Exception {
-		// Open Alice's database
+		// Instantiate Alice's services
+		LifecycleManager lifecycleManager =
+				alice.getInstance(LifecycleManager.class);
 		DatabaseComponent db = alice.getInstance(DatabaseComponent.class);
-		assertFalse(db.open());
-		// Add the transport
-		db.addTransport(transportId, MAX_LATENCY);
-		// Start Alice's key manager
+		IdentityManager identityManager =
+				alice.getInstance(IdentityManager.class);
+		ContactManager contactManager = alice.getInstance(ContactManager.class);
+		MessagingManager messagingManager =
+				alice.getInstance(MessagingManager.class);
 		KeyManager keyManager = alice.getInstance(KeyManager.class);
-		keyManager.start();
+		PrivateMessageFactory privateMessageFactory =
+				alice.getInstance(PrivateMessageFactory.class);
+		PacketWriterFactory packetWriterFactory =
+				alice.getInstance(PacketWriterFactory.class);
+		EventBus eventBus = alice.getInstance(EventBus.class);
+		StreamWriterFactory streamWriterFactory =
+				alice.getInstance(StreamWriterFactory.class);
+
+		// Start the lifecycle manager
+		lifecycleManager.startServices();
+		lifecycleManager.waitForStartup();
+		// Add a transport
+		db.addTransport(transportId, MAX_LATENCY);
 		// Add an identity for Alice
 		LocalAuthor aliceAuthor = new LocalAuthor(aliceId, "Alice",
 				new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], timestamp);
-		IdentityManager identityManager =
-				alice.getInstance(IdentityManager.class);
 		identityManager.addLocalAuthor(aliceAuthor);
 		// Add Bob as a contact
 		Author bobAuthor = new Author(bobId, "Bob",
 				new byte[MAX_PUBLIC_KEY_LENGTH]);
-		ContactManager contactManager = alice.getInstance(ContactManager.class);
 		ContactId contactId = contactManager.addContact(bobAuthor, aliceId);
-		// Create the private conversation
-		MessagingManager messagingManager =
-				alice.getInstance(MessagingManager.class);
+		// Create a private conversation
 		messagingManager.addContact(contactId);
 		// Derive and store the transport keys
 		keyManager.addContact(contactId, Collections.singletonList(transportId),
 				master, timestamp, true);
+
 		// Send Bob a message
-		PrivateMessageFactory privateMessageFactory =
-				alice.getInstance(PrivateMessageFactory.class);
 		GroupId groupId = messagingManager.getConversationId(contactId);
 		byte[] body = "Hi Bob!".getBytes("UTF-8");
 		PrivateMessage message = privateMessageFactory.createPrivateMessage(
@@ -136,14 +146,9 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
 		assertNotNull(ctx);
 		// Create a stream writer
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		StreamWriterFactory streamWriterFactory =
-				alice.getInstance(StreamWriterFactory.class);
-		OutputStream streamWriter =
-				streamWriterFactory.createStreamWriter(out, ctx);
+		OutputStream streamWriter = streamWriterFactory.createStreamWriter(
+				out, ctx);
 		// Create an outgoing sync session
-		EventBus eventBus = alice.getInstance(EventBus.class);
-		PacketWriterFactory packetWriterFactory =
-				alice.getInstance(PacketWriterFactory.class);
 		PacketWriter packetWriter = packetWriterFactory.createPacketWriter(
 				streamWriter);
 		SyncSession session = new SimplexOutgoingSession(db,
@@ -152,40 +157,51 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
 		// Write whatever needs to be written
 		session.run();
 		streamWriter.close();
+
 		// Clean up
-		keyManager.stop();
-		db.close();
+		lifecycleManager.stopServices();
+		lifecycleManager.waitForShutdown();
+
 		// Return the contents of the stream
 		return out.toByteArray();
 	}
 
 	private void read(byte[] stream) throws Exception {
-		// Open Bob's database
+		// Instantiate Bob's services
+		LifecycleManager lifecycleManager =
+				bob.getInstance(LifecycleManager.class);
 		DatabaseComponent db = bob.getInstance(DatabaseComponent.class);
-		assertFalse(db.open());
-		// Add the transport
-		db.addTransport(transportId, MAX_LATENCY);
-		// Start Bob's key manager
+		IdentityManager identityManager =
+				bob.getInstance(IdentityManager.class);
+		ContactManager contactManager = bob.getInstance(ContactManager.class);
+		MessagingManager messagingManager =
+				bob.getInstance(MessagingManager.class);
 		KeyManager keyManager = bob.getInstance(KeyManager.class);
-		keyManager.start();
+		StreamReaderFactory streamReaderFactory =
+				bob.getInstance(StreamReaderFactory.class);
+		PacketReaderFactory packetReaderFactory =
+				bob.getInstance(PacketReaderFactory.class);
+		EventBus eventBus = bob.getInstance(EventBus.class);
+
+		// Start the lifecyle manager
+		lifecycleManager.startServices();
+		lifecycleManager.waitForStartup();
+		// Add a transport
+		db.addTransport(transportId, MAX_LATENCY);
 		// Add an identity for Bob
 		LocalAuthor bobAuthor = new LocalAuthor(bobId, "Bob",
 				new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], timestamp);
-		IdentityManager identityManager =
-				bob.getInstance(IdentityManager.class);
 		identityManager.addLocalAuthor(bobAuthor);
 		// Add Alice as a contact
 		Author aliceAuthor = new Author(aliceId, "Alice",
 				new byte[MAX_PUBLIC_KEY_LENGTH]);
-		ContactManager contactManager = bob.getInstance(ContactManager.class);
 		ContactId contactId = contactManager.addContact(aliceAuthor, bobId);
-		// Create the private conversation
-		MessagingManager messagingManager =
-				bob.getInstance(MessagingManager.class);
+		// Create a private conversation
 		messagingManager.addContact(contactId);
 		// Derive and store the transport keys
 		keyManager.addContact(contactId, Collections.singletonList(transportId),
 				master, timestamp, false);
+
 		// Set up an event listener
 		MessageListener listener = new MessageListener();
 		bob.getInstance(EventBus.class).addListener(listener);
@@ -197,19 +213,13 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
 		StreamContext ctx = keyManager.getStreamContext(transportId, tag);
 		assertNotNull(ctx);
 		// Create a stream reader
-		StreamReaderFactory streamReaderFactory =
-				bob.getInstance(StreamReaderFactory.class);
-		InputStream streamReader =
-				streamReaderFactory.createStreamReader(in, ctx);
+		InputStream streamReader = streamReaderFactory.createStreamReader(
+				in, ctx);
 		// Create an incoming sync session
-		EventBus eventBus = bob.getInstance(EventBus.class);
-		PacketReaderFactory packetReaderFactory =
-				bob.getInstance(PacketReaderFactory.class);
 		PacketReader packetReader = packetReaderFactory.createPacketReader(
 				streamReader);
-		SyncSession session = new IncomingSession(db,
-				new ImmediateExecutor(), eventBus, contactId, transportId,
-				packetReader);
+		SyncSession session = new IncomingSession(db, new ImmediateExecutor(),
+				eventBus, contactId, transportId, packetReader);
 		// No messages should have been added yet
 		assertFalse(listener.messageAdded);
 		// Read whatever needs to be read
@@ -217,9 +227,10 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
 		streamReader.close();
 		// The private message from Alice should have been added
 		assertTrue(listener.messageAdded);
+
 		// Clean up
-		keyManager.stop();
-		db.close();
+		lifecycleManager.stopServices();
+		lifecycleManager.waitForShutdown();
 	}
 
 	@After
-- 
GitLab