integtest: Use separate folder for each integtest run, provide api address

This commit is contained in:
Andras Slemmer 2016-06-28 14:03:10 +01:00
parent aa82d4441e
commit 9e5bf7c32c
3 changed files with 81 additions and 55 deletions

View File

@ -12,44 +12,56 @@ class IRSDemoTest {
val nodeAddrA = freeLocalHostAndPort()
val apiAddrA = freeLocalHostAndPort()
val apiAddrB = freeLocalHostAndPort()
val dirA = Paths.get("./nodeA")
val dirB = Paths.get("./nodeB")
val baseDirectory = Paths.get("./build/integration-test/${TestTimestamp.timestamp}/irs-demo")
var procA: Process? = null
var procB: Process? = null
try {
setupNode(dirA, "NodeA")
setupNode(dirB, "NodeB")
procA = startNode(dirA, "NodeA", nodeAddrA, nodeAddrA, apiAddrA)
procB = startNode(dirB, "NodeB", freeLocalHostAndPort(), nodeAddrA, apiAddrB)
setupNode(baseDirectory, "NodeA")
setupNode(baseDirectory, "NodeB")
procA = startNode(
baseDirectory = baseDirectory,
nodeType = "NodeA",
nodeAddr = nodeAddrA,
networkMapAddr = apiAddrA,
apiAddr = apiAddrA
)
procB = startNode(
baseDirectory = baseDirectory,
nodeType = "NodeB",
nodeAddr = freeLocalHostAndPort(),
networkMapAddr = nodeAddrA,
apiAddr = apiAddrB
)
runTrade(apiAddrA)
runDateChange(apiAddrA)
} finally {
stopNode(procA)
stopNode(procB)
cleanup(dirA)
cleanup(dirB)
}
}
}
private fun setupNode(dir: Path, nodeType: String) {
private fun setupNode(baseDirectory: Path, nodeType: String) {
println("Running setup for $nodeType")
val args = listOf("--role", "Setup" + nodeType, "--dir", dir.toString())
val args = listOf("--role", "Setup" + nodeType, "--base-directory", baseDirectory.toString())
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemoSetup$nodeType")
assertExitOrKill(proc)
assertEquals(proc.exitValue(), 0)
}
private fun startNode(dir: Path,
private fun startNode(baseDirectory: Path,
nodeType: String,
nodeAddr: HostAndPort,
networkMapAddr: HostAndPort,
apiAddr: HostAndPort): Process {
println("Running node $nodeType")
println("Node addr: ${nodeAddr.toString()}")
println("Node addr: $nodeAddr")
println("Network map addr: $networkMapAddr")
println("API addr: $apiAddr")
val args = listOf(
"--role", nodeType,
"--dir", dir.toString(),
"--base-directory", baseDirectory.toString(),
"--network-address", nodeAddr.toString(),
"--network-map-address", networkMapAddr.toString(),
"--api-address", apiAddr.toString())
@ -60,7 +72,7 @@ private fun startNode(dir: Path,
private fun runTrade(nodeAddr: HostAndPort) {
println("Running trade")
val args = listOf("--role", "Trade", "trade1", "--network-address", "http://" + nodeAddr.toString())
val args = listOf("--role", "Trade", "trade1", "--api-address", nodeAddr.toString())
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemoTrade")
assertExitOrKill(proc)
assertEquals(proc.exitValue(), 0)
@ -68,7 +80,7 @@ private fun runTrade(nodeAddr: HostAndPort) {
private fun runDateChange(nodeAddr: HostAndPort) {
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", "--api-address", nodeAddr.toString())
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemoDate")
assertExitOrKill(proc)
assertEquals(proc.exitValue(), 0)
@ -80,8 +92,3 @@ private fun stopNode(nodeProc: Process?) {
assertAliveAndKill(nodeProc)
}
}
private fun cleanup(dir: Path) {
println("Erasing: " + dir.toString())
dir.toFile().deleteRecursively()
}

View File

@ -2,58 +2,58 @@ package com.r3corda.core.testing
import com.google.common.net.HostAndPort
import com.r3corda.core.testing.utilities.NodeApi
import com.r3corda.core.testing.utilities.TestTimestamp
import com.r3corda.core.testing.utilities.assertExitOrKill
import com.r3corda.core.testing.utilities.spawn
import org.junit.Test
import java.nio.file.Paths
import java.text.SimpleDateFormat
import java.util.*
import kotlin.test.assertEquals
class TraderDemoTest {
@Test fun `runs trader demo`() {
val buyerAddr = freeLocalHostAndPort()
val buyerApiAddr = freeLocalHostAndPort()
val directory = "./build/integration-test/${TestTimestamp.timestamp}/trader-demo"
var nodeProc: Process? = null
try {
cleanupFiles()
nodeProc = runBuyer(buyerAddr, buyerApiAddr)
runSeller(buyerAddr)
nodeProc = runBuyer(directory, buyerAddr, buyerApiAddr)
runSeller(directory, buyerAddr)
} finally {
nodeProc?.destroy()
cleanupFiles()
}
}
}
private fun runBuyer(buyerAddr: HostAndPort, buyerApiAddr: HostAndPort): Process {
println("Running Buyer")
val args = listOf(
"--role", "BUYER",
"--network-address", buyerAddr.toString(),
"--api-address", buyerApiAddr.toString()
)
val proc = spawn("com.r3corda.demos.TraderDemoKt", args, "TradeDemoBuyer")
NodeApi.ensureNodeStartsOrKill(proc, buyerApiAddr)
return proc
}
companion object {
private fun runBuyer(baseDirectory: String, buyerAddr: HostAndPort, buyerApiAddr: HostAndPort): Process {
println("Running Buyer")
val args = listOf(
"--role", "BUYER",
"--network-address", buyerAddr.toString(),
"--api-address", buyerApiAddr.toString(),
"--base-directory", baseDirectory
)
val proc = spawn("com.r3corda.demos.TraderDemoKt", args, "TradeDemoBuyer")
NodeApi.ensureNodeStartsOrKill(proc, buyerApiAddr)
return proc
}
private fun runSeller(buyerAddr: HostAndPort) {
println("Running Seller")
val sellerAddr = freeLocalHostAndPort()
val sellerApiAddr = freeLocalHostAndPort()
val args = listOf(
"--role", "SELLER",
"--network-address", sellerAddr.toString(),
"--api-address", sellerApiAddr.toString(),
"--other-network-address", buyerAddr.toString()
)
val proc = spawn("com.r3corda.demos.TraderDemoKt", args, "TradeDemoSeller")
assertExitOrKill(proc);
assertEquals(proc.exitValue(), 0)
}
private fun runSeller(baseDirectory: String, buyerAddr: HostAndPort) {
println("Running Seller")
val sellerAddr = freeLocalHostAndPort()
val sellerApiAddr = freeLocalHostAndPort()
val args = listOf(
"--role", "SELLER",
"--network-address", sellerAddr.toString(),
"--api-address", sellerApiAddr.toString(),
"--other-network-address", buyerAddr.toString(),
"--base-directory", baseDirectory
)
val proc = spawn("com.r3corda.demos.TraderDemoKt", args, "TradeDemoSeller")
assertExitOrKill(proc);
assertEquals(proc.exitValue(), 0)
}
private fun cleanupFiles() {
println("Cleaning up TraderDemoTest files")
val dir = Paths.get("trader-demo")
println("Erasing " + dir)
dir.toFile().deleteRecursively()
}
}

View File

@ -0,0 +1,19 @@
package com.r3corda.core.testing.utilities
import java.text.SimpleDateFormat
import java.util.*
/**
* [timestamp] holds a formatted (UTC) timestamp that's set the first time it is queried. This is used to
* provide a uniform timestamp for tests
*/
class TestTimestamp {
companion object {
val timestamp: String = {
val tz = TimeZone.getTimeZone("UTC")
val df = SimpleDateFormat("yyyy-MM-dd-HH:mm:ss")
df.timeZone = tz
df.format(Date())
}()
}
}