Merge branch 'db-code-cleanup' into 'master'

Clean up some database code

See merge request briar/briar!1071
This commit is contained in:
Torsten Grote
2019-04-05 14:38:54 +00:00
15 changed files with 14 additions and 115 deletions

View File

@@ -45,8 +45,7 @@ public abstract class DatabaseMigrationTest extends BrambleMockTestCase {
private final Migration<Connection> migration1 =
context.mock(Migration.class, "migration1");
protected final DatabaseConfig config =
new TestDatabaseConfig(testDir, 1024 * 1024);
protected final DatabaseConfig config = new TestDatabaseConfig(testDir);
protected final MessageFactory messageFactory = new TestMessageFactory();
protected final SecretKey key = getSecretKey();
protected final Clock clock = new SystemClock();

View File

@@ -76,8 +76,8 @@ public abstract class DatabasePerformanceComparisonTest
private Database<Connection> openDatabase(boolean conditionA)
throws DbException {
Database<Connection> db = createDatabase(conditionA,
new TestDatabaseConfig(testDir, MAX_SIZE),
new TestMessageFactory(), new SystemClock());
new TestDatabaseConfig(testDir), new TestMessageFactory(),
new SystemClock());
db.open(databaseKey, null);
return db;
}

View File

@@ -50,7 +50,6 @@ import static org.junit.Assert.assertTrue;
public abstract class DatabasePerformanceTest extends BrambleTestCase {
private static final int ONE_MEGABYTE = 1024 * 1024;
static final int MAX_SIZE = 100 * ONE_MEGABYTE;
/**
* How many contacts to simulate.

View File

@@ -48,8 +48,8 @@ public abstract class DatabaseTraceTest extends DatabasePerformanceTest {
private Database<Connection> openDatabase() throws DbException {
Database<Connection> db = createDatabase(
new TestDatabaseConfig(testDir, MAX_SIZE),
new TestMessageFactory(), new SystemClock());
new TestDatabaseConfig(testDir), new TestMessageFactory(),
new SystemClock());
db.open(databaseKey, null);
return db;
}

View File

@@ -57,7 +57,6 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_N
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
import static org.briarproject.bramble.api.sync.validation.MessageState.INVALID;
import static org.briarproject.bramble.api.sync.validation.MessageState.PENDING;
@@ -88,7 +87,6 @@ import static org.junit.Assert.fail;
public abstract class JdbcDatabaseTest extends BrambleTestCase {
private static final int ONE_MEGABYTE = 1024 * 1024;
private static final int MAX_SIZE = 5 * ONE_MEGABYTE;
// All our transports use a maximum latency of 30 seconds
private static final int MAX_LATENCY = 30 * 1000;
@@ -454,29 +452,6 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
db.close();
}
@Test
public void testGetFreeSpace() throws Exception {
Message message = getMessage(groupId, MAX_MESSAGE_BODY_LENGTH);
Database<Connection> db = open(false);
// Sanity check: there should be enough space on disk for this test
assertTrue(testDir.getFreeSpace() > MAX_SIZE);
// The free space should not be more than the allowed maximum size
long free = db.getFreeSpace();
assertTrue(free <= MAX_SIZE);
assertTrue(free > 0);
// Storing a message should reduce the free space
Connection txn = db.startTransaction();
db.addGroup(txn, group);
db.addMessage(txn, message, DELIVERED, true, null);
db.commitTransaction(txn);
assertTrue(db.getFreeSpace() < free);
db.close();
}
@Test
public void testCloseWaitsForCommit() throws Exception {
CountDownLatch closing = new CountDownLatch(1);
@@ -1996,9 +1971,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
private Database<Connection> open(boolean resume,
MessageFactory messageFactory, Clock clock) throws Exception {
Database<Connection> db =
createDatabase(new TestDatabaseConfig(testDir, MAX_SIZE),
messageFactory, clock);
Database<Connection> db = createDatabase(
new TestDatabaseConfig(testDir), messageFactory, clock);
if (!resume) deleteTestDirectory(testDir);
db.open(key, null);
return db;

View File

@@ -45,8 +45,8 @@ public abstract class SingleDatabasePerformanceTest
private Database<Connection> openDatabase() throws DbException {
Database<Connection> db = createDatabase(
new TestDatabaseConfig(testDir, MAX_SIZE),
new TestMessageFactory(), new SystemClock());
new TestDatabaseConfig(testDir), new TestMessageFactory(),
new SystemClock());
db.open(databaseKey, null);
return db;
}

View File

@@ -9,12 +9,10 @@ import java.io.File;
public class TestDatabaseConfig implements DatabaseConfig {
private final File dbDir, keyDir;
private final long maxSize;
public TestDatabaseConfig(File testDir, long maxSize) {
public TestDatabaseConfig(File testDir) {
dbDir = new File(testDir, "db");
keyDir = new File(testDir, "key");
this.maxSize = maxSize;
}
@Override
@@ -26,9 +24,4 @@ public class TestDatabaseConfig implements DatabaseConfig {
public File getDatabaseKeyDirectory() {
return keyDir;
}
@Override
public long getMaxSize() {
return maxSize;
}
}

View File

@@ -21,7 +21,7 @@ public class TestDatabaseModule {
}
public TestDatabaseModule(File dir) {
config = new TestDatabaseConfig(dir, Long.MAX_VALUE);
config = new TestDatabaseConfig(dir);
}
@Provides