Merge branch 'introduction-manager-txn' into 'master'

Transactional versions for introduction manager and private group invitation manager

See merge request briar/briar!1781
This commit is contained in:
akwizgran
2023-03-06 12:08:34 +00:00
7 changed files with 192 additions and 104 deletions

View File

@@ -29,6 +29,12 @@ public interface IntroductionManager extends ConversationClient {
*/ */
boolean canIntroduce(Contact c1, Contact c2) throws DbException; boolean canIntroduce(Contact c1, Contact c2) throws DbException;
/**
* Returns true if both contacts can be introduced at this moment.
*/
boolean canIntroduce(Transaction txn, Contact c1, Contact c2)
throws DbException;
/** /**
* The current minor version of the introduction client. * The current minor version of the introduction client.
*/ */
@@ -40,6 +46,12 @@ public interface IntroductionManager extends ConversationClient {
void makeIntroduction(Contact c1, Contact c2, @Nullable String text) void makeIntroduction(Contact c1, Contact c2, @Nullable String text)
throws DbException; throws DbException;
/**
* Sends two initial introduction messages.
*/
void makeIntroduction(Transaction txn, Contact c1, Contact c2,
@Nullable String text) throws DbException;
/** /**
* Responds to an introduction. * Responds to an introduction.
*/ */

View File

@@ -52,11 +52,21 @@ public interface PrivateGroupManager {
void addPrivateGroup(Transaction txn, PrivateGroup group, void addPrivateGroup(Transaction txn, PrivateGroup group,
GroupMessage joinMsg, boolean creator) throws DbException; GroupMessage joinMsg, boolean creator) throws DbException;
/**
* Removes a dissolved private group.
*/
void removePrivateGroup(Transaction txn, GroupId g) throws DbException;
/** /**
* Removes a dissolved private group. * Removes a dissolved private group.
*/ */
void removePrivateGroup(GroupId g) throws DbException; void removePrivateGroup(GroupId g) throws DbException;
/**
* Returns the ID of the user's previous message sent to the group
*/
MessageId getPreviousMsgId(Transaction txn, GroupId g) throws DbException;
/** /**
* Returns the ID of the user's previous message sent to the group * Returns the ID of the user's previous message sent to the group
*/ */
@@ -112,7 +122,8 @@ public interface PrivateGroupManager {
/** /**
* Returns true if the given private group was created by us. * Returns true if the given private group was created by us.
*/ */
boolean isOurPrivateGroup(Transaction txn, PrivateGroup g) throws DbException; boolean isOurPrivateGroup(Transaction txn, PrivateGroup g)
throws DbException;
/** /**
* Returns the text of the private group message with the given ID. * Returns the text of the private group message with the given ID.
@@ -161,6 +172,12 @@ public interface PrivateGroupManager {
*/ */
GroupCount getGroupCount(GroupId g) throws DbException; GroupCount getGroupCount(GroupId g) throws DbException;
/**
* Marks a message as read or unread and updates the group count.
*/
void setReadFlag(Transaction txn, GroupId g, MessageId m, boolean read)
throws DbException;
/** /**
* Marks a message as read or unread and updates the group count. * Marks a message as read or unread and updates the group count.
*/ */

View File

@@ -3,6 +3,7 @@ package org.briarproject.briar.api.privategroup.invitation;
import org.briarproject.bramble.api.contact.Contact; import org.briarproject.bramble.api.contact.Contact;
import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.contact.ContactId;
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.sync.ClientId; import org.briarproject.bramble.api.sync.ClientId;
import org.briarproject.bramble.api.sync.GroupId; import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.briar.api.client.ProtocolStateException; import org.briarproject.briar.api.client.ProtocolStateException;
@@ -47,6 +48,18 @@ public interface GroupInvitationManager extends ConversationClient {
long timestamp, byte[] signature, long autoDeleteTimer) long timestamp, byte[] signature, long autoDeleteTimer)
throws DbException; throws DbException;
/**
* Sends an invitation to share the given private group with the given
* contact, including an optional message.
*
* @throws ProtocolStateException if the group is no longer eligible to be
* shared with the contact, for example because an invitation is already
* pending.
*/
void sendInvitation(Transaction txn, GroupId g, ContactId c,
@Nullable String text, long timestamp, byte[] signature,
long autoDeleteTimer) throws DbException;
/** /**
* Responds to a pending private group invitation from the given contact. * Responds to a pending private group invitation from the given contact.
* *
@@ -56,6 +69,15 @@ public interface GroupInvitationManager extends ConversationClient {
void respondToInvitation(ContactId c, PrivateGroup g, boolean accept) void respondToInvitation(ContactId c, PrivateGroup g, boolean accept)
throws DbException; throws DbException;
/**
* Responds to a pending private group invitation from the given contact.
*
* @throws ProtocolStateException if the invitation is no longer pending,
* for example because the group has been dissolved.
*/
void respondToInvitation(Transaction txn, ContactId c, PrivateGroup g,
boolean accept) throws DbException;
/** /**
* Responds to a pending private group invitation from the given contact. * Responds to a pending private group invitation from the given contact.
* *
@@ -65,6 +87,15 @@ public interface GroupInvitationManager extends ConversationClient {
void respondToInvitation(ContactId c, SessionId s, boolean accept) void respondToInvitation(ContactId c, SessionId s, boolean accept)
throws DbException; throws DbException;
/**
* Responds to a pending private group invitation from the given contact.
*
* @throws ProtocolStateException if the invitation is no longer pending,
* for example because the group has been dissolved.
*/
void respondToInvitation(Transaction txn, ContactId c, SessionId s,
boolean accept) throws DbException;
/** /**
* Makes the user's relationship with the given contact visible to the * Makes the user's relationship with the given contact visible to the
* given private group. * given private group.
@@ -74,11 +105,27 @@ public interface GroupInvitationManager extends ConversationClient {
*/ */
void revealRelationship(ContactId c, GroupId g) throws DbException; void revealRelationship(ContactId c, GroupId g) throws DbException;
/**
* Makes the user's relationship with the given contact visible to the
* given private group.
*
* @throws ProtocolStateException if the relationship is no longer eligible
* to be revealed, for example because the contact has revealed it.
*/
void revealRelationship(Transaction txn, ContactId c, GroupId g)
throws DbException;
/** /**
* Returns all private groups to which the user has been invited. * Returns all private groups to which the user has been invited.
*/ */
Collection<GroupInvitationItem> getInvitations() throws DbException; Collection<GroupInvitationItem> getInvitations() throws DbException;
/**
* Returns all private groups to which the user has been invited.
*/
Collection<GroupInvitationItem> getInvitations(Transaction txn)
throws DbException;
/** /**
* Returns the current {@link SharingStatus} for the given {@link Contact} * Returns the current {@link SharingStatus} for the given {@link Contact}
* and {@link PrivateGroup} identified by the given {@link GroupId}. * and {@link PrivateGroup} identified by the given {@link GroupId}.
@@ -89,4 +136,16 @@ public interface GroupInvitationManager extends ConversationClient {
* was already dissolved. * was already dissolved.
*/ */
SharingStatus getSharingStatus(Contact c, GroupId g) throws DbException; SharingStatus getSharingStatus(Contact c, GroupId g) throws DbException;
/**
* Returns the current {@link SharingStatus} for the given {@link Contact}
* and {@link PrivateGroup} identified by the given {@link GroupId}.
* This indicates whether the {@link PrivateGroup} can be shared
* with the contact.
*
* @throws ProtocolStateException if {@link PrivateGroup}
* was already dissolved.
*/
SharingStatus getSharingStatus(Transaction txn, Contact c, GroupId g)
throws DbException;
} }

View File

@@ -300,36 +300,37 @@ class IntroductionManagerImpl extends ConversationClientImpl
@Override @Override
public boolean canIntroduce(Contact c1, Contact c2) throws DbException { public boolean canIntroduce(Contact c1, Contact c2) throws DbException {
Transaction txn = db.startTransaction(true); return db.transactionWithResult(true,
txn -> canIntroduce(txn, c1, c2));
}
public boolean canIntroduce(Transaction txn, Contact c1, Contact c2)
throws DbException {
try { try {
boolean can = canIntroduce(txn, c1, c2); // Look up the session, if there is one
db.commitTransaction(txn); Author introducer = identityManager.getLocalAuthor(txn);
return can; SessionId sessionId =
crypto.getSessionId(introducer, c1.getAuthor(),
c2.getAuthor());
StoredSession ss = getSession(txn, sessionId);
if (ss == null) return true;
IntroducerSession session =
sessionParser.parseIntroducerSession(ss.bdfSession);
return session.getState().isComplete();
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);
} finally {
db.endTransaction(txn);
} }
} }
private boolean canIntroduce(Transaction txn, Contact c1, Contact c2) public void makeIntroduction(Contact c1, Contact c2, @Nullable String text)
throws DbException, FormatException { throws DbException {
// Look up the session, if there is one db.transaction(false,
Author introducer = identityManager.getLocalAuthor(txn); txn -> makeIntroduction(txn, c1, c2, text));
SessionId sessionId =
crypto.getSessionId(introducer, c1.getAuthor(),
c2.getAuthor());
StoredSession ss = getSession(txn, sessionId);
if (ss == null) return true;
IntroducerSession session =
sessionParser.parseIntroducerSession(ss.bdfSession);
return session.getState().isComplete();
} }
@Override @Override
public void makeIntroduction(Contact c1, Contact c2, @Nullable String text) public void makeIntroduction(Transaction txn, Contact c1, Contact c2,
throws DbException { @Nullable String text) throws DbException {
Transaction txn = db.startTransaction(false);
try { try {
// Look up the session, if there is one // Look up the session, if there is one
Author introducer = identityManager.getLocalAuthor(txn); Author introducer = identityManager.getLocalAuthor(txn);
@@ -363,11 +364,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
session = introducerEngine.onRequestAction(txn, session, text); session = introducerEngine.onRequestAction(txn, session, text);
// Store the updated session // Store the updated session
storeSession(txn, storageId, session); storeSession(txn, storageId, session);
db.commitTransaction(txn);
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);
} finally {
db.endTransaction(txn);
} }
} }

View File

@@ -150,40 +150,35 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
} }
@Override @Override
public void removePrivateGroup(GroupId g) throws DbException { public void removePrivateGroup(Transaction txn, GroupId g)
Transaction txn = db.startTransaction(false); throws DbException {
try { for (PrivateGroupHook hook : hooks) {
for (PrivateGroupHook hook : hooks) { hook.removingGroup(txn, g);
hook.removingGroup(txn, g);
}
Group group = db.getGroup(txn, g);
db.removeGroup(txn, group);
db.commitTransaction(txn);
} finally {
db.endTransaction(txn);
} }
Group group = db.getGroup(txn, g);
db.removeGroup(txn, group);
}
@Override
public void removePrivateGroup(GroupId g) throws DbException {
db.transaction(false, txn -> removePrivateGroup(txn, g));
} }
@Override @Override
public MessageId getPreviousMsgId(GroupId g) throws DbException { public MessageId getPreviousMsgId(GroupId g) throws DbException {
MessageId previousMsgId; return db.transactionWithResult(true,
Transaction txn = db.startTransaction(true); txn -> getPreviousMsgId(txn, g));
try {
previousMsgId = getPreviousMsgId(txn, g);
db.commitTransaction(txn);
} catch (FormatException e) {
throw new DbException(e);
} finally {
db.endTransaction(txn);
}
return previousMsgId;
} }
private MessageId getPreviousMsgId(Transaction txn, GroupId g) public MessageId getPreviousMsgId(Transaction txn, GroupId g)
throws DbException, FormatException { throws DbException {
BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(txn, g); try {
byte[] previousMsgIdBytes = d.getRaw(KEY_PREVIOUS_MSG_ID); BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(txn, g);
return new MessageId(previousMsgIdBytes); byte[] previousMsgIdBytes = d.getRaw(KEY_PREVIOUS_MSG_ID);
return new MessageId(previousMsgIdBytes);
} catch (FormatException e) {
throw new DbException(e);
}
} }
private void setPreviousMsgId(Transaction txn, GroupId g, private void setPreviousMsgId(Transaction txn, GroupId g,
@@ -483,11 +478,16 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
return messageTracker.getGroupCount(g); return messageTracker.getGroupCount(g);
} }
@Override
public void setReadFlag(Transaction txn, GroupId g, MessageId m,
boolean read) throws DbException {
messageTracker.setReadFlag(txn, g, m, read);
}
@Override @Override
public void setReadFlag(GroupId g, MessageId m, boolean read) public void setReadFlag(GroupId g, MessageId m, boolean read)
throws DbException { throws DbException {
db.transaction(false, txn -> db.transaction(false, txn -> setReadFlag(txn, g, m, read));
messageTracker.setReadFlag(txn, g, m, read));
} }
@Override @Override

View File

@@ -319,8 +319,16 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
public void sendInvitation(GroupId privateGroupId, ContactId c, public void sendInvitation(GroupId privateGroupId, ContactId c,
@Nullable String text, long timestamp, byte[] signature, @Nullable String text, long timestamp, byte[] signature,
long autoDeleteTimer) throws DbException { long autoDeleteTimer) throws DbException {
db.transaction(false,
txn -> sendInvitation(txn, privateGroupId, c, text, timestamp,
signature, autoDeleteTimer));
}
@Override
public void sendInvitation(Transaction txn, GroupId privateGroupId,
ContactId c, @Nullable String text, long timestamp,
byte[] signature, long autoDeleteTimer) throws DbException {
SessionId sessionId = getSessionId(privateGroupId); SessionId sessionId = getSessionId(privateGroupId);
Transaction txn = db.startTransaction(false);
try { try {
// Look up the session, if there is one // Look up the session, if there is one
Contact contact = db.getContact(txn, c); Contact contact = db.getContact(txn, c);
@@ -344,11 +352,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
timestamp, signature, autoDeleteTimer); timestamp, signature, autoDeleteTimer);
// Store the updated session // Store the updated session
storeSession(txn, storageId, session); storeSession(txn, storageId, session);
db.commitTransaction(txn);
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);
} finally {
db.endTransaction(txn);
} }
} }
@@ -358,6 +363,12 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
respondToInvitation(c, getSessionId(g.getId()), accept); respondToInvitation(c, getSessionId(g.getId()), accept);
} }
@Override
public void respondToInvitation(Transaction txn, ContactId c,
PrivateGroup g, boolean accept) throws DbException {
respondToInvitation(txn, c, getSessionId(g.getId()), accept);
}
@Override @Override
public void respondToInvitation(ContactId c, SessionId sessionId, public void respondToInvitation(ContactId c, SessionId sessionId,
boolean accept) throws DbException { boolean accept) throws DbException {
@@ -365,6 +376,12 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
txn -> respondToInvitation(txn, c, sessionId, accept, false)); txn -> respondToInvitation(txn, c, sessionId, accept, false));
} }
@Override
public void respondToInvitation(Transaction txn, ContactId c,
SessionId sessionId, boolean accept) throws DbException {
respondToInvitation(txn, c, sessionId, accept, false);
}
private void respondToInvitation(Transaction txn, ContactId c, private void respondToInvitation(Transaction txn, ContactId c,
SessionId sessionId, boolean accept, boolean isAutoDecline) SessionId sessionId, boolean accept, boolean isAutoDecline)
throws DbException { throws DbException {
@@ -390,7 +407,12 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
@Override @Override
public void revealRelationship(ContactId c, GroupId g) throws DbException { public void revealRelationship(ContactId c, GroupId g) throws DbException {
Transaction txn = db.startTransaction(false); db.transaction(false, txn -> revealRelationship(txn, c, g));
}
@Override
public void revealRelationship(Transaction txn, ContactId c, GroupId g)
throws DbException {
try { try {
// Look up the session // Look up the session
Contact contact = db.getContact(txn, c); Contact contact = db.getContact(txn, c);
@@ -404,11 +426,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
session = peerEngine.onJoinAction(txn, session); session = peerEngine.onJoinAction(txn, session);
// Store the updated session // Store the updated session
storeSession(txn, ss.storageId, session); storeSession(txn, ss.storageId, session);
db.commitTransaction(txn);
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);
} finally {
db.endTransaction(txn);
} }
} }
@@ -495,9 +514,14 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
@Override @Override
public Collection<GroupInvitationItem> getInvitations() throws DbException { public Collection<GroupInvitationItem> getInvitations() throws DbException {
return db.transactionWithResult(true, this::getInvitations);
}
@Override
public Collection<GroupInvitationItem> getInvitations(Transaction txn)
throws DbException {
List<GroupInvitationItem> items = new ArrayList<>(); List<GroupInvitationItem> items = new ArrayList<>();
BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery(); BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery();
Transaction txn = db.startTransaction(true);
try { try {
// Look up the available invite messages for each contact // Look up the available invite messages for each contact
for (Contact c : db.getContacts(txn)) { for (Contact c : db.getContacts(txn)) {
@@ -507,11 +531,8 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
for (MessageId m : results) for (MessageId m : results)
items.add(parseGroupInvitationItem(txn, c, m)); items.add(parseGroupInvitationItem(txn, c, m));
} }
db.commitTransaction(txn);
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);
} finally {
db.endTransaction(txn);
} }
return items; return items;
} }
@@ -519,15 +540,20 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
@Override @Override
public SharingStatus getSharingStatus(Contact c, GroupId privateGroupId) public SharingStatus getSharingStatus(Contact c, GroupId privateGroupId)
throws DbException { throws DbException {
return db.transactionWithResult(true,
txn -> getSharingStatus(txn, c, privateGroupId));
}
@Override
public SharingStatus getSharingStatus(Transaction txn, Contact c,
GroupId privateGroupId) throws DbException {
GroupId contactGroupId = getContactGroup(c).getId(); GroupId contactGroupId = getContactGroup(c).getId();
SessionId sessionId = getSessionId(privateGroupId); SessionId sessionId = getSessionId(privateGroupId);
Transaction txn = db.startTransaction(true);
try { try {
Visibility client = clientVersioningManager.getClientVisibility(txn, Visibility client = clientVersioningManager.getClientVisibility(txn,
c.getId(), PrivateGroupManager.CLIENT_ID, c.getId(), PrivateGroupManager.CLIENT_ID,
PrivateGroupManager.MAJOR_VERSION); PrivateGroupManager.MAJOR_VERSION);
StoredSession ss = getSession(txn, contactGroupId, sessionId); StoredSession ss = getSession(txn, contactGroupId, sessionId);
db.commitTransaction(txn);
// The group can't be shared unless the contact supports the client // The group can't be shared unless the contact supports the client
if (client != SHARED) return SharingStatus.NOT_SUPPORTED; if (client != SHARED) return SharingStatus.NOT_SUPPORTED;
// If there's no session, the contact can be invited // If there's no session, the contact can be invited
@@ -548,8 +574,6 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
throw new AssertionError("Unhandled state: " + state.name()); throw new AssertionError("Unhandled state: " + state.name());
} catch (FormatException e) { } catch (FormatException e) {
throw new DbException(e); throw new DbException(e);
} finally {
db.endTransaction(txn);
} }
} }

View File

@@ -570,9 +570,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
byte[] signature = getRandomBytes(42); byte[] signature = getRandomBytes(42);
expectGetSession(noResults, sessionId, contactGroup.getId()); expectGetSession(noResults, sessionId, contactGroup.getId());
context.checking(new Expectations() {{ context.checking(new DbExpectations() {{
oneOf(db).startTransaction(false); oneOf(db).transaction(with(false), withDbRunnable(txn));
will(returnValue(txn));
oneOf(db).getContact(txn, contactId); oneOf(db).getContact(txn, contactId);
will(returnValue(contact)); will(returnValue(contact));
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
@@ -587,10 +586,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
will(returnValue(creatorSession)); will(returnValue(creatorSession));
}}); }});
expectStoreSession(creatorSession, storageMessage.getId()); expectStoreSession(creatorSession, storageMessage.getId());
context.checking(new Expectations() {{
oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn);
}});
groupInvitationManager.sendInvitation(privateGroup.getId(), contactId, groupInvitationManager.sendInvitation(privateGroup.getId(), contactId,
text, time, signature, NO_AUTO_DELETE_TIMER); text, time, signature, NO_AUTO_DELETE_TIMER);
} }
@@ -602,9 +597,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
byte[] signature = getRandomBytes(43); byte[] signature = getRandomBytes(43);
expectGetSession(oneResult, sessionId, contactGroup.getId()); expectGetSession(oneResult, sessionId, contactGroup.getId());
context.checking(new Expectations() {{ context.checking(new DbExpectations() {{
oneOf(db).startTransaction(false); oneOf(db).transaction(with(false), withDbRunnable(txn));
will(returnValue(txn));
oneOf(db).getContact(txn, contactId); oneOf(db).getContact(txn, contactId);
will(returnValue(contact)); will(returnValue(contact));
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
@@ -619,10 +613,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
will(returnValue(creatorSession)); will(returnValue(creatorSession));
}}); }});
expectStoreSession(creatorSession, storageMessage.getId()); expectStoreSession(creatorSession, storageMessage.getId());
context.checking(new Expectations() {{
oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn);
}});
groupInvitationManager.sendInvitation(privateGroup.getId(), contactId, groupInvitationManager.sendInvitation(privateGroup.getId(), contactId,
text, time, signature, NO_AUTO_DELETE_TIMER); text, time, signature, NO_AUTO_DELETE_TIMER);
} }
@@ -700,9 +690,8 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testRevealRelationship() throws Exception { public void testRevealRelationship() throws Exception {
context.checking(new Expectations() {{ context.checking(new DbExpectations() {{
oneOf(db).startTransaction(false); oneOf(db).transaction(with(false), withDbRunnable(txn));
will(returnValue(txn));
oneOf(db).getContact(txn, contactId); oneOf(db).getContact(txn, contactId);
will(returnValue(contact)); will(returnValue(contact));
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
@@ -713,8 +702,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
will(returnValue(peerSession)); will(returnValue(peerSession));
oneOf(peerEngine).onJoinAction(txn, peerSession); oneOf(peerEngine).onJoinAction(txn, peerSession);
will(returnValue(peerSession)); will(returnValue(peerSession));
oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn);
}}); }});
expectGetSession(oneResult, sessionId, contactGroup.getId()); expectGetSession(oneResult, sessionId, contactGroup.getId());
expectStoreSession(peerSession, storageMessage.getId()); expectStoreSession(peerSession, storageMessage.getId());
@@ -725,15 +712,13 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testRevealRelationshipWithoutSession() throws Exception { public void testRevealRelationshipWithoutSession() throws Exception {
context.checking(new Expectations() {{ context.checking(new DbExpectations() {{
oneOf(db).startTransaction(false); oneOf(db).transaction(with(false), withDbRunnable(txn));
will(returnValue(txn));
oneOf(db).getContact(txn, contactId); oneOf(db).getContact(txn, contactId);
will(returnValue(contact)); will(returnValue(contact));
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(db).endTransaction(txn);
}}); }});
expectGetSession(noResults, sessionId, contactGroup.getId()); expectGetSession(noResults, sessionId, contactGroup.getId());
@@ -832,11 +817,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
PrivateGroup pg = new PrivateGroup(group, groupName, PrivateGroup pg = new PrivateGroup(group, groupName,
author, salt); author, salt);
context.checking(new Expectations() {{ context.checking(new DbExpectations() {{
oneOf(messageParser).getInvitesAvailableToAnswerQuery(); oneOf(messageParser).getInvitesAvailableToAnswerQuery();
will(returnValue(query)); will(returnValue(query));
oneOf(db).startTransaction(true); oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
will(returnValue(txn));
oneOf(db).getContacts(txn); oneOf(db).getContacts(txn);
will(returnValue(singletonList(contact))); will(returnValue(singletonList(contact)));
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
@@ -856,9 +840,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
oneOf(privateGroupFactory).createPrivateGroup(groupName, author, oneOf(privateGroupFactory).createPrivateGroup(groupName, author,
salt); salt);
will(returnValue(pg)); will(returnValue(pg));
// end transaction
oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn);
}}); }});
Collection<GroupInvitationItem> items = Collection<GroupInvitationItem> items =
@@ -910,12 +891,11 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
private void expectIsInvitationAllowed(CreatorState state) private void expectIsInvitationAllowed(CreatorState state)
throws Exception { throws Exception {
expectGetSession(oneResult, sessionId, contactGroup.getId()); expectGetSession(oneResult, sessionId, contactGroup.getId());
context.checking(new Expectations() {{ context.checking(new DbExpectations() {{
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID, oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
MAJOR_VERSION, contact); MAJOR_VERSION, contact);
will(returnValue(contactGroup)); will(returnValue(contactGroup));
oneOf(db).startTransaction(true); oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
will(returnValue(txn));
oneOf(clientVersioningManager).getClientVisibility(txn, contactId, oneOf(clientVersioningManager).getClientVisibility(txn, contactId,
PrivateGroupManager.CLIENT_ID, PrivateGroupManager.CLIENT_ID,
PrivateGroupManager.MAJOR_VERSION); PrivateGroupManager.MAJOR_VERSION);
@@ -925,8 +905,6 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
will(returnValue(creatorSession)); will(returnValue(creatorSession));
oneOf(creatorSession).getState(); oneOf(creatorSession).getState();
will(returnValue(state)); will(returnValue(state));
oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn);
}}); }});
} }