mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Factor MessageTracker out of BdfIncomingMessageHook.
This commit is contained in:
@@ -9,6 +9,7 @@ import org.briarproject.api.blogs.BlogManager;
|
||||
import org.briarproject.api.blogs.BlogPostFactory;
|
||||
import org.briarproject.api.blogs.BlogSharingManager;
|
||||
import org.briarproject.api.clients.ContactGroupFactory;
|
||||
import org.briarproject.api.clients.MessageTracker;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
@@ -70,6 +71,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
||||
lifecycleManager2;
|
||||
private SyncSessionFactory sync0, sync1;
|
||||
private BlogManager blogManager0, blogManager1;
|
||||
private MessageTracker messageTracker0, messageTracker1;
|
||||
private ContactManager contactManager0, contactManager1, contactManager2;
|
||||
private Contact contact1, contact2, contact01, contact02;
|
||||
private ContactId contactId1, contactId01;
|
||||
@@ -142,6 +144,8 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
||||
contactManager2 = t2.getContactManager();
|
||||
blogManager0 = t0.getBlogManager();
|
||||
blogManager1 = t1.getBlogManager();
|
||||
messageTracker0 = t0.getMessageTracker();
|
||||
messageTracker1 = t1.getMessageTracker();
|
||||
blogSharingManager0 = t0.getBlogSharingManager();
|
||||
blogSharingManager1 = t1.getBlogSharingManager();
|
||||
blogSharingManager2 = t2.getBlogSharingManager();
|
||||
@@ -192,19 +196,19 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
||||
// get sharing group and assert group message count
|
||||
GroupId g = contactGroupFactory.createContactGroup(CLIENT_ID, contact1)
|
||||
.getId();
|
||||
assertGroupCount(blogSharingManager0, g, 1, 0);
|
||||
assertGroupCount(messageTracker0, g, 1, 0);
|
||||
|
||||
// sync first request message
|
||||
sync0To1();
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener1.requestReceived);
|
||||
assertGroupCount(blogSharingManager1, g, 2, 1);
|
||||
assertGroupCount(messageTracker1, g, 2, 1);
|
||||
|
||||
// sync response back
|
||||
sync1To0();
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.responseReceived);
|
||||
assertGroupCount(blogSharingManager0, g, 2, 1);
|
||||
assertGroupCount(messageTracker0, g, 2, 1);
|
||||
|
||||
// blog was added successfully
|
||||
assertEquals(0, blogSharingManager0.getInvitations().size());
|
||||
@@ -242,8 +246,8 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
|
||||
assertFalse(blogSharingManager1.canBeShared(blog2.getId(), contact01));
|
||||
|
||||
// group message count is still correct
|
||||
assertGroupCount(blogSharingManager0, g, 2, 1);
|
||||
assertGroupCount(blogSharingManager1, g, 2, 1);
|
||||
assertGroupCount(messageTracker0, g, 2, 1);
|
||||
assertGroupCount(messageTracker1, g, 2, 1);
|
||||
|
||||
stopLifecycles();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject;
|
||||
|
||||
import org.briarproject.api.blogs.BlogManager;
|
||||
import org.briarproject.api.blogs.BlogSharingManager;
|
||||
import org.briarproject.api.clients.MessageTracker;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
@@ -82,6 +83,8 @@ interface BlogSharingIntegrationTestComponent {
|
||||
|
||||
BlogManager getBlogManager();
|
||||
|
||||
MessageTracker getMessageTracker();
|
||||
|
||||
SyncSessionFactory getSyncSessionFactory();
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public abstract class BriarIntegrationTest extends BriarTestCase {
|
||||
|
||||
protected void assertGroupCount(MessageTracker tracker, GroupId g,
|
||||
protected static void assertGroupCount(MessageTracker tracker, GroupId g,
|
||||
long msgCount, long unreadCount, long latestMsg)
|
||||
throws DbException {
|
||||
|
||||
@@ -19,7 +19,7 @@ public abstract class BriarIntegrationTest extends BriarTestCase {
|
||||
assertEquals(latestMsg, groupCount.getLatestMsgTime());
|
||||
}
|
||||
|
||||
protected void assertGroupCount(MessageTracker tracker, GroupId g,
|
||||
protected static void assertGroupCount(MessageTracker tracker, GroupId g,
|
||||
long msgCount, long unreadCount) throws DbException {
|
||||
|
||||
GroupCount c1 = tracker.getGroupCount(g);
|
||||
|
||||
@@ -4,11 +4,11 @@ import junit.framework.Assert;
|
||||
|
||||
import net.jodah.concurrentunit.Waiter;
|
||||
|
||||
import org.briarproject.api.clients.MessageTracker;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.KeyPair;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.event.Event;
|
||||
@@ -66,6 +66,7 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
private SyncSessionFactory sync0, sync1;
|
||||
private ForumManager forumManager0, forumManager1;
|
||||
private ContactManager contactManager0, contactManager1;
|
||||
private MessageTracker messageTracker0, messageTracker1;
|
||||
private ContactId contactId0,contactId1;
|
||||
private IdentityManager identityManager0, identityManager1;
|
||||
private LocalAuthor author0, author1;
|
||||
@@ -118,6 +119,8 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
identityManager1 = t1.getIdentityManager();
|
||||
contactManager0 = t0.getContactManager();
|
||||
contactManager1 = t1.getContactManager();
|
||||
messageTracker0 = t0.getMessageTracker();
|
||||
messageTracker1 = t1.getMessageTracker();
|
||||
forumManager0 = t0.getForumManager();
|
||||
forumManager1 = t1.getForumManager();
|
||||
forumSharingManager0 = t0.getForumSharingManager();
|
||||
@@ -156,16 +159,16 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
forumManager0.addLocalPost(post1);
|
||||
forumManager0.setReadFlag(forum.getGroup().getId(),
|
||||
post1.getMessage().getId(), true);
|
||||
assertGroupCount(forumManager0, forum.getGroup().getId(), 1, 0,
|
||||
assertGroupCount(messageTracker0, forum.getGroup().getId(), 1, 0,
|
||||
post1.getMessage().getTimestamp());
|
||||
forumManager0.addLocalPost(post2);
|
||||
forumManager0.setReadFlag(forum.getGroup().getId(),
|
||||
post2.getMessage().getId(), false);
|
||||
assertGroupCount(forumManager0, forum.getGroup().getId(), 2, 1,
|
||||
assertGroupCount(messageTracker0, forum.getGroup().getId(), 2, 1,
|
||||
post2.getMessage().getTimestamp());
|
||||
forumManager0.setReadFlag(forum.getGroup().getId(),
|
||||
post2.getMessage().getId(), false);
|
||||
assertGroupCount(forumManager0, forum.getGroup().getId(), 2, 1,
|
||||
assertGroupCount(messageTracker0, forum.getGroup().getId(), 2, 1,
|
||||
post2.getMessage().getTimestamp());
|
||||
Collection<ForumPostHeader> headers =
|
||||
forumManager0.getPostHeaders(forum.getGroup().getId());
|
||||
@@ -215,14 +218,14 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
forumManager0.addLocalPost(post1);
|
||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
||||
assertEquals(0, forumManager1.getPostHeaders(g).size());
|
||||
assertGroupCount(forumManager0, g, 1, 0, time);
|
||||
assertGroupCount(forumManager1, g, 0, 0, 0);
|
||||
assertGroupCount(messageTracker0, g, 1, 0, time);
|
||||
assertGroupCount(messageTracker1, g, 0, 0, 0);
|
||||
|
||||
// send post to 1
|
||||
sync0To1();
|
||||
deliveryWaiter.await(TIMEOUT, 1);
|
||||
assertEquals(1, forumManager1.getPostHeaders(g).size());
|
||||
assertGroupCount(forumManager1, g, 1, 1, time);
|
||||
assertGroupCount(messageTracker1, g, 1, 1, time);
|
||||
|
||||
// add another forum post
|
||||
long time2 = clock.currentTimeMillis();
|
||||
@@ -230,14 +233,14 @@ public class ForumManagerTest extends BriarIntegrationTest {
|
||||
forumManager1.addLocalPost(post2);
|
||||
assertEquals(1, forumManager0.getPostHeaders(g).size());
|
||||
assertEquals(2, forumManager1.getPostHeaders(g).size());
|
||||
assertGroupCount(forumManager0, g, 1, 0, time);
|
||||
assertGroupCount(forumManager1, g, 2, 1, time2);
|
||||
assertGroupCount(messageTracker0, g, 1, 0, time);
|
||||
assertGroupCount(messageTracker1, g, 2, 1, time2);
|
||||
|
||||
// send post to 0
|
||||
sync1To0();
|
||||
deliveryWaiter.await(TIMEOUT, 1);
|
||||
assertEquals(2, forumManager1.getPostHeaders(g).size());
|
||||
assertGroupCount(forumManager0, g, 2, 1, time2);
|
||||
assertGroupCount(messageTracker0, g, 2, 1, time2);
|
||||
|
||||
stopLifecycles();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject;
|
||||
|
||||
import org.briarproject.api.clients.MessageTracker;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.forum.ForumManager;
|
||||
@@ -78,6 +79,8 @@ interface ForumManagerTestComponent {
|
||||
|
||||
ContactManager getContactManager();
|
||||
|
||||
MessageTracker getMessageTracker();
|
||||
|
||||
ForumSharingManager getForumSharingManager();
|
||||
|
||||
ForumManager getForumManager();
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.briarproject.TestDatabaseModule;
|
||||
import org.briarproject.TestUtils;
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.clients.ClientHelper;
|
||||
import org.briarproject.api.clients.MessageTracker;
|
||||
import org.briarproject.api.clients.SessionId;
|
||||
import org.briarproject.api.contact.Contact;
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
@@ -105,6 +106,7 @@ public class IntroductionIntegrationTest extends BriarIntegrationTest {
|
||||
lifecycleManager2;
|
||||
private SyncSessionFactory sync0, sync1, sync2;
|
||||
private ContactManager contactManager0, contactManager1, contactManager2;
|
||||
private MessageTracker messageTracker0, messageTracker1, messageTracker2;
|
||||
private ContactId contactId0, contactId1, contactId2;
|
||||
private IdentityManager identityManager0, identityManager1,
|
||||
identityManager2;
|
||||
@@ -172,6 +174,9 @@ public class IntroductionIntegrationTest extends BriarIntegrationTest {
|
||||
contactManager0 = t0.getContactManager();
|
||||
contactManager1 = t1.getContactManager();
|
||||
contactManager2 = t2.getContactManager();
|
||||
messageTracker0 = t0.getMessageTracker();
|
||||
messageTracker1 = t1.getMessageTracker();
|
||||
messageTracker2 = t2.getMessageTracker();
|
||||
introductionManager0 = t0.getIntroductionManager();
|
||||
introductionManager1 = t1.getIntroductionManager();
|
||||
introductionManager2 = t2.getIntroductionManager();
|
||||
@@ -205,38 +210,38 @@ public class IntroductionIntegrationTest extends BriarIntegrationTest {
|
||||
.createIntroductionGroup(introducee1);
|
||||
Group g2 = introductionGroupFactory
|
||||
.createIntroductionGroup(introducee2);
|
||||
assertGroupCount(introductionManager0, g1.getId(), 1, 0, time);
|
||||
assertGroupCount(introductionManager0, g2.getId(), 1, 0, time);
|
||||
assertGroupCount(messageTracker0, g1.getId(), 1, 0, time);
|
||||
assertGroupCount(messageTracker0, g2.getId(), 1, 0, time);
|
||||
|
||||
// sync first request message
|
||||
deliverMessage(sync0, contactId0, sync1, contactId1, "0 to 1");
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener1.requestReceived);
|
||||
assertGroupCount(introductionManager1, g1.getId(), 2, 1);
|
||||
assertGroupCount(messageTracker1, g1.getId(), 2, 1);
|
||||
|
||||
// sync second request message
|
||||
deliverMessage(sync0, contactId0, sync2, contactId2, "0 to 2");
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener2.requestReceived);
|
||||
assertGroupCount(introductionManager2, g2.getId(), 2, 1);
|
||||
assertGroupCount(messageTracker2, g2.getId(), 2, 1);
|
||||
|
||||
// sync first response
|
||||
deliverMessage(sync1, contactId1, sync0, contactId0, "1 to 0");
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.response1Received);
|
||||
assertGroupCount(introductionManager0, g1.getId(), 2, 1);
|
||||
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
|
||||
|
||||
// sync second response
|
||||
deliverMessage(sync2, contactId2, sync0, contactId0, "2 to 0");
|
||||
eventWaiter.await(TIMEOUT, 1);
|
||||
assertTrue(listener0.response2Received);
|
||||
assertGroupCount(introductionManager0, g2.getId(), 2, 1);
|
||||
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
|
||||
|
||||
// sync forwarded responses to introducees
|
||||
deliverMessage(sync0, contactId0, sync1, contactId1, "0 to 1");
|
||||
deliverMessage(sync0, contactId0, sync2, contactId2, "0 to 2");
|
||||
assertGroupCount(introductionManager1, g1.getId(), 3, 2);
|
||||
assertGroupCount(introductionManager2, g2.getId(), 3, 2);
|
||||
assertGroupCount(messageTracker1, g1.getId(), 3, 2);
|
||||
assertGroupCount(messageTracker2, g2.getId(), 3, 2);
|
||||
|
||||
// sync first ACK and its forward
|
||||
deliverMessage(sync1, contactId1, sync0, contactId0, "1 to 0");
|
||||
@@ -269,10 +274,10 @@ public class IntroductionIntegrationTest extends BriarIntegrationTest {
|
||||
}
|
||||
|
||||
assertDefaultUiMessages();
|
||||
assertGroupCount(introductionManager0, g1.getId(), 2, 1);
|
||||
assertGroupCount(introductionManager0, g2.getId(), 2, 1);
|
||||
assertGroupCount(introductionManager1, g1.getId(), 3, 2);
|
||||
assertGroupCount(introductionManager2, g2.getId(), 3, 2);
|
||||
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
|
||||
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
|
||||
assertGroupCount(messageTracker1, g1.getId(), 3, 2);
|
||||
assertGroupCount(messageTracker2, g2.getId(), 3, 2);
|
||||
} finally {
|
||||
stopLifecycles();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.briarproject.TestDatabaseModule;
|
||||
import org.briarproject.TestPluginsModule;
|
||||
import org.briarproject.TestSeedProviderModule;
|
||||
import org.briarproject.api.clients.ClientHelper;
|
||||
import org.briarproject.api.clients.MessageTracker;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
@@ -50,7 +51,7 @@ import dagger.Component;
|
||||
PropertiesModule.class,
|
||||
MessagingModule.class
|
||||
})
|
||||
public interface IntroductionIntegrationTestComponent {
|
||||
interface IntroductionIntegrationTestComponent {
|
||||
|
||||
void inject(IntroductionIntegrationTest testCase);
|
||||
|
||||
@@ -82,6 +83,8 @@ public interface IntroductionIntegrationTestComponent {
|
||||
|
||||
TransportPropertyManager getTransportPropertyManager();
|
||||
|
||||
MessageTracker getMessageTracker();
|
||||
|
||||
SyncSessionFactory getSyncSessionFactory();
|
||||
|
||||
/* the following methods are only needed to manually construct messages */
|
||||
|
||||
Reference in New Issue
Block a user