Create an identity at startup if the database doesn't exist.

This commit is contained in:
akwizgran
2013-04-08 16:01:52 +01:00
parent ce7e9e73c9
commit de472ba2a6
47 changed files with 934 additions and 419 deletions

View File

@@ -14,7 +14,11 @@ public class TestDatabaseConfig implements DatabaseConfig {
this.maxSize = maxSize;
}
public File getDataDirectory() {
public boolean databaseExists() {
return dir.isDirectory() && dir.listFiles().length > 0;
}
public File getDatabaseDirectory() {
return dir;
}

View File

@@ -125,8 +125,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
exactly(13).of(database).startTransaction();
will(returnValue(txn));
exactly(13).of(database).commitTransaction(txn);
// open(false)
oneOf(database).open(false);
// open()
oneOf(database).open();
will(returnValue(false));
oneOf(cleaner).startCleaning(
with(any(DatabaseCleaner.Callback.class)),
with(any(long.class)));
@@ -199,7 +200,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
DatabaseComponent db = createDatabaseComponent(database, cleaner,
shutdown);
db.open(false);
assertFalse(db.open());
db.addListener(listener);
assertEquals(UNRATED, db.getRating(authorId));
db.setRating(authorId, GOOD); // First time - listeners called

View File

@@ -1832,7 +1832,8 @@ public class H2DatabaseTest extends BriarTestCase {
private Database<Connection> open(boolean resume) throws Exception {
Database<Connection> db = new H2Database(new TestDatabaseConfig(testDir,
MAX_SIZE), new SystemClock());
db.open(resume);
if(!resume) TestUtils.deleteTestDirectory(testDir);
db.open();
return db;
}

View File

@@ -102,7 +102,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
private byte[] write() throws Exception {
// Open Alice's database
DatabaseComponent db = alice.getInstance(DatabaseComponent.class);
db.open(false);
assertFalse(db.open());
// Start Alice's key manager
KeyManager km = alice.getInstance(KeyManager.class);
km.start();
@@ -156,7 +156,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
private void read(byte[] b) throws Exception {
// Open Bob's database
DatabaseComponent db = bob.getInstance(DatabaseComponent.class);
db.open(false);
assertFalse(db.open());
// Start Bob's key manager
KeyManager km = bob.getInstance(KeyManager.class);
km.start();