mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Merge branch 'tests-cleanup' into 'master'
Clean up tests * Broke up ConstantsTest (#280) - the key encoding parts are now in KeyEncodingAndParsingTest, the message encoding parts are in MessageSizeIntegrationTest * Renamed the other integration tests in briar-android-tests * Moved the integration tests in briar-android-tests to the top-level package, as they all involve code from multiple packages * Separated DatabaseExecutorModule from DatabaseModule so we can use a different @DatabaseExecutor in integration tests * Merged AppModule with AndroidModule (@ernir, this touches code you're working on but I don't think there are any conflicts) * Renamed some TestUtils methods for consistency * Used TestUtils.getRandomBytes() where applicable Fixes #280. See merge request !133
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package org.briarproject.db;
|
||||
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
@Module
|
||||
public class DatabaseExecutorModule {
|
||||
|
||||
public static class EagerSingletons {
|
||||
@Inject
|
||||
@DatabaseExecutor
|
||||
ExecutorService executorService;
|
||||
}
|
||||
|
||||
private final ExecutorService databaseExecutor;
|
||||
|
||||
public DatabaseExecutorModule() {
|
||||
// Use an unbounded queue
|
||||
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
||||
// Discard tasks that are submitted during shutdown
|
||||
RejectedExecutionHandler policy =
|
||||
new ThreadPoolExecutor.DiscardPolicy();
|
||||
// Use a single thread and keep it in the pool for 60 secs
|
||||
databaseExecutor = new ThreadPoolExecutor(0, 1, 60, SECONDS, queue,
|
||||
policy);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@DatabaseExecutor
|
||||
ExecutorService provideDatabaseExecutorService(
|
||||
LifecycleManager lifecycleManager) {
|
||||
lifecycleManager.registerForShutdown(databaseExecutor);
|
||||
return databaseExecutor;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@DatabaseExecutor
|
||||
Executor provideDatabaseExecutor(
|
||||
@DatabaseExecutor ExecutorService dbExecutor) {
|
||||
return dbExecutor;
|
||||
}
|
||||
}
|
||||
@@ -2,50 +2,21 @@ package org.briarproject.db;
|
||||
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||
import org.briarproject.api.system.Clock;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.sql.Connection;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
@Module
|
||||
public class DatabaseModule {
|
||||
|
||||
public static class EagerSingletons {
|
||||
@Inject
|
||||
@DatabaseExecutor ExecutorService executorService;
|
||||
}
|
||||
|
||||
private final ExecutorService databaseExecutor;
|
||||
|
||||
public DatabaseModule() {
|
||||
// Use an unbounded queue
|
||||
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
||||
// Discard tasks that are submitted during shutdown
|
||||
RejectedExecutionHandler policy =
|
||||
new ThreadPoolExecutor.DiscardPolicy();
|
||||
// Use a single thread and keep it in the pool for 60 secs
|
||||
databaseExecutor = new ThreadPoolExecutor(0, 1, 60, SECONDS, queue,
|
||||
policy);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Database<Connection> provideDatabase(DatabaseConfig config,
|
||||
@@ -53,21 +24,11 @@ public class DatabaseModule {
|
||||
return new H2Database(config, random, clock);
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
@Provides
|
||||
@Singleton
|
||||
DatabaseComponent provideDatabaseComponent(Database<Connection> db,
|
||||
EventBus eventBus, ShutdownManager shutdown) {
|
||||
return new DatabaseComponentImpl<Connection>(db, Connection.class,
|
||||
eventBus, shutdown);
|
||||
}
|
||||
|
||||
@Provides @Singleton @DatabaseExecutor
|
||||
ExecutorService provideDatabaseExecutorService(LifecycleManager lifecycleManager) {
|
||||
lifecycleManager.registerForShutdown(databaseExecutor);
|
||||
return databaseExecutor;
|
||||
}
|
||||
|
||||
@Provides @Singleton @DatabaseExecutor
|
||||
Executor provideDatabaseExecutor(@DatabaseExecutor ExecutorService dbExecutor) {
|
||||
return dbExecutor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user