Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
briar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
681
Issues
681
List
Boards
Labels
Service Desk
Milestones
Merge Requests
16
Merge Requests
16
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
briar
briar
Commits
baf64e11
Verified
Commit
baf64e11
authored
Oct 29, 2018
by
Torsten Grote
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[bramble] Add transactionless method for retrieving AuthorInfo to ContactManager
parent
88adfabe
Pipeline
#2633
passed with stage
in 10 minutes and 11 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
1 deletion
+67
-1
bramble-api/src/main/java/org/briarproject/bramble/api/contact/ContactManager.java
.../org/briarproject/bramble/api/contact/ContactManager.java
+5
-0
bramble-core/src/main/java/org/briarproject/bramble/contact/ContactManagerImpl.java
.../org/briarproject/bramble/contact/ContactManagerImpl.java
+5
-0
bramble-core/src/test/java/org/briarproject/bramble/contact/ContactManagerImplTest.java
.../briarproject/bramble/contact/ContactManagerImplTest.java
+22
-1
bramble-core/src/test/java/org/briarproject/bramble/test/DbExpectations.java
...st/java/org/briarproject/bramble/test/DbExpectations.java
+8
-0
bramble-core/src/test/java/org/briarproject/bramble/test/RunTransactionWithResultAction.java
...rproject/bramble/test/RunTransactionWithResultAction.java
+27
-0
No files found.
bramble-api/src/main/java/org/briarproject/bramble/api/contact/ContactManager.java
View file @
baf64e11
...
...
@@ -114,6 +114,11 @@ public interface ContactManager {
boolean
contactExists
(
AuthorId
remoteAuthorId
,
AuthorId
localAuthorId
)
throws
DbException
;
/**
* Returns the {@link AuthorInfo} for the given author.
*/
AuthorInfo
getAuthorInfo
(
AuthorId
a
)
throws
DbException
;
/**
* Returns the {@link AuthorInfo} for the given author.
*/
...
...
bramble-core/src/main/java/org/briarproject/bramble/contact/ContactManagerImpl.java
View file @
baf64e11
...
...
@@ -201,6 +201,11 @@ class ContactManagerImpl implements ContactManager {
db
.
removeContact
(
txn
,
c
);
}
@Override
public
AuthorInfo
getAuthorInfo
(
AuthorId
a
)
throws
DbException
{
return
db
.
transactionWithResult
(
true
,
txn
->
getAuthorInfo
(
txn
,
a
));
}
@Override
public
AuthorInfo
getAuthorInfo
(
Transaction
txn
,
AuthorId
authorId
)
throws
DbException
{
...
...
bramble-core/src/test/java/org/briarproject/bramble/contact/ContactManagerImplTest.java
View file @
baf64e11
...
...
@@ -224,7 +224,28 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
}
@Test
public
void
testGetAuthorStatus
()
throws
DbException
{
public
void
testGetAuthorStatus
()
throws
Exception
{
Transaction
txn
=
new
Transaction
(
null
,
true
);
Collection
<
Contact
>
contacts
=
singletonList
(
new
Contact
(
new
ContactId
(
1
),
remote
,
localAuthor
.
getId
(),
alias
,
false
,
true
));
context
.
checking
(
new
DbExpectations
()
{{
oneOf
(
db
).
transactionWithResult
(
with
(
equal
(
true
)),
withDbCallable
(
txn
));
oneOf
(
identityManager
).
getLocalAuthor
(
txn
);
will
(
returnValue
(
localAuthor
));
oneOf
(
db
).
getContactsByAuthorId
(
txn
,
remote
.
getId
());
will
(
returnValue
(
contacts
));
}});
AuthorInfo
authorInfo
=
contactManager
.
getAuthorInfo
(
txn
,
remote
.
getId
());
assertEquals
(
UNVERIFIED
,
authorInfo
.
getStatus
());
assertEquals
(
alias
,
contact
.
getAlias
());
}
@Test
public
void
testGetAuthorStatusTransaction
()
throws
DbException
{
Transaction
txn
=
new
Transaction
(
null
,
true
);
// check unknown author
...
...
bramble-core/src/test/java/org/briarproject/bramble/test/DbExpectations.java
View file @
baf64e11
package
org.briarproject.bramble.test
;
import
org.briarproject.bramble.api.db.DbCallable
;
import
org.briarproject.bramble.api.db.DbRunnable
;
import
org.briarproject.bramble.api.db.Transaction
;
import
org.jmock.Expectations
;
...
...
@@ -13,4 +14,11 @@ public class DbExpectations extends Expectations {
return
null
;
}
protected
<
R
,
E
extends
Exception
>
DbCallable
<
R
,
E
>
withDbCallable
(
Transaction
txn
)
{
addParameterMatcher
(
any
(
DbCallable
.
class
));
currentBuilder
().
setAction
(
new
RunTransactionWithResultAction
(
txn
));
return
null
;
}
}
bramble-core/src/test/java/org/briarproject/bramble/test/RunTransactionWithResultAction.java
0 → 100644
View file @
baf64e11
package
org.briarproject.bramble.test
;
import
org.briarproject.bramble.api.db.DbCallable
;
import
org.briarproject.bramble.api.db.Transaction
;
import
org.hamcrest.Description
;
import
org.jmock.api.Action
;
import
org.jmock.api.Invocation
;
public
class
RunTransactionWithResultAction
implements
Action
{
private
final
Transaction
txn
;
public
RunTransactionWithResultAction
(
Transaction
txn
)
{
this
.
txn
=
txn
;
}
@Override
public
Object
invoke
(
Invocation
invocation
)
throws
Throwable
{
DbCallable
task
=
(
DbCallable
)
invocation
.
getParameter
(
1
);
return
task
.
call
(
txn
);
}
@Override
public
void
describeTo
(
Description
description
)
{
description
.
appendText
(
"runs a task inside a database transaction"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment