mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Interrupt messaging session if contact or transport is removed.
This commit is contained in:
@@ -149,11 +149,13 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
StreamWriter streamWriter = streamWriterFactory.createStreamWriter(out,
|
||||
MAX_FRAME_LENGTH, ctx);
|
||||
// Create an outgoing messaging session
|
||||
EventBus eventBus = alice.getInstance(EventBus.class);
|
||||
PacketWriterFactory packetWriterFactory =
|
||||
alice.getInstance(PacketWriterFactory.class);
|
||||
MessagingSession session = new SinglePassOutgoingSession(db,
|
||||
new ImmediateExecutor(), packetWriterFactory, contactId,
|
||||
Long.MAX_VALUE, streamWriter.getOutputStream());
|
||||
MessagingSession session = new SimplexOutgoingSession(db,
|
||||
new ImmediateExecutor(), eventBus, packetWriterFactory,
|
||||
contactId, transportId, Long.MAX_VALUE,
|
||||
streamWriter.getOutputStream());
|
||||
// Write whatever needs to be written
|
||||
session.run();
|
||||
// Clean up
|
||||
@@ -207,13 +209,14 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
StreamReader streamReader = streamReaderFactory.createStreamReader(in,
|
||||
MAX_FRAME_LENGTH, ctx);
|
||||
// Create an incoming messaging session
|
||||
EventBus eventBus = bob.getInstance(EventBus.class);
|
||||
MessageVerifier messageVerifier =
|
||||
bob.getInstance(MessageVerifier.class);
|
||||
PacketReaderFactory packetReaderFactory =
|
||||
bob.getInstance(PacketReaderFactory.class);
|
||||
MessagingSession session = new IncomingSession(db,
|
||||
new ImmediateExecutor(), new ImmediateExecutor(),
|
||||
messageVerifier, packetReaderFactory, contactId,
|
||||
new ImmediateExecutor(), new ImmediateExecutor(), eventBus,
|
||||
messageVerifier, packetReaderFactory, contactId, transportId,
|
||||
streamReader.getInputStream());
|
||||
// No messages should have been added yet
|
||||
assertFalse(listener.messageAdded);
|
||||
|
||||
@@ -4,22 +4,18 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestLifecycleModule;
|
||||
import org.briarproject.TestSystemModule;
|
||||
import org.briarproject.TestUtils;
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.UniqueId;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.messaging.Ack;
|
||||
import org.briarproject.api.messaging.MessageId;
|
||||
import org.briarproject.api.messaging.MessagingSession;
|
||||
import org.briarproject.api.messaging.PacketWriterFactory;
|
||||
import org.briarproject.crypto.CryptoModule;
|
||||
import org.briarproject.event.EventModule;
|
||||
import org.briarproject.plugins.ImmediateExecutor;
|
||||
import org.briarproject.serial.SerialModule;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
@@ -30,36 +26,36 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
|
||||
public class SinglePassOutgoingSessionTest extends BriarTestCase {
|
||||
public class SimplexOutgoingSessionTest extends BriarTestCase {
|
||||
|
||||
// FIXME: This is an integration test, not a unit test
|
||||
|
||||
private final Mockery context;
|
||||
private final DatabaseComponent db;
|
||||
private final Executor dbExecutor;
|
||||
private final EventBus eventBus;
|
||||
private final PacketWriterFactory packetWriterFactory;
|
||||
private final ContactId contactId;
|
||||
private final TransportId transportId;
|
||||
private final MessageId messageId;
|
||||
private final byte[] secret;
|
||||
|
||||
public SinglePassOutgoingSessionTest() {
|
||||
public SimplexOutgoingSessionTest() {
|
||||
context = new Mockery();
|
||||
db = context.mock(DatabaseComponent.class);
|
||||
dbExecutor = Executors.newSingleThreadExecutor();
|
||||
dbExecutor = new ImmediateExecutor();
|
||||
Module testModule = new AbstractModule() {
|
||||
@Override
|
||||
public void configure() {
|
||||
bind(DatabaseComponent.class).toInstance(db);
|
||||
bind(Executor.class).annotatedWith(
|
||||
DatabaseExecutor.class).toInstance(dbExecutor);
|
||||
bind(PacketWriterFactory.class).to(
|
||||
PacketWriterFactoryImpl.class);
|
||||
}
|
||||
};
|
||||
Injector i = Guice.createInjector(testModule,
|
||||
new TestLifecycleModule(), new TestSystemModule(),
|
||||
new CryptoModule(), new EventModule(), new MessagingModule(),
|
||||
new SerialModule());
|
||||
Injector i = Guice.createInjector(testModule, new SerialModule());
|
||||
eventBus = context.mock(EventBus.class);
|
||||
packetWriterFactory = i.getInstance(PacketWriterFactory.class);
|
||||
contactId = new ContactId(234);
|
||||
transportId = new TransportId("id");
|
||||
messageId = new MessageId(TestUtils.getRandomId());
|
||||
secret = new byte[32];
|
||||
new Random().nextBytes(secret);
|
||||
@@ -68,9 +64,12 @@ public class SinglePassOutgoingSessionTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testNothingToSend() throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagingSession session = new SinglePassOutgoingSession(db, dbExecutor,
|
||||
packetWriterFactory, contactId, Long.MAX_VALUE, out);
|
||||
final SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||
dbExecutor, eventBus, packetWriterFactory, contactId,
|
||||
transportId, Long.MAX_VALUE, out);
|
||||
context.checking(new Expectations() {{
|
||||
// Add listener
|
||||
oneOf(eventBus).addListener(session);
|
||||
// No transport acks to send
|
||||
oneOf(db).generateTransportAcks(contactId);
|
||||
will(returnValue(null));
|
||||
@@ -99,6 +98,8 @@ public class SinglePassOutgoingSessionTest extends BriarTestCase {
|
||||
oneOf(db).generateBatch(with(contactId), with(any(int.class)),
|
||||
with(any(long.class)));
|
||||
will(returnValue(null));
|
||||
// Remove listener
|
||||
oneOf(eventBus).removeListener(session);
|
||||
}});
|
||||
session.run();
|
||||
// Nothing should have been written
|
||||
@@ -109,10 +110,13 @@ public class SinglePassOutgoingSessionTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testSomethingToSend() throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
MessagingSession session = new SinglePassOutgoingSession(db, dbExecutor,
|
||||
packetWriterFactory, contactId, Long.MAX_VALUE, out);
|
||||
final SimplexOutgoingSession session = new SimplexOutgoingSession(db,
|
||||
dbExecutor, eventBus, packetWriterFactory, contactId,
|
||||
transportId, Long.MAX_VALUE, out);
|
||||
final byte[] raw = new byte[1234];
|
||||
context.checking(new Expectations() {{
|
||||
// Add listener
|
||||
oneOf(eventBus).addListener(session);
|
||||
// No transport acks to send
|
||||
oneOf(db).generateTransportAcks(contactId);
|
||||
will(returnValue(null));
|
||||
@@ -148,6 +152,8 @@ public class SinglePassOutgoingSessionTest extends BriarTestCase {
|
||||
oneOf(db).generateBatch(with(contactId), with(any(int.class)),
|
||||
with(any(long.class)));
|
||||
will(returnValue(null));
|
||||
// Remove listener
|
||||
oneOf(eventBus).removeListener(session);
|
||||
}});
|
||||
session.run();
|
||||
// Something should have been written
|
||||
Reference in New Issue
Block a user