return successful peers in rejection suggestion
This commit is contained in:
@@ -144,7 +144,7 @@ class ConnectionAcceptor {
|
|||||||
} else {
|
} else {
|
||||||
log.info("rejecting connection, leaf:$leaf")
|
log.info("rejecting connection, leaf:$leaf")
|
||||||
e.outputStream.write("REJECT".bytes)
|
e.outputStream.write("REJECT".bytes)
|
||||||
def hosts = hostCache.getHosts(10)
|
def hosts = hostCache.getGoodHosts(10)
|
||||||
if (!hosts.isEmpty()) {
|
if (!hosts.isEmpty()) {
|
||||||
def json = [:]
|
def json = [:]
|
||||||
json.tryHosts = hosts.collect { d -> d.toBase64() }
|
json.tryHosts = hosts.collect { d -> d.toBase64() }
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ class ConnectionAcceptorTest {
|
|||||||
assert dest == destinations.dest1
|
assert dest == destinations.dest1
|
||||||
TrustLevel.TRUSTED
|
TrustLevel.TRUSTED
|
||||||
}
|
}
|
||||||
hostCacheMock.ignore.getHosts { n -> [] }
|
hostCacheMock.ignore.getGoodHosts { n -> [] }
|
||||||
|
|
||||||
initMocks()
|
initMocks()
|
||||||
|
|
||||||
@@ -289,7 +289,7 @@ class ConnectionAcceptorTest {
|
|||||||
assert dest == destinations.dest1
|
assert dest == destinations.dest1
|
||||||
TrustLevel.TRUSTED
|
TrustLevel.TRUSTED
|
||||||
}
|
}
|
||||||
hostCacheMock.ignore.getHosts { n -> [] }
|
hostCacheMock.ignore.getGoodHosts { n -> [] }
|
||||||
|
|
||||||
initMocks()
|
initMocks()
|
||||||
|
|
||||||
@@ -331,7 +331,7 @@ class ConnectionAcceptorTest {
|
|||||||
assert dest == destinations.dest1
|
assert dest == destinations.dest1
|
||||||
TrustLevel.TRUSTED
|
TrustLevel.TRUSTED
|
||||||
}
|
}
|
||||||
hostCacheMock.ignore.getHosts { n -> [destinations.dest2] }
|
hostCacheMock.ignore.getGoodHosts { n -> [destinations.dest2] }
|
||||||
|
|
||||||
initMocks()
|
initMocks()
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class HostCacheTest {
|
|||||||
cache?.stop()
|
cache?.stop()
|
||||||
trustMock.verify trust
|
trustMock.verify trust
|
||||||
settingsMock.verify settings
|
settingsMock.verify settings
|
||||||
|
Thread.sleep(150)
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMocks() {
|
private void initMocks() {
|
||||||
@@ -61,20 +62,16 @@ class HostCacheTest {
|
|||||||
void testEmpty() {
|
void testEmpty() {
|
||||||
initMocks()
|
initMocks()
|
||||||
assert cache.getHosts(5).size() == 0
|
assert cache.getHosts(5).size() == 0
|
||||||
|
assert cache.getGoodHosts(5).size() == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOnDiscoveredEvent() {
|
void testOnDiscoveredEvent() {
|
||||||
trustMock.demand.getLevel { d ->
|
trustMock.ignore.getLevel { d ->
|
||||||
assert d == destinations.dest1
|
assert d == destinations.dest1
|
||||||
TrustLevel.NEUTRAL
|
TrustLevel.NEUTRAL
|
||||||
}
|
}
|
||||||
trustMock.demand.getLevel { d ->
|
settingsMock.ignore.allowUntrusted { true }
|
||||||
assert d == destinations.dest1
|
|
||||||
TrustLevel.NEUTRAL
|
|
||||||
}
|
|
||||||
settingsMock.demand.allowUntrusted { true }
|
|
||||||
settingsMock.demand.allowUntrusted { true }
|
|
||||||
|
|
||||||
initMocks()
|
initMocks()
|
||||||
|
|
||||||
@@ -83,6 +80,8 @@ class HostCacheTest {
|
|||||||
def rv = cache.getHosts(5)
|
def rv = cache.getHosts(5)
|
||||||
assert rv.size() == 1
|
assert rv.size() == 1
|
||||||
assert rv.contains(destinations.dest1)
|
assert rv.contains(destinations.dest1)
|
||||||
|
|
||||||
|
assert cache.getGoodHosts(5).size() == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -154,11 +153,7 @@ class HostCacheTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFailedHostSuceeds() {
|
void testFailedHostSuceeds() {
|
||||||
trustMock.demand.getLevel { d ->
|
trustMock.ignore.getLevel { d ->
|
||||||
assert d == destinations.dest1
|
|
||||||
TrustLevel.TRUSTED
|
|
||||||
}
|
|
||||||
trustMock.demand.getLevel { d ->
|
|
||||||
assert d == destinations.dest1
|
assert d == destinations.dest1
|
||||||
TrustLevel.TRUSTED
|
TrustLevel.TRUSTED
|
||||||
}
|
}
|
||||||
@@ -171,13 +166,42 @@ class HostCacheTest {
|
|||||||
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED))
|
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED))
|
||||||
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED))
|
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED))
|
||||||
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.SUCCESSFUL))
|
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.SUCCESSFUL))
|
||||||
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED))
|
|
||||||
|
|
||||||
def rv = cache.getHosts(5)
|
def rv = cache.getHosts(5)
|
||||||
assert rv.size() == 1
|
assert rv.size() == 1
|
||||||
assert rv.contains(destinations.dest1)
|
assert rv.contains(destinations.dest1)
|
||||||
|
|
||||||
|
rv = cache.getGoodHosts(5)
|
||||||
|
assert rv.size() == 1
|
||||||
|
assert rv.contains(destinations.dest1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testFailedOnceNoLongerGood() {
|
||||||
|
trustMock.ignore.getLevel { d ->
|
||||||
|
assert d == destinations.dest1
|
||||||
|
TrustLevel.TRUSTED
|
||||||
|
}
|
||||||
|
|
||||||
|
initMocks()
|
||||||
|
cache.onHostDiscoveredEvent(new HostDiscoveredEvent(destination: destinations.dest1))
|
||||||
|
|
||||||
|
def endpoint = new Endpoint(destinations.dest1, null, null)
|
||||||
|
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.SUCCESSFUL))
|
||||||
|
|
||||||
|
def rv = cache.getHosts(5)
|
||||||
|
def rv2 = cache.getGoodHosts(5)
|
||||||
|
assert rv.size() == 1
|
||||||
|
assert rv.contains(destinations.dest1)
|
||||||
|
assert rv == rv2
|
||||||
|
|
||||||
|
cache.onConnectionEvent( new ConnectionEvent(endpoint: endpoint, status: ConnectionAttemptStatus.FAILED))
|
||||||
|
|
||||||
|
rv = cache.getHosts(5)
|
||||||
|
assert rv.size() == 1
|
||||||
|
assert rv.contains(destinations.dest1)
|
||||||
|
assert cache.getGoodHosts(5).size() == 0
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDuplicateHostDiscovered() {
|
void testDuplicateHostDiscovered() {
|
||||||
@@ -217,6 +241,7 @@ class HostCacheTest {
|
|||||||
def json = slurper.parseText(it)
|
def json = slurper.parseText(it)
|
||||||
assert json.destination == destinations.dest1.toBase64()
|
assert json.destination == destinations.dest1.toBase64()
|
||||||
assert json.failures == 0
|
assert json.failures == 0
|
||||||
|
assert json.successes == 0
|
||||||
}
|
}
|
||||||
assert lines == 1
|
assert lines == 1
|
||||||
}
|
}
|
||||||
@@ -226,6 +251,7 @@ class HostCacheTest {
|
|||||||
def json = [:]
|
def json = [:]
|
||||||
json.destination = destinations.dest1.toBase64()
|
json.destination = destinations.dest1.toBase64()
|
||||||
json.failures = 0
|
json.failures = 0
|
||||||
|
json.successes = 1
|
||||||
json = JsonOutput.toJson(json)
|
json = JsonOutput.toJson(json)
|
||||||
persist.append("${json}\n")
|
persist.append("${json}\n")
|
||||||
|
|
||||||
@@ -239,6 +265,6 @@ class HostCacheTest {
|
|||||||
assert rv.size() == 1
|
assert rv.size() == 1
|
||||||
assert rv.contains(destinations.dest1)
|
assert rv.contains(destinations.dest1)
|
||||||
|
|
||||||
|
assert cache.getGoodHosts(5) == rv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user