mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 14:49:53 +01:00
Fix bug in reporting of connection state, add regression tests.
This commit is contained in:
@@ -214,7 +214,8 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isConnected(ContactId c) {
|
public boolean isConnected(ContactId c) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
return contactConnections.containsKey(c);
|
List<ConnectionRecord> recs = contactConnections.get(c);
|
||||||
|
return recs != null && !recs.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,10 @@ public class ConnectionRegistryImplTest extends BrambleMockTestCase {
|
|||||||
assertEquals(emptyList(), c.getConnectedOrBetterContacts(transportId2));
|
assertEquals(emptyList(), c.getConnectedOrBetterContacts(transportId2));
|
||||||
assertEquals(emptyList(), c.getConnectedContacts(transportId3));
|
assertEquals(emptyList(), c.getConnectedContacts(transportId3));
|
||||||
assertEquals(emptyList(), c.getConnectedOrBetterContacts(transportId3));
|
assertEquals(emptyList(), c.getConnectedOrBetterContacts(transportId3));
|
||||||
|
assertFalse(c.isConnected(contactId1));
|
||||||
|
assertFalse(c.isConnected(contactId1, transportId1));
|
||||||
|
assertFalse(c.isConnected(contactId1, transportId2));
|
||||||
|
assertFalse(c.isConnected(contactId1, transportId3));
|
||||||
|
|
||||||
// Check that a registered connection shows up - this should
|
// Check that a registered connection shows up - this should
|
||||||
// broadcast a ConnectionOpenedEvent and a ContactConnectedEvent
|
// broadcast a ConnectionOpenedEvent and a ContactConnectedEvent
|
||||||
@@ -88,6 +92,8 @@ public class ConnectionRegistryImplTest extends BrambleMockTestCase {
|
|||||||
c.getConnectedContacts(transportId1));
|
c.getConnectedContacts(transportId1));
|
||||||
assertEquals(singletonList(contactId1),
|
assertEquals(singletonList(contactId1),
|
||||||
c.getConnectedOrBetterContacts(transportId1));
|
c.getConnectedOrBetterContacts(transportId1));
|
||||||
|
assertTrue(c.isConnected(contactId1));
|
||||||
|
assertTrue(c.isConnected(contactId1, transportId1));
|
||||||
|
|
||||||
// Register another connection with the same contact and transport -
|
// Register another connection with the same contact and transport -
|
||||||
// this should broadcast a ConnectionOpenedEvent and lookup should be
|
// this should broadcast a ConnectionOpenedEvent and lookup should be
|
||||||
@@ -102,6 +108,8 @@ public class ConnectionRegistryImplTest extends BrambleMockTestCase {
|
|||||||
c.getConnectedContacts(transportId1));
|
c.getConnectedContacts(transportId1));
|
||||||
assertEquals(singletonList(contactId1),
|
assertEquals(singletonList(contactId1),
|
||||||
c.getConnectedOrBetterContacts(transportId1));
|
c.getConnectedOrBetterContacts(transportId1));
|
||||||
|
assertTrue(c.isConnected(contactId1));
|
||||||
|
assertTrue(c.isConnected(contactId1, transportId1));
|
||||||
|
|
||||||
// Unregister one of the connections - this should broadcast a
|
// Unregister one of the connections - this should broadcast a
|
||||||
// ConnectionClosedEvent and lookup should be unaffected
|
// ConnectionClosedEvent and lookup should be unaffected
|
||||||
@@ -115,6 +123,8 @@ public class ConnectionRegistryImplTest extends BrambleMockTestCase {
|
|||||||
c.getConnectedContacts(transportId1));
|
c.getConnectedContacts(transportId1));
|
||||||
assertEquals(singletonList(contactId1),
|
assertEquals(singletonList(contactId1),
|
||||||
c.getConnectedOrBetterContacts(transportId1));
|
c.getConnectedOrBetterContacts(transportId1));
|
||||||
|
assertTrue(c.isConnected(contactId1));
|
||||||
|
assertTrue(c.isConnected(contactId1, transportId1));
|
||||||
|
|
||||||
// Unregister the other connection - this should broadcast a
|
// Unregister the other connection - this should broadcast a
|
||||||
// ConnectionClosedEvent and a ContactDisconnectedEvent
|
// ConnectionClosedEvent and a ContactDisconnectedEvent
|
||||||
@@ -128,6 +138,8 @@ public class ConnectionRegistryImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
|
assertEquals(emptyList(), c.getConnectedContacts(transportId1));
|
||||||
assertEquals(emptyList(), c.getConnectedOrBetterContacts(transportId1));
|
assertEquals(emptyList(), c.getConnectedOrBetterContacts(transportId1));
|
||||||
|
assertFalse(c.isConnected(contactId1));
|
||||||
|
assertFalse(c.isConnected(contactId1, transportId1));
|
||||||
|
|
||||||
// Try to unregister the connection again - exception should be thrown
|
// Try to unregister the connection again - exception should be thrown
|
||||||
try {
|
try {
|
||||||
@@ -163,6 +175,15 @@ public class ConnectionRegistryImplTest extends BrambleMockTestCase {
|
|||||||
c.registerConnection(contactId2, transportId2, conn3, true);
|
c.registerConnection(contactId2, transportId2, conn3, true);
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
|
|
||||||
|
assertTrue(c.isConnected(contactId1));
|
||||||
|
assertTrue(c.isConnected(contactId2));
|
||||||
|
|
||||||
|
assertTrue(c.isConnected(contactId1, transportId1));
|
||||||
|
assertFalse(c.isConnected(contactId1, transportId2));
|
||||||
|
|
||||||
|
assertTrue(c.isConnected(contactId2, transportId1));
|
||||||
|
assertTrue(c.isConnected(contactId2, transportId2));
|
||||||
|
|
||||||
Collection<ContactId> connected = c.getConnectedContacts(transportId1);
|
Collection<ContactId> connected = c.getConnectedContacts(transportId1);
|
||||||
assertEquals(2, connected.size());
|
assertEquals(2, connected.size());
|
||||||
assertTrue(connected.contains(contactId1));
|
assertTrue(connected.contains(contactId1));
|
||||||
|
|||||||
Reference in New Issue
Block a user