Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
briar
Commits
4b5ad9ac
Verified
Commit
4b5ad9ac
authored
6 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Make test expectations modular.
parent
a94ffd41
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1126
Small cleanups for rendezvous poller
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bramble-core/src/test/java/org/briarproject/bramble/rendezvous/RendezvousPollerImplTest.java
+60
-88
60 additions, 88 deletions
...rproject/bramble/rendezvous/RendezvousPollerImplTest.java
with
60 additions
and
88 deletions
bramble-core/src/test/java/org/briarproject/bramble/rendezvous/RendezvousPollerImplTest.java
+
60
−
88
View file @
4b5ad9ac
...
@@ -115,20 +115,10 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
...
@@ -115,20 +115,10 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
with
(
MILLISECONDS
));
with
(
MILLISECONDS
));
will
(
new
CaptureArgumentAction
<>(
captureExpiryTask
,
Runnable
.
class
,
will
(
new
CaptureArgumentAction
<>(
captureExpiryTask
,
Runnable
.
class
,
0
));
0
));
// Load our handshake key pair
oneOf
(
db
).
transactionWithResult
(
with
(
true
),
withDbCallable
(
txn
));
will
(
returnValue
(
handshakeKeyPair
));
// Derive the rendezvous key
oneOf
(
transportCrypto
).
deriveStaticMasterKey
(
pendingContact
.
getPublicKey
(),
handshakeKeyPair
);
will
(
returnValue
(
staticMasterKey
));
oneOf
(
rendezvousCrypto
).
deriveRendezvousKey
(
staticMasterKey
);
will
(
returnValue
(
rendezvousKey
));
oneOf
(
transportCrypto
).
isAlice
(
pendingContact
.
getPublicKey
(),
handshakeKeyPair
);
will
(
returnValue
(
alice
));
}});
}});
expectDeriveRendezvousKey
();
rendezvousPoller
.
startService
();
rendezvousPoller
.
startService
();
context
.
assertIsSatisfied
();
context
.
assertIsSatisfied
();
...
@@ -157,45 +147,27 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
...
@@ -157,45 +147,27 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
@Test
@Test
public
void
testCreatesAndClosesEndpointsWhenPendingContactIsAddedAndRemoved
()
public
void
testCreatesAndClosesEndpointsWhenPendingContactIsAddedAndRemoved
()
throws
Exception
{
throws
Exception
{
Transaction
txn
=
new
Transaction
(
null
,
true
);
long
now
=
pendingContact
.
getTimestamp
();
long
now
=
pendingContact
.
getTimestamp
();
// Enable the transport - no endpoints should be created yet
// Enable the transport - no endpoints should be created yet
context
.
checking
(
new
Expectations
()
{{
expectGetPlugin
();
oneOf
(
pluginManager
).
getPlugin
(
transportId
);
will
(
returnValue
(
plugin
));
oneOf
(
plugin
).
supportsRendezvous
();
will
(
returnValue
(
true
));
allowing
(
plugin
).
getId
();
will
(
returnValue
(
transportId
));
}});
rendezvousPoller
.
eventOccurred
(
new
TransportEnabledEvent
(
transportId
));
rendezvousPoller
.
eventOccurred
(
new
TransportEnabledEvent
(
transportId
));
context
.
assertIsSatisfied
();
context
.
assertIsSatisfied
();
// Add the pending contact - endpoint should be created and polled
// Add the pending contact - endpoint should be created and polled
context
.
checking
(
new
Db
Expectations
()
{{
context
.
checking
(
new
Expectations
()
{{
// Add pending contact
// Add pending contact
oneOf
(
clock
).
currentTimeMillis
();
oneOf
(
clock
).
currentTimeMillis
();
will
(
returnValue
(
now
));
will
(
returnValue
(
now
));
oneOf
(
scheduler
).
schedule
(
with
(
any
(
Runnable
.
class
)),
oneOf
(
scheduler
).
schedule
(
with
(
any
(
Runnable
.
class
)),
with
(
RENDEZVOUS_TIMEOUT_MS
),
with
(
MILLISECONDS
));
with
(
RENDEZVOUS_TIMEOUT_MS
),
with
(
MILLISECONDS
));
oneOf
(
db
).
transactionWithResult
(
with
(
true
),
withDbCallable
(
txn
));
}});
will
(
returnValue
(
handshakeKeyPair
));
oneOf
(
transportCrypto
).
deriveStaticMasterKey
(
expectDeriveRendezvousKey
();
pendingContact
.
getPublicKey
(),
handshakeKeyPair
);
expectCreateEndpoint
();
will
(
returnValue
(
staticMasterKey
));
oneOf
(
rendezvousCrypto
).
deriveRendezvousKey
(
staticMasterKey
);
context
.
checking
(
new
Expectations
()
{{
will
(
returnValue
(
rendezvousKey
));
oneOf
(
transportCrypto
).
isAlice
(
pendingContact
.
getPublicKey
(),
handshakeKeyPair
);
will
(
returnValue
(
alice
));
oneOf
(
rendezvousCrypto
).
createKeyMaterialSource
(
rendezvousKey
,
transportId
);
will
(
returnValue
(
keyMaterialSource
));
oneOf
(
plugin
).
createRendezvousEndpoint
(
with
(
keyMaterialSource
),
with
(
alice
),
with
(
any
(
ConnectionHandler
.
class
)));
will
(
returnValue
(
rendezvousEndpoint
));
// Poll newly added pending contact
// Poll newly added pending contact
oneOf
(
rendezvousEndpoint
).
getRemoteTransportProperties
();
oneOf
(
rendezvousEndpoint
).
getRemoteTransportProperties
();
will
(
returnValue
(
transportProperties
));
will
(
returnValue
(
transportProperties
));
...
@@ -224,25 +196,17 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
...
@@ -224,25 +196,17 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
@Test
@Test
public
void
testCreatesAndClosesEndpointsWhenPendingContactIsAddedAndExpired
()
public
void
testCreatesAndClosesEndpointsWhenPendingContactIsAddedAndExpired
()
throws
Exception
{
throws
Exception
{
Transaction
txn
=
new
Transaction
(
null
,
true
);
long
now
=
pendingContact
.
getTimestamp
();
long
now
=
pendingContact
.
getTimestamp
();
AtomicReference
<
Runnable
>
captureExpiryTask
=
new
AtomicReference
<>();
AtomicReference
<
Runnable
>
captureExpiryTask
=
new
AtomicReference
<>();
// Enable the transport - no endpoints should be created yet
// Enable the transport - no endpoints should be created yet
context
.
checking
(
new
Expectations
()
{{
expectGetPlugin
();
oneOf
(
pluginManager
).
getPlugin
(
transportId
);
will
(
returnValue
(
plugin
));
oneOf
(
plugin
).
supportsRendezvous
();
will
(
returnValue
(
true
));
allowing
(
plugin
).
getId
();
will
(
returnValue
(
transportId
));
}});
rendezvousPoller
.
eventOccurred
(
new
TransportEnabledEvent
(
transportId
));
rendezvousPoller
.
eventOccurred
(
new
TransportEnabledEvent
(
transportId
));
context
.
assertIsSatisfied
();
context
.
assertIsSatisfied
();
// Add the pending contact - endpoint should be created and polled
// Add the pending contact - endpoint should be created and polled
context
.
checking
(
new
Db
Expectations
()
{{
context
.
checking
(
new
Expectations
()
{{
// Add pending contact
// Add pending contact
oneOf
(
clock
).
currentTimeMillis
();
oneOf
(
clock
).
currentTimeMillis
();
will
(
returnValue
(
now
));
will
(
returnValue
(
now
));
...
@@ -251,22 +215,12 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
...
@@ -251,22 +215,12 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
with
(
RENDEZVOUS_TIMEOUT_MS
),
with
(
MILLISECONDS
));
with
(
RENDEZVOUS_TIMEOUT_MS
),
with
(
MILLISECONDS
));
will
(
new
CaptureArgumentAction
<>(
captureExpiryTask
,
Runnable
.
class
,
will
(
new
CaptureArgumentAction
<>(
captureExpiryTask
,
Runnable
.
class
,
0
));
0
));
oneOf
(
db
).
transactionWithResult
(
with
(
true
),
withDbCallable
(
txn
));
}});
will
(
returnValue
(
handshakeKeyPair
));
oneOf
(
transportCrypto
).
deriveStaticMasterKey
(
expectDeriveRendezvousKey
();
pendingContact
.
getPublicKey
(),
handshakeKeyPair
);
expectCreateEndpoint
();
will
(
returnValue
(
staticMasterKey
));
oneOf
(
rendezvousCrypto
).
deriveRendezvousKey
(
staticMasterKey
);
context
.
checking
(
new
Expectations
()
{{
will
(
returnValue
(
rendezvousKey
));
oneOf
(
transportCrypto
).
isAlice
(
pendingContact
.
getPublicKey
(),
handshakeKeyPair
);
will
(
returnValue
(
alice
));
oneOf
(
rendezvousCrypto
).
createKeyMaterialSource
(
rendezvousKey
,
transportId
);
will
(
returnValue
(
keyMaterialSource
));
oneOf
(
plugin
).
createRendezvousEndpoint
(
with
(
keyMaterialSource
),
with
(
alice
),
with
(
any
(
ConnectionHandler
.
class
)));
will
(
returnValue
(
rendezvousEndpoint
));
// Poll newly added pending contact
// Poll newly added pending contact
oneOf
(
rendezvousEndpoint
).
getRemoteTransportProperties
();
oneOf
(
rendezvousEndpoint
).
getRemoteTransportProperties
();
will
(
returnValue
(
transportProperties
));
will
(
returnValue
(
transportProperties
));
...
@@ -300,7 +254,6 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
...
@@ -300,7 +254,6 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
@Test
@Test
public
void
testCreatesAndClosesEndpointsWhenTransportIsEnabledAndDisabled
()
public
void
testCreatesAndClosesEndpointsWhenTransportIsEnabledAndDisabled
()
throws
Exception
{
throws
Exception
{
Transaction
txn
=
new
Transaction
(
null
,
true
);
long
now
=
pendingContact
.
getTimestamp
();
long
now
=
pendingContact
.
getTimestamp
();
// Add the pending contact - no endpoints should be created yet
// Add the pending contact - no endpoints should be created yet
...
@@ -309,6 +262,38 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
...
@@ -309,6 +262,38 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
will
(
returnValue
(
now
));
will
(
returnValue
(
now
));
oneOf
(
scheduler
).
schedule
(
with
(
any
(
Runnable
.
class
)),
oneOf
(
scheduler
).
schedule
(
with
(
any
(
Runnable
.
class
)),
with
(
RENDEZVOUS_TIMEOUT_MS
),
with
(
MILLISECONDS
));
with
(
RENDEZVOUS_TIMEOUT_MS
),
with
(
MILLISECONDS
));
}});
expectDeriveRendezvousKey
();
rendezvousPoller
.
eventOccurred
(
new
PendingContactAddedEvent
(
pendingContact
));
context
.
assertIsSatisfied
();
// Enable the transport - endpoint should be created
expectGetPlugin
();
expectCreateEndpoint
();
rendezvousPoller
.
eventOccurred
(
new
TransportEnabledEvent
(
transportId
));
context
.
assertIsSatisfied
();
// Disable the transport - endpoint should be closed
context
.
checking
(
new
Expectations
()
{{
oneOf
(
rendezvousEndpoint
).
close
();
}});
rendezvousPoller
.
eventOccurred
(
new
TransportDisabledEvent
(
transportId
));
context
.
assertIsSatisfied
();
// Remove the pending contact - endpoint is already closed
rendezvousPoller
.
eventOccurred
(
new
PendingContactRemovedEvent
(
pendingContact
.
getId
()));
}
private
void
expectDeriveRendezvousKey
()
throws
Exception
{
Transaction
txn
=
new
Transaction
(
null
,
true
);
context
.
checking
(
new
DbExpectations
()
{{
oneOf
(
db
).
transactionWithResult
(
with
(
true
),
withDbCallable
(
txn
));
oneOf
(
db
).
transactionWithResult
(
with
(
true
),
withDbCallable
(
txn
));
will
(
returnValue
(
handshakeKeyPair
));
will
(
returnValue
(
handshakeKeyPair
));
oneOf
(
transportCrypto
).
deriveStaticMasterKey
(
oneOf
(
transportCrypto
).
deriveStaticMasterKey
(
...
@@ -320,19 +305,10 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
...
@@ -320,19 +305,10 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
handshakeKeyPair
);
handshakeKeyPair
);
will
(
returnValue
(
alice
));
will
(
returnValue
(
alice
));
}});
}});
}
rendezvousPoller
.
eventOccurred
(
private
void
expectCreateEndpoint
()
{
new
PendingContactAddedEvent
(
pendingContact
));
context
.
assertIsSatisfied
();
// Enable the transport - endpoint should be created
context
.
checking
(
new
Expectations
()
{{
context
.
checking
(
new
Expectations
()
{{
oneOf
(
pluginManager
).
getPlugin
(
transportId
);
will
(
returnValue
(
plugin
));
oneOf
(
plugin
).
supportsRendezvous
();
will
(
returnValue
(
true
));
allowing
(
plugin
).
getId
();
will
(
returnValue
(
transportId
));
oneOf
(
rendezvousCrypto
).
createKeyMaterialSource
(
rendezvousKey
,
oneOf
(
rendezvousCrypto
).
createKeyMaterialSource
(
rendezvousKey
,
transportId
);
transportId
);
will
(
returnValue
(
keyMaterialSource
));
will
(
returnValue
(
keyMaterialSource
));
...
@@ -340,20 +316,16 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
...
@@ -340,20 +316,16 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
with
(
alice
),
with
(
any
(
ConnectionHandler
.
class
)));
with
(
alice
),
with
(
any
(
ConnectionHandler
.
class
)));
will
(
returnValue
(
rendezvousEndpoint
));
will
(
returnValue
(
rendezvousEndpoint
));
}});
}});
}
rendezvousPoller
.
eventOccurred
(
new
TransportEnabledEvent
(
transportId
));
private
void
expectGetPlugin
()
{
context
.
assertIsSatisfied
();
// Disable the transport - endpoint should be closed
context
.
checking
(
new
Expectations
()
{{
context
.
checking
(
new
Expectations
()
{{
oneOf
(
rendezvousEndpoint
).
close
();
oneOf
(
pluginManager
).
getPlugin
(
transportId
);
will
(
returnValue
(
plugin
));
oneOf
(
plugin
).
supportsRendezvous
();
will
(
returnValue
(
true
));
allowing
(
plugin
).
getId
();
will
(
returnValue
(
transportId
));
}});
}});
rendezvousPoller
.
eventOccurred
(
new
TransportDisabledEvent
(
transportId
));
context
.
assertIsSatisfied
();
// Remove the pending contact - endpoint is already closed
rendezvousPoller
.
eventOccurred
(
new
PendingContactRemovedEvent
(
pendingContact
.
getId
()));
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment