mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Merge branch '427-local-author-caching' into 'master'
Cache the local author and load before the db latch is released Closes #427, #588 See merge request !354
This commit is contained in:
@@ -38,6 +38,16 @@ public class TestDatabaseConfig implements DatabaseConfig {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocalAuthorName(String nickname) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalAuthorName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxSize() {
|
||||
return maxSize;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TestLifecycleModule {
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartResult startServices() {
|
||||
public StartResult startServices(String nickname) {
|
||||
return StartResult.SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,6 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
@Test
|
||||
public void testCreateLocalState() throws DbException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final LocalAuthor localAuthor = (LocalAuthor) blog1.getAuthor();
|
||||
|
||||
final ContactId contactId = new ContactId(0);
|
||||
final Collection<ContactId> contactIds =
|
||||
@@ -105,7 +104,7 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).getLocalAuthor(txn);
|
||||
will(returnValue(localAuthor));
|
||||
will(returnValue(blog1.getAuthor()));
|
||||
oneOf(blogFactory).createBlog(blog1.getAuthor());
|
||||
will(returnValue(blog1));
|
||||
oneOf(db).containsGroup(txn, blog1.getId());
|
||||
@@ -151,42 +150,6 @@ public class BlogManagerImplTest extends BriarTestCase {
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddingIdentity() throws DbException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Author a = blog1.getAuthor();
|
||||
final LocalAuthor localAuthor =
|
||||
new LocalAuthor(a.getId(), a.getName(), a.getPublicKey(),
|
||||
a.getPublicKey(), 0);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).createBlog(localAuthor);
|
||||
will(returnValue(blog1));
|
||||
oneOf(db).addGroup(txn, blog1.getGroup());
|
||||
}});
|
||||
|
||||
blogManager.addingIdentity(txn, localAuthor);
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemovingIdentity() throws DbException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Author a = blog1.getAuthor();
|
||||
final LocalAuthor localAuthor =
|
||||
new LocalAuthor(a.getId(), a.getName(), a.getPublicKey(),
|
||||
a.getPublicKey(), 0);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(blogFactory).createBlog(localAuthor);
|
||||
will(returnValue(blog1));
|
||||
oneOf(db).removeGroup(txn, blog1.getGroup());
|
||||
}});
|
||||
|
||||
blogManager.removingIdentity(txn, localAuthor);
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncomingMessage() throws DbException, FormatException {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
|
||||
@@ -136,7 +136,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
// startTransaction()
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
// addLocalAuthor()
|
||||
// registerLocalAuthor()
|
||||
oneOf(database).containsLocalAuthor(txn, localAuthorId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).addLocalAuthor(txn, localAuthor);
|
||||
@@ -813,7 +813,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
// startTransaction()
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
// addLocalAuthor()
|
||||
// registerLocalAuthor()
|
||||
oneOf(database).containsLocalAuthor(txn, localAuthorId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).addLocalAuthor(txn, localAuthor);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class IdentityManagerImplTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetAuthorStatus() throws DbException {
|
||||
AuthorId authorId = new AuthorId(TestUtils.getRandomId());
|
||||
final AuthorId authorId = new AuthorId(TestUtils.getRandomId());
|
||||
final Collection<LocalAuthor> localAuthors = new ArrayList<>();
|
||||
LocalAuthor localAuthor =
|
||||
new LocalAuthor(new AuthorId(TestUtils.getRandomId()),
|
||||
@@ -54,9 +54,17 @@ public class IdentityManagerImplTest extends BriarTestCase {
|
||||
TestUtils.getRandomBytes(42),
|
||||
TestUtils.getRandomBytes(42), 0);
|
||||
localAuthors.add(localAuthor);
|
||||
Collection<Contact> contacts = new ArrayList<>();
|
||||
final Collection<Contact> contacts = new ArrayList<>();
|
||||
|
||||
checkAuthorStatusContext(localAuthors, authorId, contacts);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getLocalAuthors(txn);
|
||||
will(returnValue(localAuthors));
|
||||
oneOf(db).getContactsByAuthorId(txn, authorId);
|
||||
will(returnValue(contacts));
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
assertEquals(UNKNOWN, identityManager.getAuthorStatus(authorId));
|
||||
|
||||
// add one unverified contact
|
||||
@@ -67,7 +75,7 @@ public class IdentityManagerImplTest extends BriarTestCase {
|
||||
false, true);
|
||||
contacts.add(contact);
|
||||
|
||||
checkAuthorStatusContext(localAuthors, authorId, contacts);
|
||||
checkAuthorStatusContext(authorId, contacts);
|
||||
assertEquals(UNVERIFIED, identityManager.getAuthorStatus(authorId));
|
||||
|
||||
// add one verified contact
|
||||
@@ -76,37 +84,28 @@ public class IdentityManagerImplTest extends BriarTestCase {
|
||||
true, true);
|
||||
contacts.add(contact2);
|
||||
|
||||
checkAuthorStatusContext(localAuthors, authorId, contacts);
|
||||
checkAuthorStatusContext(authorId, contacts);
|
||||
assertEquals(VERIFIED, identityManager.getAuthorStatus(authorId));
|
||||
|
||||
// add ourselves to the local authors
|
||||
LocalAuthor localAuthor2 =
|
||||
new LocalAuthor(authorId,
|
||||
TestUtils.getRandomString(8),
|
||||
TestUtils.getRandomBytes(42),
|
||||
TestUtils.getRandomBytes(42), 0);
|
||||
localAuthors.add(localAuthor2);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getLocalAuthors(txn);
|
||||
will(returnValue(localAuthors));
|
||||
never(db).getLocalAuthors(txn);
|
||||
never(db).getContactsByAuthorId(txn, authorId);
|
||||
oneOf(db).endTransaction(txn);
|
||||
}});
|
||||
assertEquals(OURSELVES, identityManager.getAuthorStatus(authorId));
|
||||
assertEquals(OURSELVES,
|
||||
identityManager.getAuthorStatus(localAuthor.getId()));
|
||||
|
||||
context.assertIsSatisfied();
|
||||
}
|
||||
|
||||
private void checkAuthorStatusContext(
|
||||
final Collection<LocalAuthor> localAuthors, final AuthorId authorId,
|
||||
private void checkAuthorStatusContext(final AuthorId authorId,
|
||||
final Collection<Contact> contacts) throws DbException {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getLocalAuthors(txn);
|
||||
will(returnValue(localAuthors));
|
||||
never(db).getLocalAuthors(txn);
|
||||
oneOf(db).getContactsByAuthorId(txn, authorId);
|
||||
will(returnValue(contacts));
|
||||
oneOf(db).endTransaction(txn);
|
||||
|
||||
Reference in New Issue
Block a user