mirror of
https://github.com/corda/corda.git
synced 2025-01-18 18:56:28 +00:00
node-driver: Polling doesn't timeout, just prints warning
This commit is contained in:
parent
9cbdf001fb
commit
5f33bedc13
@ -154,7 +154,7 @@ private fun getTimestampAsDirectoryName(): String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addressMustBeBound(hostAndPort: HostAndPort) {
|
fun addressMustBeBound(hostAndPort: HostAndPort) {
|
||||||
poll {
|
poll("address $hostAndPort to bind") {
|
||||||
try {
|
try {
|
||||||
Socket(hostAndPort.hostText, hostAndPort.port).close()
|
Socket(hostAndPort.hostText, hostAndPort.port).close()
|
||||||
Unit
|
Unit
|
||||||
@ -165,7 +165,7 @@ fun addressMustBeBound(hostAndPort: HostAndPort) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addressMustNotBeBound(hostAndPort: HostAndPort) {
|
fun addressMustNotBeBound(hostAndPort: HostAndPort) {
|
||||||
poll {
|
poll("address $hostAndPort to unbind") {
|
||||||
try {
|
try {
|
||||||
Socket(hostAndPort.hostText, hostAndPort.port).close()
|
Socket(hostAndPort.hostText, hostAndPort.port).close()
|
||||||
null
|
null
|
||||||
@ -175,16 +175,16 @@ fun addressMustNotBeBound(hostAndPort: HostAndPort) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <A> poll(f: () -> A?): A {
|
fun <A> poll(pollName: String, pollIntervalMs: Long = 500, warnCount: Int = 120, f: () -> A?): A {
|
||||||
var counter = 0
|
var counter = 0
|
||||||
var result = f()
|
var result = f()
|
||||||
while (result == null && counter < 120) {
|
while (result == null) {
|
||||||
counter++
|
if (counter == warnCount) {
|
||||||
Thread.sleep(500)
|
log.warn("Been polling $pollName for ${pollIntervalMs * warnCount / 1000.0} seconds...")
|
||||||
result = f()
|
|
||||||
}
|
}
|
||||||
if (result == null) {
|
counter = (counter % warnCount) + 1
|
||||||
throw Exception("Poll timed out")
|
Thread.sleep(pollIntervalMs)
|
||||||
|
result = f()
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -326,7 +326,7 @@ class DriverDSL(
|
|||||||
advertisedServices = setOf(NetworkMapService.Type)
|
advertisedServices = setOf(NetworkMapService.Type)
|
||||||
)
|
)
|
||||||
networkMapCache.addMapService(messagingService, fakeNodeInfo, true)
|
networkMapCache.addMapService(messagingService, fakeNodeInfo, true)
|
||||||
networkMapNodeInfo = poll {
|
networkMapNodeInfo = poll("network map cache for $networkMapName") {
|
||||||
networkMapCache.partyNodes.forEach {
|
networkMapCache.partyNodes.forEach {
|
||||||
if (it.identity.name == networkMapName) {
|
if (it.identity.name == networkMapName) {
|
||||||
return@poll it
|
return@poll it
|
||||||
|
@ -13,7 +13,7 @@ class DriverTests {
|
|||||||
fun nodeMustBeUp(networkMapCache: NetworkMapCache, nodeInfo: NodeInfo, nodeName: String) {
|
fun nodeMustBeUp(networkMapCache: NetworkMapCache, nodeInfo: NodeInfo, nodeName: String) {
|
||||||
val address = nodeInfo.address as ArtemisMessagingComponent.Address
|
val address = nodeInfo.address as ArtemisMessagingComponent.Address
|
||||||
// Check that the node is registered in the network map
|
// Check that the node is registered in the network map
|
||||||
poll {
|
poll("network map cache for $nodeName") {
|
||||||
networkMapCache.get().firstOrNull {
|
networkMapCache.get().firstOrNull {
|
||||||
it.identity.name == nodeName
|
it.identity.name == nodeName
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user