mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Executors and Services register themselves with the LifecycleManager.
Fixes issue #3612607.
This commit is contained in:
@@ -44,12 +44,9 @@ import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||
import net.sf.briar.clock.ClockModule;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
import net.sf.briar.db.DatabaseModule;
|
||||
import net.sf.briar.lifecycle.LifecycleModule;
|
||||
import net.sf.briar.messaging.MessagingModule;
|
||||
import net.sf.briar.messaging.duplex.DuplexMessagingModule;
|
||||
import net.sf.briar.messaging.simplex.SimplexMessagingModule;
|
||||
import net.sf.briar.plugins.JavaSePluginsModule;
|
||||
import net.sf.briar.plugins.PluginsModule;
|
||||
import net.sf.briar.reliability.ReliabilityModule;
|
||||
import net.sf.briar.serial.SerialModule;
|
||||
import net.sf.briar.transport.TransportModule;
|
||||
@@ -82,11 +79,10 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
public ProtocolIntegrationTest() throws Exception {
|
||||
super();
|
||||
Injector i = Guice.createInjector(new TestDatabaseModule(),
|
||||
new TestUiModule(), new ClockModule(), new CryptoModule(),
|
||||
new DatabaseModule(), new LifecycleModule(),
|
||||
new TestLifecycleModule(), new TestUiModule(),
|
||||
new ClockModule(), new CryptoModule(), new DatabaseModule(),
|
||||
new MessagingModule(), new DuplexMessagingModule(),
|
||||
new SimplexMessagingModule(), new PluginsModule(),
|
||||
new JavaSePluginsModule(), new ReliabilityModule(),
|
||||
new SimplexMessagingModule(), new ReliabilityModule(),
|
||||
new SerialModule(), new TransportModule());
|
||||
connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class);
|
||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||
|
||||
42
briar-tests/src/net/sf/briar/TestLifecycleModule.java
Normal file
42
briar-tests/src/net/sf/briar/TestLifecycleModule.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package net.sf.briar;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||
import net.sf.briar.api.lifecycle.Service;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
public class TestLifecycleModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(LifecycleManager.class).toInstance(new LifecycleManager() {
|
||||
|
||||
public void register(Service s) {}
|
||||
|
||||
public void registerForShutdown(ExecutorService e) {}
|
||||
|
||||
public void startServices() {}
|
||||
|
||||
public void stopServices() {}
|
||||
|
||||
public void waitForDatabase() throws InterruptedException {}
|
||||
|
||||
public void waitForStartup() throws InterruptedException {}
|
||||
|
||||
public void waitForShutdown() throws InterruptedException {}
|
||||
});
|
||||
bind(ShutdownManager.class).toInstance(new ShutdownManager() {
|
||||
|
||||
public int addShutdownHook(Runnable hook) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean removeShutdownHook(int handle) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@ import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestDatabaseModule;
|
||||
import net.sf.briar.TestLifecycleModule;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.Author;
|
||||
import net.sf.briar.api.AuthorFactory;
|
||||
@@ -40,7 +42,11 @@ import net.sf.briar.api.messaging.SubscriptionUpdate;
|
||||
import net.sf.briar.api.messaging.TransportUpdate;
|
||||
import net.sf.briar.clock.ClockModule;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
import net.sf.briar.db.DatabaseModule;
|
||||
import net.sf.briar.messaging.duplex.DuplexMessagingModule;
|
||||
import net.sf.briar.messaging.simplex.SimplexMessagingModule;
|
||||
import net.sf.briar.serial.SerialModule;
|
||||
import net.sf.briar.transport.TransportModule;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -56,9 +62,11 @@ public class ConstantsTest extends BriarTestCase {
|
||||
private final PacketWriterFactory packetWriterFactory;
|
||||
|
||||
public ConstantsTest() throws Exception {
|
||||
super();
|
||||
Injector i = Guice.createInjector(new ClockModule(), new CryptoModule(),
|
||||
new MessagingModule(), new SerialModule());
|
||||
Injector i = Guice.createInjector(new TestDatabaseModule(),
|
||||
new TestLifecycleModule(), new ClockModule(),
|
||||
new CryptoModule(), new DatabaseModule(), new MessagingModule(),
|
||||
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
||||
new SerialModule(), new TransportModule());
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
groupFactory = i.getInstance(GroupFactory.class);
|
||||
authorFactory = i.getInstance(AuthorFactory.class);
|
||||
|
||||
@@ -5,13 +5,19 @@ import java.io.IOException;
|
||||
import java.util.BitSet;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestDatabaseModule;
|
||||
import net.sf.briar.TestLifecycleModule;
|
||||
import net.sf.briar.api.messaging.PacketWriter;
|
||||
import net.sf.briar.api.messaging.Request;
|
||||
import net.sf.briar.api.serial.SerialComponent;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
import net.sf.briar.clock.ClockModule;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
import net.sf.briar.db.DatabaseModule;
|
||||
import net.sf.briar.messaging.duplex.DuplexMessagingModule;
|
||||
import net.sf.briar.messaging.simplex.SimplexMessagingModule;
|
||||
import net.sf.briar.serial.SerialModule;
|
||||
import net.sf.briar.transport.TransportModule;
|
||||
import net.sf.briar.util.StringUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -28,8 +34,11 @@ public class PacketWriterImplTest extends BriarTestCase {
|
||||
|
||||
public PacketWriterImplTest() {
|
||||
super();
|
||||
Injector i = Guice.createInjector(new ClockModule(), new CryptoModule(),
|
||||
new MessagingModule(), new SerialModule());
|
||||
Injector i = Guice.createInjector(new TestDatabaseModule(),
|
||||
new TestLifecycleModule(), new ClockModule(),
|
||||
new CryptoModule(), new DatabaseModule(), new MessagingModule(),
|
||||
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
||||
new SerialModule(), new TransportModule());
|
||||
serial = i.getInstance(SerialComponent.class);
|
||||
writerFactory = i.getInstance(WriterFactory.class);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestLifecycleModule;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
@@ -60,7 +61,6 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
||||
context = new Mockery();
|
||||
db = context.mock(DatabaseComponent.class);
|
||||
Module testModule = new AbstractModule() {
|
||||
@Override
|
||||
public void configure() {
|
||||
bind(DatabaseComponent.class).toInstance(db);
|
||||
bind(Executor.class).annotatedWith(
|
||||
@@ -68,10 +68,11 @@ public class OutgoingSimplexConnectionTest extends BriarTestCase {
|
||||
Executors.newCachedThreadPool());
|
||||
}
|
||||
};
|
||||
Injector i = Guice.createInjector(testModule, new ClockModule(),
|
||||
new CryptoModule(), new SerialModule(), new TransportModule(),
|
||||
new SimplexMessagingModule(), new MessagingModule(),
|
||||
new DuplexMessagingModule());
|
||||
Injector i = Guice.createInjector(testModule,
|
||||
new TestLifecycleModule(), new ClockModule(),
|
||||
new CryptoModule(), new MessagingModule(),
|
||||
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
||||
new SerialModule(), new TransportModule());
|
||||
connRegistry = i.getInstance(ConnectionRegistry.class);
|
||||
connWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||
packetWriterFactory = i.getInstance(PacketWriterFactory.class);
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Random;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestDatabaseModule;
|
||||
import net.sf.briar.TestUiModule;
|
||||
import net.sf.briar.TestLifecycleModule;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.Author;
|
||||
import net.sf.briar.api.AuthorId;
|
||||
@@ -35,13 +35,9 @@ import net.sf.briar.api.transport.Endpoint;
|
||||
import net.sf.briar.clock.ClockModule;
|
||||
import net.sf.briar.crypto.CryptoModule;
|
||||
import net.sf.briar.db.DatabaseModule;
|
||||
import net.sf.briar.lifecycle.LifecycleModule;
|
||||
import net.sf.briar.messaging.MessagingModule;
|
||||
import net.sf.briar.messaging.duplex.DuplexMessagingModule;
|
||||
import net.sf.briar.plugins.ImmediateExecutor;
|
||||
import net.sf.briar.plugins.JavaSePluginsModule;
|
||||
import net.sf.briar.plugins.PluginsModule;
|
||||
import net.sf.briar.reliability.ReliabilityModule;
|
||||
import net.sf.briar.serial.SerialModule;
|
||||
import net.sf.briar.transport.TransportModule;
|
||||
|
||||
@@ -85,11 +81,9 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
|
||||
private Injector createInjector(File dir) {
|
||||
return Guice.createInjector(new TestDatabaseModule(dir),
|
||||
new TestUiModule(), new ClockModule(), new CryptoModule(),
|
||||
new DatabaseModule(), new LifecycleModule(),
|
||||
new MessagingModule(), new DuplexMessagingModule(),
|
||||
new SimplexMessagingModule(), new PluginsModule(),
|
||||
new JavaSePluginsModule(), new ReliabilityModule(),
|
||||
new TestLifecycleModule(), new ClockModule(),
|
||||
new CryptoModule(), new DatabaseModule(), new MessagingModule(),
|
||||
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
||||
new SerialModule(), new TransportModule());
|
||||
}
|
||||
|
||||
|
||||
@@ -121,8 +121,8 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
simplexPluginConfig, duplexPluginConfig, db, poller,
|
||||
dispatcher, uiCallback);
|
||||
// Two plugins should be started and stopped
|
||||
assertEquals(2, p.start());
|
||||
assertEquals(2, p.stop());
|
||||
assertTrue(p.start());
|
||||
assertTrue(p.stop());
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import static net.sf.briar.api.transport.TransportConstants.MAC_LENGTH;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestLifecycleModule;
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.crypto.AuthenticatedCipher;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
@@ -34,7 +35,8 @@ public class IncomingEncryptionLayerTest extends BriarTestCase {
|
||||
|
||||
public IncomingEncryptionLayerTest() {
|
||||
super();
|
||||
Injector i = Guice.createInjector(new CryptoModule());
|
||||
Injector i = Guice.createInjector(new CryptoModule(),
|
||||
new TestLifecycleModule());
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
frameCipher = crypto.getFrameCipher();
|
||||
frameKey = crypto.generateSecretKey();
|
||||
|
||||
@@ -10,6 +10,7 @@ import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestLifecycleModule;
|
||||
import net.sf.briar.api.crypto.AuthenticatedCipher;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.crypto.ErasableKey;
|
||||
@@ -34,7 +35,8 @@ public class OutgoingEncryptionLayerTest extends BriarTestCase {
|
||||
|
||||
public OutgoingEncryptionLayerTest() {
|
||||
super();
|
||||
Injector i = Guice.createInjector(new CryptoModule());
|
||||
Injector i = Guice.createInjector(new CryptoModule(),
|
||||
new TestLifecycleModule());
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
frameCipher = crypto.getFrameCipher();
|
||||
tag = new byte[TAG_LENGTH];
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.io.OutputStream;
|
||||
import java.util.Random;
|
||||
|
||||
import net.sf.briar.BriarTestCase;
|
||||
import net.sf.briar.TestLifecycleModule;
|
||||
import net.sf.briar.TestUtils;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
@@ -45,13 +46,13 @@ public class TransportIntegrationTest extends BriarTestCase {
|
||||
public TransportIntegrationTest() {
|
||||
super();
|
||||
Module testModule = new AbstractModule() {
|
||||
@Override
|
||||
public void configure() {
|
||||
bind(ConnectionWriterFactory.class).to(
|
||||
ConnectionWriterFactoryImpl.class);
|
||||
}
|
||||
};
|
||||
Injector i = Guice.createInjector(testModule, new CryptoModule());
|
||||
Injector i = Guice.createInjector(testModule, new CryptoModule(),
|
||||
new TestLifecycleModule());
|
||||
crypto = i.getInstance(CryptoComponent.class);
|
||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||
contactId = new ContactId(234);
|
||||
|
||||
Reference in New Issue
Block a user