Implement Service interface rather than extending it.

Whether or not a class needs to run as a service is an implementation decision.
This commit is contained in:
akwizgran
2016-01-19 15:50:29 +00:00
parent 2cd3a3a4f0
commit 33ef09a6bf
12 changed files with 90 additions and 72 deletions

View File

@@ -25,6 +25,7 @@ import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageValidatedEvent; import org.briarproject.api.event.MessageValidatedEvent;
import org.briarproject.api.event.SettingsUpdatedEvent; import org.briarproject.api.event.SettingsUpdatedEvent;
import org.briarproject.api.forum.ForumManager; import org.briarproject.api.forum.ForumManager;
import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.messaging.MessagingManager; import org.briarproject.api.messaging.MessagingManager;
import org.briarproject.api.sync.ClientId; import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId; 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; import static java.util.logging.Level.WARNING;
class AndroidNotificationManagerImpl implements AndroidNotificationManager, class AndroidNotificationManagerImpl implements AndroidNotificationManager,
EventListener { Service, EventListener {
private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3; private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3;
private static final int FORUM_POST_NOTIFICATION_ID = 4; private static final int FORUM_POST_NOTIFICATION_ID = 4;
@@ -91,6 +92,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
appContext = app.getApplicationContext(); appContext = app.getApplicationContext();
} }
@Override
public boolean start() { public boolean start() {
eventBus.addListener(this); eventBus.addListener(this);
loadSettings(); loadSettings();
@@ -110,6 +112,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
}); });
} }
@Override
public boolean stop() { public boolean stop() {
eventBus.removeListener(this); eventBus.removeListener(this);
clearNotifications(); clearNotifications();

View File

@@ -1,10 +1,9 @@
package org.briarproject.api.android; package org.briarproject.api.android;
import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
/** Manages notifications for private messages and forum posts. */ /** Manages notifications for private messages and forum posts. */
public interface AndroidNotificationManager extends Service { public interface AndroidNotificationManager {
void showPrivateMessageNotification(GroupId g); void showPrivateMessageNotification(GroupId g);

View File

@@ -1,16 +1,15 @@
package org.briarproject.api.plugins; package org.briarproject.api.plugins;
import java.util.Collection;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.plugins.duplex.DuplexPlugin; import org.briarproject.api.plugins.duplex.DuplexPlugin;
import java.util.Collection;
/** /**
* Responsible for starting transport plugins at startup, stopping them at * Responsible for starting transport plugins at startup, stopping them at
* shutdown, and providing access to plugins for exchanging invitations. * 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 * Returns the plugin for the given transport, or null if no such plugin

View File

@@ -1,9 +1,8 @@
package org.briarproject.api.sync; package org.briarproject.api.sync;
import org.briarproject.api.db.Metadata; 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 * Validates the given message and returns its metadata if the message

View File

@@ -1,12 +1,10 @@
package org.briarproject.api.sync; package org.briarproject.api.sync;
import org.briarproject.api.lifecycle.Service;
/** /**
* Responsible for managing message validators and passing them messages to * Responsible for managing message validators and passing them messages to
* validate. * validate.
*/ */
public interface ValidationManager extends Service { public interface ValidationManager {
/** Sets the message validator for the given client. */ /** Sets the message validator for the given client. */
void setMessageValidator(ClientId c, MessageValidator v); void setMessageValidator(ClientId c, MessageValidator v);

View File

@@ -3,7 +3,6 @@ package org.briarproject.api.transport;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
import org.briarproject.api.contact.ContactId; import org.briarproject.api.contact.ContactId;
import org.briarproject.api.crypto.SecretKey; import org.briarproject.api.crypto.SecretKey;
import org.briarproject.api.lifecycle.Service;
import java.util.Collection; import java.util.Collection;
@@ -11,7 +10,7 @@ import java.util.Collection;
* Responsible for managing transport keys and recognising the pseudo-random * Responsible for managing transport keys and recognising the pseudo-random
* tags of incoming streams. * 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 * Informs the key manager that a new contact has been added. Derives and

View File

@@ -15,6 +15,7 @@ import org.briarproject.api.data.MetadataEncoder;
import org.briarproject.api.data.ObjectReader; import org.briarproject.api.data.ObjectReader;
import org.briarproject.api.db.Metadata; import org.briarproject.api.db.Metadata;
import org.briarproject.api.identity.Author; import org.briarproject.api.identity.Author;
import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.sync.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.sync.MessageValidator; 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.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
import static org.briarproject.forum.ForumManagerImpl.CLIENT_ID; import static org.briarproject.forum.ForumManagerImpl.CLIENT_ID;
class ForumPostValidator implements MessageValidator { class ForumPostValidator implements MessageValidator, Service {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(ForumPostValidator.class.getName()); Logger.getLogger(ForumPostValidator.class.getName());

View File

@@ -7,6 +7,7 @@ import org.briarproject.api.data.BdfReader;
import org.briarproject.api.data.BdfReaderFactory; import org.briarproject.api.data.BdfReaderFactory;
import org.briarproject.api.data.MetadataEncoder; import org.briarproject.api.data.MetadataEncoder;
import org.briarproject.api.db.Metadata; import org.briarproject.api.db.Metadata;
import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.sync.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.sync.MessageValidator; 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.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
import static org.briarproject.messaging.MessagingManagerImpl.CLIENT_ID; import static org.briarproject.messaging.MessagingManagerImpl.CLIENT_ID;
class PrivateMessageValidator implements MessageValidator { class PrivateMessageValidator implements MessageValidator, Service {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(PrivateMessageValidator.class.getName()); Logger.getLogger(PrivateMessageValidator.class.getName());

View File

@@ -10,6 +10,7 @@ import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.TransportDisabledEvent; import org.briarproject.api.event.TransportDisabledEvent;
import org.briarproject.api.event.TransportEnabledEvent; import org.briarproject.api.event.TransportEnabledEvent;
import org.briarproject.api.lifecycle.IoExecutor; import org.briarproject.api.lifecycle.IoExecutor;
import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.plugins.ConnectionManager; import org.briarproject.api.plugins.ConnectionManager;
import org.briarproject.api.plugins.Plugin; import org.briarproject.api.plugins.Plugin;
import org.briarproject.api.plugins.PluginCallback; 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.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
class PluginManagerImpl implements PluginManager { class PluginManagerImpl implements PluginManager, Service {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(PluginManagerImpl.class.getName()); Logger.getLogger(PluginManagerImpl.class.getName());
@@ -88,6 +89,7 @@ class PluginManagerImpl implements PluginManager {
duplexPlugins = new CopyOnWriteArrayList<DuplexPlugin>(); duplexPlugins = new CopyOnWriteArrayList<DuplexPlugin>();
} }
@Override
public boolean start() { public boolean start() {
// Instantiate and start the simplex plugins // Instantiate and start the simplex plugins
LOG.info("Starting simplex plugins"); LOG.info("Starting simplex plugins");
@@ -115,6 +117,7 @@ class PluginManagerImpl implements PluginManager {
return true; return true;
} }
@Override
public boolean stop() { public boolean stop() {
// Stop the poller // Stop the poller
LOG.info("Stopping poller"); LOG.info("Stopping poller");

View File

@@ -14,6 +14,7 @@ import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus; import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener; import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent; import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.sync.ClientId; import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message; import org.briarproject.api.sync.Message;
@@ -30,7 +31,8 @@ import java.util.logging.Logger;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH; 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 = private static final Logger LOG =
Logger.getLogger(ValidationManagerImpl.class.getName()); Logger.getLogger(ValidationManagerImpl.class.getName());

View File

@@ -13,6 +13,7 @@ import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener; import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.TransportAddedEvent; import org.briarproject.api.event.TransportAddedEvent;
import org.briarproject.api.event.TransportRemovedEvent; import org.briarproject.api.event.TransportRemovedEvent;
import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.api.system.Timer; import org.briarproject.api.system.Timer;
import org.briarproject.api.transport.KeyManager; import org.briarproject.api.transport.KeyManager;
@@ -29,7 +30,7 @@ import javax.inject.Inject;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
class KeyManagerImpl implements KeyManager, EventListener { class KeyManagerImpl implements KeyManager, Service, EventListener {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(KeyManagerImpl.class.getName()); Logger.getLogger(KeyManagerImpl.class.getName());
@@ -55,6 +56,7 @@ class KeyManagerImpl implements KeyManager, EventListener {
managers = new ConcurrentHashMap<TransportId, TransportKeyManager>(); managers = new ConcurrentHashMap<TransportId, TransportKeyManager>();
} }
@Override
public boolean start() { public boolean start() {
eventBus.addListener(this); eventBus.addListener(this);
try { try {
@@ -68,6 +70,7 @@ class KeyManagerImpl implements KeyManager, EventListener {
return true; return true;
} }
@Override
public boolean stop() { public boolean stop() {
eventBus.removeListener(this); eventBus.removeListener(this);
return true; return true;

View File

@@ -5,7 +5,6 @@ import com.google.inject.Injector;
import org.briarproject.BriarTestCase; import org.briarproject.BriarTestCase;
import org.briarproject.TestDatabaseModule; import org.briarproject.TestDatabaseModule;
import org.briarproject.TestLifecycleModule;
import org.briarproject.TestSystemModule; import org.briarproject.TestSystemModule;
import org.briarproject.TestUtils; import org.briarproject.TestUtils;
import org.briarproject.api.TransportId; 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.AuthorId;
import org.briarproject.api.identity.IdentityManager; import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.identity.LocalAuthor; import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.messaging.MessagingManager; import org.briarproject.api.messaging.MessagingManager;
import org.briarproject.api.messaging.PrivateMessage; import org.briarproject.api.messaging.PrivateMessage;
import org.briarproject.api.messaging.PrivateMessageFactory; import org.briarproject.api.messaging.PrivateMessageFactory;
@@ -40,6 +40,7 @@ import org.briarproject.data.DataModule;
import org.briarproject.db.DatabaseModule; import org.briarproject.db.DatabaseModule;
import org.briarproject.event.EventModule; import org.briarproject.event.EventModule;
import org.briarproject.identity.IdentityModule; import org.briarproject.identity.IdentityModule;
import org.briarproject.lifecycle.LifecycleModule;
import org.briarproject.messaging.MessagingModule; import org.briarproject.messaging.MessagingModule;
import org.briarproject.plugins.ImmediateExecutor; import org.briarproject.plugins.ImmediateExecutor;
import org.briarproject.transport.TransportModule; import org.briarproject.transport.TransportModule;
@@ -78,17 +79,17 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
@Before @Before
public void setUp() { public void setUp() {
testDir.mkdirs(); assertTrue(testDir.mkdirs());
alice = createInjector(aliceDir); alice = createInjector(aliceDir);
bob = createInjector(bobDir); bob = createInjector(bobDir);
} }
private Injector createInjector(File dir) { private Injector createInjector(File dir) {
return Guice.createInjector(new TestDatabaseModule(dir), return Guice.createInjector(new TestDatabaseModule(dir),
new TestLifecycleModule(), new TestSystemModule(), new TestSystemModule(), new ContactModule(), new CryptoModule(),
new ContactModule(), new CryptoModule(), new DatabaseModule(), new DatabaseModule(), new DataModule(), new EventModule(),
new DataModule(), new EventModule(), new IdentityModule(), new IdentityModule(), new LifecycleModule(),
new SyncModule(), new MessagingModule(), new TransportModule()); new MessagingModule(), new SyncModule(), new TransportModule());
} }
@Test @Test
@@ -97,35 +98,44 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
} }
private byte[] write() throws Exception { 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); DatabaseComponent db = alice.getInstance(DatabaseComponent.class);
assertFalse(db.open()); IdentityManager identityManager =
// Add the transport alice.getInstance(IdentityManager.class);
db.addTransport(transportId, MAX_LATENCY); ContactManager contactManager = alice.getInstance(ContactManager.class);
// Start Alice's key manager MessagingManager messagingManager =
alice.getInstance(MessagingManager.class);
KeyManager keyManager = alice.getInstance(KeyManager.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 // Add an identity for Alice
LocalAuthor aliceAuthor = new LocalAuthor(aliceId, "Alice", LocalAuthor aliceAuthor = new LocalAuthor(aliceId, "Alice",
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], timestamp); new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], timestamp);
IdentityManager identityManager =
alice.getInstance(IdentityManager.class);
identityManager.addLocalAuthor(aliceAuthor); identityManager.addLocalAuthor(aliceAuthor);
// Add Bob as a contact // Add Bob as a contact
Author bobAuthor = new Author(bobId, "Bob", Author bobAuthor = new Author(bobId, "Bob",
new byte[MAX_PUBLIC_KEY_LENGTH]); new byte[MAX_PUBLIC_KEY_LENGTH]);
ContactManager contactManager = alice.getInstance(ContactManager.class);
ContactId contactId = contactManager.addContact(bobAuthor, aliceId); ContactId contactId = contactManager.addContact(bobAuthor, aliceId);
// Create the private conversation // Create a private conversation
MessagingManager messagingManager =
alice.getInstance(MessagingManager.class);
messagingManager.addContact(contactId); messagingManager.addContact(contactId);
// Derive and store the transport keys // Derive and store the transport keys
keyManager.addContact(contactId, Collections.singletonList(transportId), keyManager.addContact(contactId, Collections.singletonList(transportId),
master, timestamp, true); master, timestamp, true);
// Send Bob a message // Send Bob a message
PrivateMessageFactory privateMessageFactory =
alice.getInstance(PrivateMessageFactory.class);
GroupId groupId = messagingManager.getConversationId(contactId); GroupId groupId = messagingManager.getConversationId(contactId);
byte[] body = "Hi Bob!".getBytes("UTF-8"); byte[] body = "Hi Bob!".getBytes("UTF-8");
PrivateMessage message = privateMessageFactory.createPrivateMessage( PrivateMessage message = privateMessageFactory.createPrivateMessage(
@@ -136,14 +146,9 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
assertNotNull(ctx); assertNotNull(ctx);
// Create a stream writer // Create a stream writer
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamWriterFactory streamWriterFactory = OutputStream streamWriter = streamWriterFactory.createStreamWriter(
alice.getInstance(StreamWriterFactory.class); out, ctx);
OutputStream streamWriter =
streamWriterFactory.createStreamWriter(out, ctx);
// Create an outgoing sync session // Create an outgoing sync session
EventBus eventBus = alice.getInstance(EventBus.class);
PacketWriterFactory packetWriterFactory =
alice.getInstance(PacketWriterFactory.class);
PacketWriter packetWriter = packetWriterFactory.createPacketWriter( PacketWriter packetWriter = packetWriterFactory.createPacketWriter(
streamWriter); streamWriter);
SyncSession session = new SimplexOutgoingSession(db, SyncSession session = new SimplexOutgoingSession(db,
@@ -152,40 +157,51 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
// Write whatever needs to be written // Write whatever needs to be written
session.run(); session.run();
streamWriter.close(); streamWriter.close();
// Clean up // Clean up
keyManager.stop(); lifecycleManager.stopServices();
db.close(); lifecycleManager.waitForShutdown();
// Return the contents of the stream // Return the contents of the stream
return out.toByteArray(); return out.toByteArray();
} }
private void read(byte[] stream) throws Exception { 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); DatabaseComponent db = bob.getInstance(DatabaseComponent.class);
assertFalse(db.open()); IdentityManager identityManager =
// Add the transport bob.getInstance(IdentityManager.class);
db.addTransport(transportId, MAX_LATENCY); ContactManager contactManager = bob.getInstance(ContactManager.class);
// Start Bob's key manager MessagingManager messagingManager =
bob.getInstance(MessagingManager.class);
KeyManager keyManager = bob.getInstance(KeyManager.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 // Add an identity for Bob
LocalAuthor bobAuthor = new LocalAuthor(bobId, "Bob", LocalAuthor bobAuthor = new LocalAuthor(bobId, "Bob",
new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], timestamp); new byte[MAX_PUBLIC_KEY_LENGTH], new byte[100], timestamp);
IdentityManager identityManager =
bob.getInstance(IdentityManager.class);
identityManager.addLocalAuthor(bobAuthor); identityManager.addLocalAuthor(bobAuthor);
// Add Alice as a contact // Add Alice as a contact
Author aliceAuthor = new Author(aliceId, "Alice", Author aliceAuthor = new Author(aliceId, "Alice",
new byte[MAX_PUBLIC_KEY_LENGTH]); new byte[MAX_PUBLIC_KEY_LENGTH]);
ContactManager contactManager = bob.getInstance(ContactManager.class);
ContactId contactId = contactManager.addContact(aliceAuthor, bobId); ContactId contactId = contactManager.addContact(aliceAuthor, bobId);
// Create the private conversation // Create a private conversation
MessagingManager messagingManager =
bob.getInstance(MessagingManager.class);
messagingManager.addContact(contactId); messagingManager.addContact(contactId);
// Derive and store the transport keys // Derive and store the transport keys
keyManager.addContact(contactId, Collections.singletonList(transportId), keyManager.addContact(contactId, Collections.singletonList(transportId),
master, timestamp, false); master, timestamp, false);
// Set up an event listener // Set up an event listener
MessageListener listener = new MessageListener(); MessageListener listener = new MessageListener();
bob.getInstance(EventBus.class).addListener(listener); bob.getInstance(EventBus.class).addListener(listener);
@@ -197,19 +213,13 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
StreamContext ctx = keyManager.getStreamContext(transportId, tag); StreamContext ctx = keyManager.getStreamContext(transportId, tag);
assertNotNull(ctx); assertNotNull(ctx);
// Create a stream reader // Create a stream reader
StreamReaderFactory streamReaderFactory = InputStream streamReader = streamReaderFactory.createStreamReader(
bob.getInstance(StreamReaderFactory.class); in, ctx);
InputStream streamReader =
streamReaderFactory.createStreamReader(in, ctx);
// Create an incoming sync session // Create an incoming sync session
EventBus eventBus = bob.getInstance(EventBus.class);
PacketReaderFactory packetReaderFactory =
bob.getInstance(PacketReaderFactory.class);
PacketReader packetReader = packetReaderFactory.createPacketReader( PacketReader packetReader = packetReaderFactory.createPacketReader(
streamReader); streamReader);
SyncSession session = new IncomingSession(db, SyncSession session = new IncomingSession(db, new ImmediateExecutor(),
new ImmediateExecutor(), eventBus, contactId, transportId, eventBus, contactId, transportId, packetReader);
packetReader);
// No messages should have been added yet // No messages should have been added yet
assertFalse(listener.messageAdded); assertFalse(listener.messageAdded);
// Read whatever needs to be read // Read whatever needs to be read
@@ -217,9 +227,10 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
streamReader.close(); streamReader.close();
// The private message from Alice should have been added // The private message from Alice should have been added
assertTrue(listener.messageAdded); assertTrue(listener.messageAdded);
// Clean up // Clean up
keyManager.stop(); lifecycleManager.stopServices();
db.close(); lifecycleManager.waitForShutdown();
} }
@After @After