Merged in rog-timeout-patch (pull request #322)

waitForNodeStartup should now throw after 2 minutes rather than 20 seconds. Some bank devs were finding integration tests failing as nodes had still not started...

Added getFreeLocalPorts() for grabbing more than one port. Fixes bug in freeLocalHostAndPort() where the same port can be picked multiple times.

In README.md instruct users to grab IntelliJ16 instead of 15.
This commit is contained in:
Roger Willis 2016-09-05 16:06:05 +01:00
commit a4d2b28b6b
4 changed files with 30 additions and 6 deletions

View File

@ -42,7 +42,7 @@ Install the Oracle JDK 8u45 or higher. It is possible that OpenJDK will also wor
## Using IntelliJ
It's a good idea to use a modern IDE. We use IntelliJ. Install IntelliJ version 15 community edition (which is free):
It's a good idea to use a modern IDE. We use IntelliJ. Install the __latest version__ of IntelliJ community edition (which is free):
https://www.jetbrains.com/idea/download/

View File

@ -9,9 +9,11 @@ import java.nio.file.Paths
class IRSDemoTest: IntegrationTestCategory {
@Test fun `runs IRS demo`() {
val nodeAddrA = freeLocalHostAndPort()
val apiAddrA = freeLocalHostAndPort()
val apiAddrB = freeLocalHostAndPort()
val hostAndPorts = getFreeLocalPorts("localhost", 4)
val nodeAddrA = hostAndPorts[0]
val apiAddrA = hostAndPorts[1]
val apiAddrB = hostAndPorts[2]
val baseDirectory = Paths.get("./build/integration-test/${TestTimestamp.timestamp}/irs-demo")
var procA: Process? = null
@ -29,7 +31,7 @@ class IRSDemoTest: IntegrationTestCategory {
procB = startNode(
baseDirectory = baseDirectory,
nodeType = "NodeB",
nodeAddr = freeLocalHostAndPort(),
nodeAddr = hostAndPorts[3],
networkMapAddr = nodeAddrA,
apiAddr = apiAddrB
)

View File

@ -75,11 +75,32 @@ inline fun <R> rootCauseExceptions(body: () -> R): R {
}
}
/**
* Returns a free port.
*
* Unsafe for getting multiple ports!
* Use [getFreeLocalPorts] for getting multiple ports.
*/
fun freeLocalHostAndPort(): HostAndPort {
val freePort = ServerSocket(0).use { it.localPort }
return HostAndPort.fromParts("localhost", freePort)
}
/**
* Creates a specified number of ports for use by the Node.
*
* Unlikely, but in the time between running this function and handing the ports
* to the Node, some other process else could allocate the returned ports.
*/
fun getFreeLocalPorts(hostName: String, numberToAlloc: Int): List<HostAndPort> {
// Create a bunch of sockets up front.
val sockets = Array(numberToAlloc) { ServerSocket(0) }
val result = sockets.map { HostAndPort.fromParts(hostName, it.localPort) }
// Close sockets only once we've grabbed all the ports we need.
sockets.forEach(ServerSocket::close)
return result
}
/**
* Creates and tests a ledger built by the passed in dsl. The provided services can be customised, otherwise a default
* of a freshly built [MockServices] is used.

View File

@ -13,7 +13,8 @@ class NodeApi {
class NodeDidNotStartException(message: String): Exception(message)
companion object {
val NODE_WAIT_RETRY_COUNT: Int = 100
// Increased timeout to two minutes.
val NODE_WAIT_RETRY_COUNT: Int = 600
val NODE_WAIT_RETRY_DELAY_MS: Long = 200
fun ensureNodeStartsOrKill(proc: Process, nodeWebserverAddr: HostAndPort) {