mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Merge branch 'briar-integration-test-transaction' into 'master'
Remove custom DB transaction code from BriarIntegrationTest See merge request briar/briar!946
This commit is contained in:
@@ -62,7 +62,7 @@ public class BlogManagerIntegrationTest
|
|||||||
blog1 = blogFactory.createBlog(author1);
|
blog1 = blogFactory.createBlog(author1);
|
||||||
|
|
||||||
rssBlog = blogFactory.createFeedBlog(rssAuthor);
|
rssBlog = blogFactory.createFeedBlog(rssAuthor);
|
||||||
withinTransaction(db0, txn -> blogManager0.addBlog(txn, rssBlog));
|
db0.transaction(false, txn -> blogManager0.addBlog(txn, rssBlog));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -330,7 +330,7 @@ public class BlogManagerIntegrationTest
|
|||||||
cHeader = h;
|
cHeader = h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(cHeader != null);
|
assertNotNull(cHeader);
|
||||||
|
|
||||||
// another comment on the comment
|
// another comment on the comment
|
||||||
String comment2 = "This is a comment on a comment.";
|
String comment2 = "This is a comment on a comment.";
|
||||||
|
|||||||
@@ -298,20 +298,20 @@ public class IntroductionIntegrationTest
|
|||||||
Group g1 = introductionManager0.getContactGroup(introducee1);
|
Group g1 = introductionManager0.getContactGroup(introducee1);
|
||||||
Group g2 = introductionManager0.getContactGroup(introducee2);
|
Group g2 = introductionManager0.getContactGroup(introducee2);
|
||||||
Collection<PrivateMessageHeader> messages =
|
Collection<PrivateMessageHeader> messages =
|
||||||
withinTransactionReturns(db0, txn -> introductionManager0
|
db0.transactionWithResult(true, txn -> introductionManager0
|
||||||
.getMessageHeaders(txn, contactId1From0));
|
.getMessageHeaders(txn, contactId1From0));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
|
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
|
||||||
messages = withinTransactionReturns(db0,
|
messages = db0.transactionWithResult(true,
|
||||||
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0));
|
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
|
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
|
||||||
messages = withinTransactionReturns(db1,
|
messages = db1.transactionWithResult(true,
|
||||||
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1));
|
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
assertGroupCount(messageTracker1, g1.getId(), 2, 1);
|
assertGroupCount(messageTracker1, g1.getId(), 2, 1);
|
||||||
// introducee2 should also have the decline response of introducee1
|
// introducee2 should also have the decline response of introducee1
|
||||||
messages = withinTransactionReturns(db2,
|
messages = db2.transactionWithResult(true,
|
||||||
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2));
|
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2));
|
||||||
assertEquals(3, messages.size());
|
assertEquals(3, messages.size());
|
||||||
assertGroupCount(messageTracker2, g2.getId(), 3, 2);
|
assertGroupCount(messageTracker2, g2.getId(), 3, 2);
|
||||||
@@ -364,18 +364,18 @@ public class IntroductionIntegrationTest
|
|||||||
.contactExists(author1.getId(), author2.getId()));
|
.contactExists(author1.getId(), author2.getId()));
|
||||||
|
|
||||||
Collection<PrivateMessageHeader> messages =
|
Collection<PrivateMessageHeader> messages =
|
||||||
withinTransactionReturns(db0, txn -> introductionManager0
|
db0.transactionWithResult(true, txn -> introductionManager0
|
||||||
.getMessageHeaders(txn, contactId1From0));
|
.getMessageHeaders(txn, contactId1From0));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
messages = withinTransactionReturns(db0,
|
messages = db0.transactionWithResult(true,
|
||||||
txn -> introductionManager0
|
txn -> introductionManager0
|
||||||
.getMessageHeaders(txn, contactId2From0));
|
.getMessageHeaders(txn, contactId2From0));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
messages = withinTransactionReturns(db1,
|
messages = db1.transactionWithResult(true,
|
||||||
txn -> introductionManager1
|
txn -> introductionManager1
|
||||||
.getMessageHeaders(txn, contactId0From1));
|
.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(3, messages.size());
|
assertEquals(3, messages.size());
|
||||||
messages = withinTransactionReturns(db2,
|
messages = db2.transactionWithResult(true,
|
||||||
txn -> introductionManager2
|
txn -> introductionManager2
|
||||||
.getMessageHeaders(txn, contactId0From2));
|
.getMessageHeaders(txn, contactId0From2));
|
||||||
assertEquals(3, messages.size());
|
assertEquals(3, messages.size());
|
||||||
@@ -524,19 +524,19 @@ public class IntroductionIntegrationTest
|
|||||||
|
|
||||||
Group g1 = introductionManager0.getContactGroup(introducee1);
|
Group g1 = introductionManager0.getContactGroup(introducee1);
|
||||||
Group g2 = introductionManager0.getContactGroup(introducee2);
|
Group g2 = introductionManager0.getContactGroup(introducee2);
|
||||||
assertEquals(2, withinTransactionReturns(db0,
|
assertEquals(2, db0.transactionWithResult(true,
|
||||||
txn -> introductionManager0.getMessageHeaders(txn, contactId1From0))
|
txn -> introductionManager0.getMessageHeaders(txn, contactId1From0))
|
||||||
.size());
|
.size());
|
||||||
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
|
assertGroupCount(messageTracker0, g1.getId(), 2, 1);
|
||||||
assertEquals(2, withinTransactionReturns(db0,
|
assertEquals(2, db0.transactionWithResult(true,
|
||||||
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0))
|
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0))
|
||||||
.size());
|
.size());
|
||||||
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
|
assertGroupCount(messageTracker0, g2.getId(), 2, 1);
|
||||||
assertEquals(3, withinTransactionReturns(db1,
|
assertEquals(3, db1.transactionWithResult(true,
|
||||||
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1))
|
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1))
|
||||||
.size());
|
.size());
|
||||||
assertGroupCount(messageTracker1, g1.getId(), 3, 2);
|
assertGroupCount(messageTracker1, g1.getId(), 3, 2);
|
||||||
assertEquals(3, withinTransactionReturns(db2,
|
assertEquals(3, db2.transactionWithResult(true,
|
||||||
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2))
|
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2))
|
||||||
.size());
|
.size());
|
||||||
assertGroupCount(messageTracker2, g2.getId(), 3, 2);
|
assertGroupCount(messageTracker2, g2.getId(), 3, 2);
|
||||||
@@ -562,7 +562,7 @@ public class IntroductionIntegrationTest
|
|||||||
assertFalse(listener1.requestReceived);
|
assertFalse(listener1.requestReceived);
|
||||||
|
|
||||||
// make really sure we don't have that request
|
// make really sure we don't have that request
|
||||||
assertTrue(withinTransactionReturns(db1,
|
assertTrue(db1.transactionWithResult(true,
|
||||||
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1))
|
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1))
|
||||||
.isEmpty());
|
.isEmpty());
|
||||||
|
|
||||||
@@ -997,7 +997,7 @@ public class IntroductionIntegrationTest
|
|||||||
AcceptMessage m = visitor.visit(message);
|
AcceptMessage m = visitor.visit(message);
|
||||||
|
|
||||||
// replace original response with modified one
|
// replace original response with modified one
|
||||||
withinTransaction(db0, txn -> {
|
db0.transaction(false, txn -> {
|
||||||
db0.removeMessage(txn, message.getMessageId());
|
db0.removeMessage(txn, message.getMessageId());
|
||||||
Message msg = c0.getMessageEncoder()
|
Message msg = c0.getMessageEncoder()
|
||||||
.encodeAcceptMessage(m.getGroupId(), m.getTimestamp(),
|
.encodeAcceptMessage(m.getGroupId(), m.getTimestamp(),
|
||||||
@@ -1103,22 +1103,22 @@ public class IntroductionIntegrationTest
|
|||||||
|
|
||||||
private void assertDefaultUiMessages() throws DbException {
|
private void assertDefaultUiMessages() throws DbException {
|
||||||
Collection<PrivateMessageHeader> messages =
|
Collection<PrivateMessageHeader> messages =
|
||||||
withinTransactionReturns(db0, txn -> introductionManager0
|
db0.transactionWithResult(true, txn -> introductionManager0
|
||||||
.getMessageHeaders(txn, contactId1From0));
|
.getMessageHeaders(txn, contactId1From0));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
assertMessagesAreAcked(messages);
|
assertMessagesAreAcked(messages);
|
||||||
|
|
||||||
messages = withinTransactionReturns(db0,
|
messages = db0.transactionWithResult(true,
|
||||||
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0));
|
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
assertMessagesAreAcked(messages);
|
assertMessagesAreAcked(messages);
|
||||||
|
|
||||||
messages = withinTransactionReturns(db1,
|
messages = db1.transactionWithResult(true,
|
||||||
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1));
|
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
assertMessagesAreAcked(messages);
|
assertMessagesAreAcked(messages);
|
||||||
|
|
||||||
messages = withinTransactionReturns(db2,
|
messages = db2.transactionWithResult(true,
|
||||||
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2));
|
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
assertMessagesAreAcked(messages);
|
assertMessagesAreAcked(messages);
|
||||||
@@ -1302,8 +1302,8 @@ public class IntroductionIntegrationTest
|
|||||||
private IntroductionRequest getIntroductionRequest(DatabaseComponent db,
|
private IntroductionRequest getIntroductionRequest(DatabaseComponent db,
|
||||||
IntroductionManager manager, ContactId contactId)
|
IntroductionManager manager, ContactId contactId)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
Collection<PrivateMessageHeader> messages = withinTransactionReturns(db,
|
Collection<PrivateMessageHeader> messages = db.transactionWithResult(
|
||||||
txn -> manager.getMessageHeaders(txn, contactId));
|
true, txn -> manager.getMessageHeaders(txn, contactId));
|
||||||
for (PrivateMessageHeader im : messages) {
|
for (PrivateMessageHeader im : messages) {
|
||||||
if (im instanceof IntroductionRequest) {
|
if (im instanceof IntroductionRequest) {
|
||||||
return (IntroductionRequest) im;
|
return (IntroductionRequest) im;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import static org.briarproject.briar.api.privategroup.Visibility.VISIBLE;
|
|||||||
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
|
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class PrivateGroupManagerIntegrationTest
|
public class PrivateGroupManagerIntegrationTest
|
||||||
@@ -102,7 +103,7 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
header = h;
|
header = h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(header != null);
|
assertNotNull(header);
|
||||||
assertFalse(header.isRead());
|
assertFalse(header.isRead());
|
||||||
assertEquals(author0, header.getAuthor());
|
assertEquals(author0, header.getAuthor());
|
||||||
assertEquals(time, header.getTimestamp());
|
assertEquals(time, header.getTimestamp());
|
||||||
@@ -244,7 +245,7 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
groupManager0.getPreviousMsgId(groupId0));
|
groupManager0.getPreviousMsgId(groupId0));
|
||||||
|
|
||||||
// share the group with 1
|
// share the group with 1
|
||||||
withinTransaction(db0, txn -> db0.setGroupVisibility(txn,
|
db0.transaction(false, txn -> db0.setGroupVisibility(txn,
|
||||||
contactId1From0, privateGroup0.getId(), SHARED));
|
contactId1From0, privateGroup0.getId(), SHARED));
|
||||||
|
|
||||||
// author1 joins privateGroup0 with wrong timestamp
|
// author1 joins privateGroup0 with wrong timestamp
|
||||||
@@ -262,7 +263,7 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
groupManager1.getPreviousMsgId(groupId0));
|
groupManager1.getPreviousMsgId(groupId0));
|
||||||
|
|
||||||
// share the group with 0
|
// share the group with 0
|
||||||
withinTransaction(db1, txn -> db1.setGroupVisibility(txn,
|
db1.transaction(false, txn -> db1.setGroupVisibility(txn,
|
||||||
contactId0From1, privateGroup0.getId(), SHARED));
|
contactId0From1, privateGroup0.getId(), SHARED));
|
||||||
|
|
||||||
// sync join messages
|
// sync join messages
|
||||||
@@ -296,7 +297,7 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
groupManager0.getPreviousMsgId(groupId0));
|
groupManager0.getPreviousMsgId(groupId0));
|
||||||
|
|
||||||
// share the group with 1
|
// share the group with 1
|
||||||
withinTransaction(db0, txn -> db0.setGroupVisibility(txn,
|
db0.transaction(false, txn -> db0.setGroupVisibility(txn,
|
||||||
contactId1From0, privateGroup0.getId(), SHARED));
|
contactId1From0, privateGroup0.getId(), SHARED));
|
||||||
|
|
||||||
// author1 joins privateGroup0 with wrong signature in join message
|
// author1 joins privateGroup0 with wrong signature in join message
|
||||||
@@ -315,7 +316,7 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
groupManager1.getPreviousMsgId(groupId0));
|
groupManager1.getPreviousMsgId(groupId0));
|
||||||
|
|
||||||
// share the group with 0
|
// share the group with 0
|
||||||
withinTransaction(db1, txn -> db1.setGroupVisibility(txn,
|
db1.transaction(false, txn -> db1.setGroupVisibility(txn,
|
||||||
contactId0From1, privateGroup0.getId(), SHARED));
|
contactId0From1, privateGroup0.getId(), SHARED));
|
||||||
|
|
||||||
// sync join messages
|
// sync join messages
|
||||||
@@ -391,7 +392,7 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
addGroup();
|
addGroup();
|
||||||
|
|
||||||
// share the group with 2
|
// share the group with 2
|
||||||
withinTransaction(db0, txn -> db0.setGroupVisibility(txn,
|
db0.transaction(false, txn -> db0.setGroupVisibility(txn,
|
||||||
contactId2From0, privateGroup0.getId(), SHARED));
|
contactId2From0, privateGroup0.getId(), SHARED));
|
||||||
|
|
||||||
// author2 joins privateGroup0
|
// author2 joins privateGroup0
|
||||||
@@ -404,7 +405,7 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
GroupMessage joinMsg2 = groupMessageFactory
|
GroupMessage joinMsg2 = groupMessageFactory
|
||||||
.createJoinMessage(privateGroup0.getId(), joinTime, author2,
|
.createJoinMessage(privateGroup0.getId(), joinTime, author2,
|
||||||
inviteTime, creatorSignature);
|
inviteTime, creatorSignature);
|
||||||
withinTransaction(db2, txn -> {
|
db2.transaction(false, txn -> {
|
||||||
groupManager2.addPrivateGroup(txn, privateGroup0, joinMsg2, false);
|
groupManager2.addPrivateGroup(txn, privateGroup0, joinMsg2, false);
|
||||||
// share the group with 0
|
// share the group with 0
|
||||||
db2.setGroupVisibility(txn,
|
db2.setGroupVisibility(txn,
|
||||||
@@ -440,9 +441,9 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// reveal contact relationship
|
// reveal contact relationship
|
||||||
withinTransaction(db1, txn -> groupManager1.relationshipRevealed(txn,
|
db1.transaction(false, txn -> groupManager1.relationshipRevealed(txn,
|
||||||
groupId0, author2.getId(), false));
|
groupId0, author2.getId(), false));
|
||||||
withinTransaction(db2, txn -> groupManager2.relationshipRevealed(txn,
|
db2.transaction(false, txn -> groupManager2.relationshipRevealed(txn,
|
||||||
groupId0, author1.getId(), true));
|
groupId0, author1.getId(), true));
|
||||||
|
|
||||||
// assert that contact relationship is now revealed properly
|
// assert that contact relationship is now revealed properly
|
||||||
@@ -496,7 +497,7 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
assertFalse(groupManager1.isDissolved(groupId0));
|
assertFalse(groupManager1.isDissolved(groupId0));
|
||||||
|
|
||||||
// creator dissolves group
|
// creator dissolves group
|
||||||
withinTransaction(db1,
|
db1.transaction(false,
|
||||||
txn -> groupManager1.markGroupDissolved(txn, groupId0));
|
txn -> groupManager1.markGroupDissolved(txn, groupId0));
|
||||||
|
|
||||||
// group is dissolved now
|
// group is dissolved now
|
||||||
@@ -513,7 +514,7 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
groupManager0.getPreviousMsgId(groupId0));
|
groupManager0.getPreviousMsgId(groupId0));
|
||||||
|
|
||||||
// share the group with 1
|
// share the group with 1
|
||||||
withinTransaction(db0, txn -> db0.setGroupVisibility(txn,
|
db0.transaction(false, txn -> db0.setGroupVisibility(txn,
|
||||||
contactId1From0, privateGroup0.getId(), SHARED));
|
contactId1From0, privateGroup0.getId(), SHARED));
|
||||||
|
|
||||||
// author1 joins privateGroup0
|
// author1 joins privateGroup0
|
||||||
@@ -529,7 +530,7 @@ public class PrivateGroupManagerIntegrationTest
|
|||||||
groupManager1.addPrivateGroup(privateGroup0, joinMsg1, false);
|
groupManager1.addPrivateGroup(privateGroup0, joinMsg1, false);
|
||||||
|
|
||||||
// share the group with 0
|
// share the group with 0
|
||||||
withinTransaction(db1, txn -> db1.setGroupVisibility(txn,
|
db1.transaction(false, txn -> db1.setGroupVisibility(txn,
|
||||||
contactId0From1, privateGroup0.getId(), SHARED));
|
contactId0From1, privateGroup0.getId(), SHARED));
|
||||||
assertEquals(joinMsg1.getMessage().getId(),
|
assertEquals(joinMsg1.getMessage().getId(),
|
||||||
groupManager1.getPreviousMsgId(groupId0));
|
groupManager1.getPreviousMsgId(groupId0));
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class GroupInvitationIntegrationTest
|
|||||||
assertFalse(item.isSubscribed());
|
assertFalse(item.isSubscribed());
|
||||||
|
|
||||||
Collection<PrivateMessageHeader> messages =
|
Collection<PrivateMessageHeader> messages =
|
||||||
withinTransactionReturns(db1, txn -> groupInvitationManager1
|
db1.transactionWithResult(true, txn -> groupInvitationManager1
|
||||||
.getMessageHeaders(txn, contactId0From1));
|
.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(1, messages.size());
|
assertEquals(1, messages.size());
|
||||||
GroupInvitationRequest request =
|
GroupInvitationRequest request =
|
||||||
@@ -119,7 +119,7 @@ public class GroupInvitationIntegrationTest
|
|||||||
.respondToInvitation(contactId0From1, privateGroup0, false);
|
.respondToInvitation(contactId0From1, privateGroup0, false);
|
||||||
|
|
||||||
Collection<PrivateMessageHeader> messages =
|
Collection<PrivateMessageHeader> messages =
|
||||||
withinTransactionReturns(db1, txn -> groupInvitationManager1
|
db1.transactionWithResult(true, txn -> groupInvitationManager1
|
||||||
.getMessageHeaders(txn, contactId0From1));
|
.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
boolean foundResponse = false;
|
boolean foundResponse = false;
|
||||||
@@ -136,7 +136,7 @@ public class GroupInvitationIntegrationTest
|
|||||||
|
|
||||||
sync1To0(1, true);
|
sync1To0(1, true);
|
||||||
|
|
||||||
messages = withinTransactionReturns(db0, txn -> groupInvitationManager0
|
messages = db0.transactionWithResult(true, txn -> groupInvitationManager0
|
||||||
.getMessageHeaders(txn, contactId1From0));
|
.getMessageHeaders(txn, contactId1From0));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
foundResponse = false;
|
foundResponse = false;
|
||||||
@@ -169,7 +169,7 @@ public class GroupInvitationIntegrationTest
|
|||||||
.respondToInvitation(contactId0From1, privateGroup0, true);
|
.respondToInvitation(contactId0From1, privateGroup0, true);
|
||||||
|
|
||||||
Collection<PrivateMessageHeader> messages =
|
Collection<PrivateMessageHeader> messages =
|
||||||
withinTransactionReturns(db1, txn -> groupInvitationManager1
|
db1.transactionWithResult(true, txn -> groupInvitationManager1
|
||||||
.getMessageHeaders(txn, contactId0From1));
|
.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
boolean foundResponse = false;
|
boolean foundResponse = false;
|
||||||
@@ -190,7 +190,7 @@ public class GroupInvitationIntegrationTest
|
|||||||
|
|
||||||
sync1To0(1, true);
|
sync1To0(1, true);
|
||||||
|
|
||||||
messages = withinTransactionReturns(db1, txn -> groupInvitationManager0
|
messages = db1.transactionWithResult(true, txn -> groupInvitationManager0
|
||||||
.getMessageHeaders(txn, contactId1From0));
|
.getMessageHeaders(txn, contactId1From0));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
foundResponse = false;
|
foundResponse = false;
|
||||||
@@ -226,7 +226,7 @@ public class GroupInvitationIntegrationTest
|
|||||||
// 1 has one unread message
|
// 1 has one unread message
|
||||||
Group g0 = groupInvitationManager1.getContactGroup(contact0From1);
|
Group g0 = groupInvitationManager1.getContactGroup(contact0From1);
|
||||||
assertGroupCount(messageTracker1, g0.getId(), 1, 1, timestamp);
|
assertGroupCount(messageTracker1, g0.getId(), 1, 1, timestamp);
|
||||||
PrivateMessageHeader m = withinTransactionReturns(db1,
|
PrivateMessageHeader m = db1.transactionWithResult(true,
|
||||||
txn -> groupInvitationManager1.getMessageHeaders(txn, contactId0From1)
|
txn -> groupInvitationManager1.getMessageHeaders(txn, contactId0From1)
|
||||||
.iterator().next());
|
.iterator().next());
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@@ -145,8 +146,9 @@ public class BlogSharingIntegrationTest
|
|||||||
assertTrue(blogManager1.getBlogs().contains(blog2));
|
assertTrue(blogManager1.getBlogs().contains(blog2));
|
||||||
|
|
||||||
// invitee has one invitation message from sharer
|
// invitee has one invitation message from sharer
|
||||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
Collection<PrivateMessageHeader> list = db1.transactionWithResult(true,
|
||||||
txn -> blogSharingManager1.getMessageHeaders(txn, contactId0From1));
|
txn -> blogSharingManager1
|
||||||
|
.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
// check other things are alright with the message
|
// check other things are alright with the message
|
||||||
for (PrivateMessageHeader m : list) {
|
for (PrivateMessageHeader m : list) {
|
||||||
@@ -166,8 +168,8 @@ public class BlogSharingIntegrationTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sharer has own invitation message and response
|
// sharer has own invitation message and response
|
||||||
assertEquals(2, withinTransactionReturns(db0,
|
assertEquals(2, db0.transactionWithResult(true, txn ->
|
||||||
txn -> blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
||||||
.size());
|
.size());
|
||||||
// blog can not be shared again
|
// blog can not be shared again
|
||||||
assertFalse(blogSharingManager0.canBeShared(blog2.getId(),
|
assertFalse(blogSharingManager0.canBeShared(blog2.getId(),
|
||||||
@@ -218,7 +220,7 @@ public class BlogSharingIntegrationTest
|
|||||||
assertTrue(blogManager1.getBlogs().contains(rssBlog));
|
assertTrue(blogManager1.getBlogs().contains(rssBlog));
|
||||||
|
|
||||||
// invitee has one invitation message from sharer
|
// invitee has one invitation message from sharer
|
||||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
Collection<PrivateMessageHeader> list = db1.transactionWithResult(true,
|
||||||
txn -> blogSharingManager1.getMessageHeaders(txn, contactId0From1));
|
txn -> blogSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
// check other things are alright with the message
|
// check other things are alright with the message
|
||||||
@@ -239,7 +241,7 @@ public class BlogSharingIntegrationTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sharer has own invitation message and response
|
// sharer has own invitation message and response
|
||||||
assertEquals(2, withinTransactionReturns(db0,
|
assertEquals(2, db0.transactionWithResult(true,
|
||||||
txn -> blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
txn -> blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
||||||
.size());
|
.size());
|
||||||
// blog can not be shared again
|
// blog can not be shared again
|
||||||
@@ -280,7 +282,7 @@ public class BlogSharingIntegrationTest
|
|||||||
assertEquals(0, blogSharingManager1.getInvitations().size());
|
assertEquals(0, blogSharingManager1.getInvitations().size());
|
||||||
|
|
||||||
// invitee has one invitation message from sharer and one response
|
// invitee has one invitation message from sharer and one response
|
||||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
Collection<PrivateMessageHeader> list = db1.transactionWithResult(true,
|
||||||
txn -> blogSharingManager1.getMessageHeaders(txn, contactId0From1));
|
txn -> blogSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
// check things are alright with the message
|
// check things are alright with the message
|
||||||
@@ -291,7 +293,7 @@ public class BlogSharingIntegrationTest
|
|||||||
assertTrue(invitation.wasAnswered());
|
assertTrue(invitation.wasAnswered());
|
||||||
assertEquals(blog2.getAuthor().getName(),
|
assertEquals(blog2.getAuthor().getName(),
|
||||||
invitation.getName());
|
invitation.getName());
|
||||||
assertEquals(null, invitation.getMessage());
|
assertNull(invitation.getMessage());
|
||||||
} else {
|
} else {
|
||||||
BlogInvitationResponse response = (BlogInvitationResponse) m;
|
BlogInvitationResponse response = (BlogInvitationResponse) m;
|
||||||
assertEquals(blog2.getId(), response.getShareableId());
|
assertEquals(blog2.getId(), response.getShareableId());
|
||||||
@@ -300,7 +302,7 @@ public class BlogSharingIntegrationTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sharer has own invitation message and response
|
// sharer has own invitation message and response
|
||||||
assertEquals(2, withinTransactionReturns(db0,
|
assertEquals(2, db0.transactionWithResult(true,
|
||||||
txn -> blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
txn -> blogSharingManager0.getMessageHeaders(txn, contactId1From0))
|
||||||
.size());
|
.size());
|
||||||
// blog can be shared again
|
// blog can be shared again
|
||||||
@@ -388,7 +390,7 @@ public class BlogSharingIntegrationTest
|
|||||||
|
|
||||||
// make sure 1 knows that they have blog2 already
|
// make sure 1 knows that they have blog2 already
|
||||||
Collection<PrivateMessageHeader> messages =
|
Collection<PrivateMessageHeader> messages =
|
||||||
withinTransactionReturns(db1, txn -> blogSharingManager1
|
db1.transactionWithResult(true, txn -> blogSharingManager1
|
||||||
.getMessageHeaders(txn, contactId0From1));
|
.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
assertEquals(blog2, blogManager1.getBlog(blog2.getId()));
|
assertEquals(blog2, blogManager1.getBlog(blog2.getId()));
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import static org.briarproject.briar.api.forum.ForumSharingManager.CLIENT_ID;
|
|||||||
import static org.briarproject.briar.api.forum.ForumSharingManager.MAJOR_VERSION;
|
import static org.briarproject.briar.api.forum.ForumSharingManager.MAJOR_VERSION;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class ForumSharingIntegrationTest
|
public class ForumSharingIntegrationTest
|
||||||
@@ -128,7 +129,7 @@ public class ForumSharingIntegrationTest
|
|||||||
assertEquals(1, forumManager1.getForums().size());
|
assertEquals(1, forumManager1.getForums().size());
|
||||||
|
|
||||||
// invitee has one invitation message from sharer
|
// invitee has one invitation message from sharer
|
||||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
Collection<PrivateMessageHeader> list = db1.transactionWithResult(true,
|
||||||
txn -> forumSharingManager1.getMessageHeaders(txn, contactId0From1));
|
txn -> forumSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
// check other things are alright with the forum message
|
// check other things are alright with the forum message
|
||||||
@@ -148,7 +149,7 @@ public class ForumSharingIntegrationTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sharer has own invitation message and response
|
// sharer has own invitation message and response
|
||||||
assertEquals(2, withinTransactionReturns(db0, txn ->
|
assertEquals(2, db0.transactionWithResult(true, txn ->
|
||||||
forumSharingManager0.getMessageHeaders(txn, contactId1From0)).size());
|
forumSharingManager0.getMessageHeaders(txn, contactId1From0)).size());
|
||||||
// forum can not be shared again
|
// forum can not be shared again
|
||||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||||
@@ -184,7 +185,7 @@ public class ForumSharingIntegrationTest
|
|||||||
assertEquals(0, forumSharingManager1.getInvitations().size());
|
assertEquals(0, forumSharingManager1.getInvitations().size());
|
||||||
|
|
||||||
// invitee has one invitation message from sharer and one response
|
// invitee has one invitation message from sharer and one response
|
||||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
Collection<PrivateMessageHeader> list = db1.transactionWithResult(true,
|
||||||
txn -> forumSharingManager1.getMessageHeaders(txn, contactId0From1));
|
txn -> forumSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
// check things are alright with the forum message
|
// check things are alright with the forum message
|
||||||
@@ -194,7 +195,7 @@ public class ForumSharingIntegrationTest
|
|||||||
assertEquals(forum0, invitation.getNameable());
|
assertEquals(forum0, invitation.getNameable());
|
||||||
assertTrue(invitation.wasAnswered());
|
assertTrue(invitation.wasAnswered());
|
||||||
assertEquals(forum0.getName(), invitation.getName());
|
assertEquals(forum0.getName(), invitation.getName());
|
||||||
assertEquals(null, invitation.getMessage());
|
assertNull(invitation.getMessage());
|
||||||
assertFalse(invitation.canBeOpened());
|
assertFalse(invitation.canBeOpened());
|
||||||
} else {
|
} else {
|
||||||
ForumInvitationResponse response = (ForumInvitationResponse) m;
|
ForumInvitationResponse response = (ForumInvitationResponse) m;
|
||||||
@@ -204,7 +205,7 @@ public class ForumSharingIntegrationTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sharer has own invitation message and response
|
// sharer has own invitation message and response
|
||||||
assertEquals(2, withinTransactionReturns(db0, txn ->
|
assertEquals(2, db0.transactionWithResult(true, txn ->
|
||||||
forumSharingManager0.getMessageHeaders(txn, contactId1From0)).size());
|
forumSharingManager0.getMessageHeaders(txn, contactId1From0)).size());
|
||||||
// forum can be shared again
|
// forum can be shared again
|
||||||
Contact c1 = contactManager0.getContact(contactId1From0);
|
Contact c1 = contactManager0.getContact(contactId1From0);
|
||||||
@@ -446,7 +447,7 @@ public class ForumSharingIntegrationTest
|
|||||||
listenToEvents(true);
|
listenToEvents(true);
|
||||||
|
|
||||||
// invitee adds the same forum
|
// invitee adds the same forum
|
||||||
withinTransaction(db1, txn -> forumManager1.addForum(txn, forum0));
|
db1.transaction(false, txn -> forumManager1.addForum(txn, forum0));
|
||||||
|
|
||||||
// send invitation
|
// send invitation
|
||||||
forumSharingManager0
|
forumSharingManager0
|
||||||
@@ -478,10 +479,10 @@ public class ForumSharingIntegrationTest
|
|||||||
.contains(contact0From1));
|
.contains(contact0From1));
|
||||||
|
|
||||||
// and both have each other's invitations (and no response)
|
// and both have each other's invitations (and no response)
|
||||||
assertEquals(2, withinTransactionReturns(db0, txn ->
|
assertEquals(2, db0.transactionWithResult(true, txn ->
|
||||||
forumSharingManager0.getMessageHeaders(txn, contactId1From0))
|
forumSharingManager0.getMessageHeaders(txn, contactId1From0))
|
||||||
.size());
|
.size());
|
||||||
assertEquals(2, withinTransactionReturns(db1, txn ->
|
assertEquals(2, db1.transactionWithResult(true, txn ->
|
||||||
forumSharingManager1.getMessageHeaders(txn, contactId0From1))
|
forumSharingManager1.getMessageHeaders(txn, contactId0From1))
|
||||||
.size());
|
.size());
|
||||||
|
|
||||||
@@ -558,7 +559,7 @@ public class ForumSharingIntegrationTest
|
|||||||
@Test
|
@Test
|
||||||
public void testTwoContactsShareSameForum() throws Exception {
|
public void testTwoContactsShareSameForum() throws Exception {
|
||||||
// second sharer adds the same forum
|
// second sharer adds the same forum
|
||||||
withinTransaction(db2, txn -> db2.addGroup(txn, forum0.getGroup()));
|
db2.transaction(false, txn -> db2.addGroup(txn, forum0.getGroup()));
|
||||||
|
|
||||||
// add listeners
|
// add listeners
|
||||||
listener0 = new SharerListener(true);
|
listener0 = new SharerListener(true);
|
||||||
@@ -576,7 +577,7 @@ public class ForumSharingIntegrationTest
|
|||||||
sync0To1(1, true);
|
sync0To1(1, true);
|
||||||
|
|
||||||
// second sharer sends invitation for same forum
|
// second sharer sends invitation for same forum
|
||||||
assertTrue(contactId1From2 != null);
|
assertNotNull(contactId1From2);
|
||||||
forumSharingManager2
|
forumSharingManager2
|
||||||
.sendInvitation(forum0.getId(), contactId1From2, null,
|
.sendInvitation(forum0.getId(), contactId1From2, null,
|
||||||
clock.currentTimeMillis());
|
clock.currentTimeMillis());
|
||||||
@@ -735,7 +736,7 @@ public class ForumSharingIntegrationTest
|
|||||||
|
|
||||||
// get invitation MessageId for later
|
// get invitation MessageId for later
|
||||||
MessageId invitationId = null;
|
MessageId invitationId = null;
|
||||||
Collection<PrivateMessageHeader> list = withinTransactionReturns(db1,
|
Collection<PrivateMessageHeader> list = db1.transactionWithResult(true,
|
||||||
txn -> forumSharingManager1.getMessageHeaders(txn, contactId0From1));
|
txn -> forumSharingManager1.getMessageHeaders(txn, contactId0From1));
|
||||||
for (PrivateMessageHeader m : list) {
|
for (PrivateMessageHeader m : list) {
|
||||||
if (m instanceof ForumInvitationRequest) {
|
if (m instanceof ForumInvitationRequest) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.test;
|
|||||||
|
|
||||||
import net.jodah.concurrentunit.Waiter;
|
import net.jodah.concurrentunit.Waiter;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
|
||||||
import org.briarproject.bramble.api.client.ClientHelper;
|
import org.briarproject.bramble.api.client.ClientHelper;
|
||||||
import org.briarproject.bramble.api.client.ContactGroupFactory;
|
import org.briarproject.bramble.api.client.ContactGroupFactory;
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
@@ -11,7 +10,6 @@ import org.briarproject.bramble.api.contact.ContactManager;
|
|||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||||
@@ -379,40 +377,4 @@ public abstract class BriarIntegrationTest<C extends BriarIntegrationTestCompone
|
|||||||
contactManager2.removeContact(contactId1From2);
|
contactManager2.removeContact(contactId1From2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
protected interface TransactionScope {
|
|
||||||
void execute(Transaction txn) throws DbException, FormatException;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void withinTransaction(DatabaseComponent db,
|
|
||||||
TransactionScope scope) throws DbException {
|
|
||||||
Transaction txn = db.startTransaction(false);
|
|
||||||
try {
|
|
||||||
scope.execute(txn);
|
|
||||||
db.commitTransaction(txn);
|
|
||||||
} catch (FormatException e) {
|
|
||||||
throw new DbException(e);
|
|
||||||
} finally {
|
|
||||||
db.endTransaction(txn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
protected interface TransactionResultScope<R> {
|
|
||||||
R execute(Transaction txn) throws DbException;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected <R> R withinTransactionReturns(DatabaseComponent db,
|
|
||||||
TransactionResultScope<R> scope) throws DbException {
|
|
||||||
Transaction txn = db.startTransaction(false);
|
|
||||||
R r;
|
|
||||||
try {
|
|
||||||
r = scope.execute(txn);
|
|
||||||
db.commitTransaction(txn);
|
|
||||||
} finally {
|
|
||||||
db.endTransaction(txn);
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user