mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
Ports now randomised during demo tests.
This commit is contained in:
committed by
Andras Slemmer
parent
b52f344eb3
commit
4900c7eb26
@ -18,8 +18,8 @@ class IRSDemoTest {
|
|||||||
try {
|
try {
|
||||||
setupNode(dirA, "NodeA")
|
setupNode(dirA, "NodeA")
|
||||||
setupNode(dirB, "NodeB")
|
setupNode(dirB, "NodeB")
|
||||||
procA = startNode(dirA, "NodeA", nodeAddrA)
|
procA = startNode(dirA, "NodeA", nodeAddrA, nodeAddrA)
|
||||||
procB = startNode(dirB, "NodeB", freeLocalHostAndPort())
|
procB = startNode(dirB, "NodeB", freeLocalHostAndPort(), nodeAddrA)
|
||||||
runTrade(apiAddrA)
|
runTrade(apiAddrA)
|
||||||
runDateChange(apiAddrA)
|
runDateChange(apiAddrA)
|
||||||
} finally {
|
} finally {
|
||||||
@ -33,16 +33,20 @@ class IRSDemoTest {
|
|||||||
private fun setupNode(dir: Path, nodeType: String) {
|
private fun setupNode(dir: Path, nodeType: String) {
|
||||||
println("Running setup for $nodeType")
|
println("Running setup for $nodeType")
|
||||||
val args = listOf("--role", "Setup" + nodeType, "--dir", dir.toString())
|
val args = listOf("--role", "Setup" + nodeType, "--dir", dir.toString())
|
||||||
val proc = spawn("com.r3corda.demos.IRSDemoKt", args)
|
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemoSetup$nodeType")
|
||||||
assertExitOrKill(proc)
|
assertExitOrKill(proc)
|
||||||
assertEquals(proc.exitValue(), 0)
|
assertEquals(proc.exitValue(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startNode(dir: Path, nodeType: String, nodeAddr: HostAndPort): Process {
|
private fun startNode(dir: Path, nodeType: String, nodeAddr: HostAndPort, networkMapAddr: HostAndPort): Process {
|
||||||
println("Running node $nodeType")
|
println("Running node $nodeType")
|
||||||
println("Node addr: ${nodeAddr.toString()}")
|
println("Node addr: ${nodeAddr.toString()}")
|
||||||
val args = listOf("--role", nodeType, "--dir", dir.toString(), "--network-address", nodeAddr.toString())
|
val args = listOf(
|
||||||
val proc = spawn("com.r3corda.demos.IRSDemoKt", args)
|
"--role", nodeType,
|
||||||
|
"--dir", dir.toString(),
|
||||||
|
"--network-address", nodeAddr.toString(),
|
||||||
|
"--network-map-address", networkMapAddr.toString())
|
||||||
|
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemo$nodeType")
|
||||||
ensureNodeStartsOrKill(proc, nodeAddr)
|
ensureNodeStartsOrKill(proc, nodeAddr)
|
||||||
return proc
|
return proc
|
||||||
}
|
}
|
||||||
@ -50,7 +54,7 @@ private fun startNode(dir: Path, nodeType: String, nodeAddr: HostAndPort): Proce
|
|||||||
private fun runTrade(nodeAddr: HostAndPort) {
|
private fun runTrade(nodeAddr: HostAndPort) {
|
||||||
println("Running trade")
|
println("Running trade")
|
||||||
val args = listOf("--role", "Trade", "trade1", "--network-address", "http://" + nodeAddr.toString())
|
val args = listOf("--role", "Trade", "trade1", "--network-address", "http://" + nodeAddr.toString())
|
||||||
val proc = spawn("com.r3corda.demos.IRSDemoKt", args)
|
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemoTrade")
|
||||||
assertExitOrKill(proc)
|
assertExitOrKill(proc)
|
||||||
assertEquals(proc.exitValue(), 0)
|
assertEquals(proc.exitValue(), 0)
|
||||||
}
|
}
|
||||||
@ -58,7 +62,7 @@ private fun runTrade(nodeAddr: HostAndPort) {
|
|||||||
private fun runDateChange(nodeAddr: HostAndPort) {
|
private fun runDateChange(nodeAddr: HostAndPort) {
|
||||||
println("Running date change")
|
println("Running date change")
|
||||||
val args = listOf("--role", "Date", "2017-01-02", "--network-address", "http://" + nodeAddr.toString())
|
val args = listOf("--role", "Date", "2017-01-02", "--network-address", "http://" + nodeAddr.toString())
|
||||||
val proc = spawn("com.r3corda.demos.IRSDemoKt", args)
|
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemoDate")
|
||||||
assertExitOrKill(proc)
|
assertExitOrKill(proc)
|
||||||
assertEquals(proc.exitValue(), 0)
|
assertEquals(proc.exitValue(), 0)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.r3corda.core.testing
|
package com.r3corda.core.testing
|
||||||
|
|
||||||
|
import com.google.common.net.HostAndPort
|
||||||
import com.r3corda.core.testing.utilities.assertExitOrKill
|
import com.r3corda.core.testing.utilities.assertExitOrKill
|
||||||
import com.r3corda.core.testing.utilities.ensureNodeStartsOrKill
|
import com.r3corda.core.testing.utilities.ensureNodeStartsOrKill
|
||||||
import com.r3corda.core.testing.utilities.spawn
|
import com.r3corda.core.testing.utilities.spawn
|
||||||
@ -9,11 +10,12 @@ import kotlin.test.assertEquals
|
|||||||
|
|
||||||
class TraderDemoTest {
|
class TraderDemoTest {
|
||||||
@Test fun `runs trader demo`() {
|
@Test fun `runs trader demo`() {
|
||||||
|
val buyerAddr = freeLocalHostAndPort()
|
||||||
var nodeProc: Process? = null
|
var nodeProc: Process? = null
|
||||||
try {
|
try {
|
||||||
cleanupFiles()
|
cleanupFiles()
|
||||||
nodeProc = runBuyer()
|
nodeProc = runBuyer(buyerAddr)
|
||||||
runSeller()
|
runSeller(buyerAddr)
|
||||||
} finally {
|
} finally {
|
||||||
nodeProc?.destroy()
|
nodeProc?.destroy()
|
||||||
cleanupFiles()
|
cleanupFiles()
|
||||||
@ -21,18 +23,22 @@ class TraderDemoTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runBuyer(): Process {
|
private fun runBuyer(buyerAddr: HostAndPort): Process {
|
||||||
println("Running Buyer")
|
println("Running Buyer")
|
||||||
val args = listOf("--role", "BUYER")
|
val args = listOf("--role", "BUYER", "--network-address", buyerAddr.toString())
|
||||||
val proc = spawn("com.r3corda.demos.TraderDemoKt", args)
|
val proc = spawn("com.r3corda.demos.TraderDemoKt", args, "TradeDemoBuyer")
|
||||||
ensureNodeStartsOrKill(proc, freeLocalHostAndPort())
|
ensureNodeStartsOrKill(proc, buyerAddr)
|
||||||
return proc
|
return proc
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runSeller() {
|
private fun runSeller(buyerAddr: HostAndPort) {
|
||||||
println("Running Seller")
|
println("Running Seller")
|
||||||
val args = listOf("--role", "SELLER")
|
val sellerAddr = freeLocalHostAndPort()
|
||||||
val proc = spawn("com.r3corda.demos.TraderDemoKt", args)
|
val args = listOf(
|
||||||
|
"--role", "SELLER",
|
||||||
|
"--network-address", sellerAddr.toString(),
|
||||||
|
"--other-network-address", buyerAddr.toString())
|
||||||
|
val proc = spawn("com.r3corda.demos.TraderDemoKt", args, "TradeDemoSeller")
|
||||||
assertExitOrKill(proc);
|
assertExitOrKill(proc);
|
||||||
assertEquals(proc.exitValue(), 0)
|
assertEquals(proc.exitValue(), 0)
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@ import java.nio.file.Paths
|
|||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
fun spawn(className: String, args: List<String>): Process {
|
fun spawn(className: String, args: List<String>, appName: String): Process {
|
||||||
val separator = System.getProperty("file.separator")
|
val separator = System.getProperty("file.separator")
|
||||||
val classpath = System.getProperty("java.class.path")
|
val classpath = System.getProperty("java.class.path")
|
||||||
val path = System.getProperty("java.home") + separator + "bin" + separator + "java"
|
val path = System.getProperty("java.home") + separator + "bin" + separator + "java"
|
||||||
val javaArgs = listOf(path, "-javaagent:lib/quasar.jar", "-cp", classpath, className)
|
val javaArgs = listOf(path, "-Dname=$appName", "-javaagent:lib/quasar.jar", "-cp", classpath, className)
|
||||||
val builder = ProcessBuilder(javaArgs + args)
|
val builder = ProcessBuilder(javaArgs + args)
|
||||||
builder.redirectError(Paths.get("error.$className.log").toFile())
|
builder.redirectError(Paths.get("error.$className.log").toFile())
|
||||||
builder.inheritIO()
|
builder.inheritIO()
|
||||||
|
@ -9,7 +9,7 @@ import java.net.HttpURLConnection
|
|||||||
import java.net.URL
|
import java.net.URL
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class NodeDidNotStartException: Throwable {
|
class NodeDidNotStartException: Exception {
|
||||||
constructor(message: String): super(message) {}
|
constructor(message: String): super(message) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ fun ensureNodeStartsOrKill(proc: Process, nodeAddr: HostAndPort) {
|
|||||||
try {
|
try {
|
||||||
assertEquals(proc.isAlive, true)
|
assertEquals(proc.isAlive, true)
|
||||||
waitForNodeStartup(nodeAddr)
|
waitForNodeStartup(nodeAddr)
|
||||||
} catch (e: Exception) {
|
} catch (e: Throwable) {
|
||||||
println("Forcibly killing node process")
|
println("Forcibly killing node process")
|
||||||
proc.destroyForcibly()
|
proc.destroyForcibly()
|
||||||
throw e
|
throw e
|
||||||
@ -47,7 +47,7 @@ private fun waitForNodeStartup(nodeAddr: HostAndPort) {
|
|||||||
"IOException: ${e.toString()}"
|
"IOException: ${e.toString()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if(retries > 50) {
|
if(retries > 25) {
|
||||||
throw NodeDidNotStartException("The node did not start: " + err)
|
throw NodeDidNotStartException("The node did not start: " + err)
|
||||||
}
|
}
|
||||||
} while (respCode != 200)
|
} while (respCode != 200)
|
||||||
|
@ -61,7 +61,7 @@ enum class IRSDemoRole {
|
|||||||
|
|
||||||
private class NodeParams() {
|
private class NodeParams() {
|
||||||
var dir : Path = Paths.get("")
|
var dir : Path = Paths.get("")
|
||||||
var address : String = ""
|
var address : HostAndPort = HostAndPort.fromString("localhost").withDefaultPort(Node.DEFAULT_PORT)
|
||||||
var mapAddress: String = ""
|
var mapAddress: String = ""
|
||||||
var identityFile: Path = Paths.get("")
|
var identityFile: Path = Paths.get("")
|
||||||
var tradeWithAddrs: List<String> = listOf()
|
var tradeWithAddrs: List<String> = listOf()
|
||||||
@ -235,7 +235,7 @@ private fun configureNodeParams(role: IRSDemoRole, args: DemoArgs, options: Opti
|
|||||||
nodeParams.dir = Paths.get(options.valueOf(args.dirArg))
|
nodeParams.dir = Paths.get(options.valueOf(args.dirArg))
|
||||||
}
|
}
|
||||||
if (options.has(args.networkAddressArg)) {
|
if (options.has(args.networkAddressArg)) {
|
||||||
nodeParams.address = options.valueOf(args.networkAddressArg)
|
nodeParams.address = HostAndPort.fromString(options.valueOf(args.networkAddressArg)).withDefaultPort(Node.DEFAULT_PORT)
|
||||||
}
|
}
|
||||||
nodeParams.identityFile = if (options.has(args.networkMapIdentityFile)) {
|
nodeParams.identityFile = if (options.has(args.networkMapIdentityFile)) {
|
||||||
Paths.get(options.valueOf(args.networkMapIdentityFile))
|
Paths.get(options.valueOf(args.networkMapIdentityFile))
|
||||||
@ -265,7 +265,8 @@ private fun runNode(nodeParams: NodeParams) : Unit {
|
|||||||
ExitServerProtocol.Handler.register(node)
|
ExitServerProtocol.Handler.register(node)
|
||||||
|
|
||||||
if(nodeParams.uploadRates) {
|
if(nodeParams.uploadRates) {
|
||||||
runUploadRates("http://localhost:31341")
|
val apiAddr = "http://${nodeParams.address.hostText}:${nodeParams.address.port + 1}";
|
||||||
|
runUploadRates(apiAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -283,8 +284,7 @@ private fun createRecipient(addr: String) : SingleMessageRecipient {
|
|||||||
private fun startNode(params : NodeParams, networkMap: SingleMessageRecipient, recipients: List<SingleMessageRecipient>) : Node {
|
private fun startNode(params : NodeParams, networkMap: SingleMessageRecipient, recipients: List<SingleMessageRecipient>) : Node {
|
||||||
val config = getNodeConfig(params)
|
val config = getNodeConfig(params)
|
||||||
val advertisedServices: Set<ServiceType>
|
val advertisedServices: Set<ServiceType>
|
||||||
val myNetAddr = HostAndPort.fromString(params.address).withDefaultPort(Node.DEFAULT_PORT)
|
val networkMapId = if (params.mapAddress.equals(params.address.toString())) {
|
||||||
val networkMapId = if (params.mapAddress.equals(params.address)) {
|
|
||||||
// This node provides network map and notary services
|
// This node provides network map and notary services
|
||||||
advertisedServices = setOf(NetworkMapService.Type, SimpleNotaryService.Type)
|
advertisedServices = setOf(NetworkMapService.Type, SimpleNotaryService.Type)
|
||||||
null
|
null
|
||||||
@ -293,7 +293,7 @@ private fun startNode(params : NodeParams, networkMap: SingleMessageRecipient, r
|
|||||||
nodeInfo(networkMap, params.identityFile, setOf(NetworkMapService.Type, SimpleNotaryService.Type))
|
nodeInfo(networkMap, params.identityFile, setOf(NetworkMapService.Type, SimpleNotaryService.Type))
|
||||||
}
|
}
|
||||||
|
|
||||||
val node = logElapsedTime("Node startup") { Node(params.dir, myNetAddr, config, networkMapId,
|
val node = logElapsedTime("Node startup") { Node(params.dir, params.address, config, networkMapId,
|
||||||
advertisedServices, DemoClock(),
|
advertisedServices, DemoClock(),
|
||||||
listOf(InterestRateSwapAPI::class.java)).start() }
|
listOf(InterestRateSwapAPI::class.java)).start() }
|
||||||
|
|
||||||
@ -415,7 +415,7 @@ private fun uploadFile(url: URL, file: String) : Boolean {
|
|||||||
private fun createNodeAParams() : NodeParams {
|
private fun createNodeAParams() : NodeParams {
|
||||||
val params = NodeParams()
|
val params = NodeParams()
|
||||||
params.dir = Paths.get("nodeA")
|
params.dir = Paths.get("nodeA")
|
||||||
params.address = "localhost"
|
params.address = HostAndPort.fromString("localhost")
|
||||||
params.tradeWithAddrs = listOf("localhost:31340")
|
params.tradeWithAddrs = listOf("localhost:31340")
|
||||||
params.tradeWithIdentities = listOf(getRoleDir(IRSDemoRole.NodeB).resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME))
|
params.tradeWithIdentities = listOf(getRoleDir(IRSDemoRole.NodeB).resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME))
|
||||||
params.defaultLegalName = "Bank A"
|
params.defaultLegalName = "Bank A"
|
||||||
@ -425,7 +425,7 @@ private fun createNodeAParams() : NodeParams {
|
|||||||
private fun createNodeBParams() : NodeParams {
|
private fun createNodeBParams() : NodeParams {
|
||||||
val params = NodeParams()
|
val params = NodeParams()
|
||||||
params.dir = Paths.get("nodeB")
|
params.dir = Paths.get("nodeB")
|
||||||
params.address = "localhost:31340"
|
params.address = HostAndPort.fromString("localhost:31340")
|
||||||
params.tradeWithAddrs = listOf("localhost")
|
params.tradeWithAddrs = listOf("localhost")
|
||||||
params.tradeWithIdentities = listOf(getRoleDir(IRSDemoRole.NodeA).resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME))
|
params.tradeWithIdentities = listOf(getRoleDir(IRSDemoRole.NodeA).resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME))
|
||||||
params.defaultLegalName = "Bank B"
|
params.defaultLegalName = "Bank B"
|
||||||
|
Reference in New Issue
Block a user