mirror of
https://github.com/corda/corda.git
synced 2024-12-20 13:33:12 +00:00
integtest: Use separate folder for each integtest run, provide api address
This commit is contained in:
parent
aa82d4441e
commit
9e5bf7c32c
@ -12,44 +12,56 @@ class IRSDemoTest {
|
|||||||
val nodeAddrA = freeLocalHostAndPort()
|
val nodeAddrA = freeLocalHostAndPort()
|
||||||
val apiAddrA = freeLocalHostAndPort()
|
val apiAddrA = freeLocalHostAndPort()
|
||||||
val apiAddrB = 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 procA: Process? = null
|
||||||
var procB: Process? = null
|
var procB: Process? = null
|
||||||
try {
|
try {
|
||||||
setupNode(dirA, "NodeA")
|
setupNode(baseDirectory, "NodeA")
|
||||||
setupNode(dirB, "NodeB")
|
setupNode(baseDirectory, "NodeB")
|
||||||
procA = startNode(dirA, "NodeA", nodeAddrA, nodeAddrA, apiAddrA)
|
procA = startNode(
|
||||||
procB = startNode(dirB, "NodeB", freeLocalHostAndPort(), nodeAddrA, apiAddrB)
|
baseDirectory = baseDirectory,
|
||||||
|
nodeType = "NodeA",
|
||||||
|
nodeAddr = nodeAddrA,
|
||||||
|
networkMapAddr = apiAddrA,
|
||||||
|
apiAddr = apiAddrA
|
||||||
|
)
|
||||||
|
procB = startNode(
|
||||||
|
baseDirectory = baseDirectory,
|
||||||
|
nodeType = "NodeB",
|
||||||
|
nodeAddr = freeLocalHostAndPort(),
|
||||||
|
networkMapAddr = nodeAddrA,
|
||||||
|
apiAddr = apiAddrB
|
||||||
|
)
|
||||||
runTrade(apiAddrA)
|
runTrade(apiAddrA)
|
||||||
runDateChange(apiAddrA)
|
runDateChange(apiAddrA)
|
||||||
} finally {
|
} finally {
|
||||||
stopNode(procA)
|
stopNode(procA)
|
||||||
stopNode(procB)
|
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")
|
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")
|
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,
|
private fun startNode(baseDirectory: Path,
|
||||||
nodeType: String,
|
nodeType: String,
|
||||||
nodeAddr: HostAndPort,
|
nodeAddr: HostAndPort,
|
||||||
networkMapAddr: HostAndPort,
|
networkMapAddr: HostAndPort,
|
||||||
apiAddr: HostAndPort): Process {
|
apiAddr: HostAndPort): Process {
|
||||||
println("Running node $nodeType")
|
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(
|
val args = listOf(
|
||||||
"--role", nodeType,
|
"--role", nodeType,
|
||||||
"--dir", dir.toString(),
|
"--base-directory", baseDirectory.toString(),
|
||||||
"--network-address", nodeAddr.toString(),
|
"--network-address", nodeAddr.toString(),
|
||||||
"--network-map-address", networkMapAddr.toString(),
|
"--network-map-address", networkMapAddr.toString(),
|
||||||
"--api-address", apiAddr.toString())
|
"--api-address", apiAddr.toString())
|
||||||
@ -60,7 +72,7 @@ private fun startNode(dir: Path,
|
|||||||
|
|
||||||
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", "--api-address", nodeAddr.toString())
|
||||||
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemoTrade")
|
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemoTrade")
|
||||||
assertExitOrKill(proc)
|
assertExitOrKill(proc)
|
||||||
assertEquals(proc.exitValue(), 0)
|
assertEquals(proc.exitValue(), 0)
|
||||||
@ -68,7 +80,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", "--api-address", nodeAddr.toString())
|
||||||
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemoDate")
|
val proc = spawn("com.r3corda.demos.IRSDemoKt", args, "IRSDemoDate")
|
||||||
assertExitOrKill(proc)
|
assertExitOrKill(proc)
|
||||||
assertEquals(proc.exitValue(), 0)
|
assertEquals(proc.exitValue(), 0)
|
||||||
@ -80,8 +92,3 @@ private fun stopNode(nodeProc: Process?) {
|
|||||||
assertAliveAndKill(nodeProc)
|
assertAliveAndKill(nodeProc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanup(dir: Path) {
|
|
||||||
println("Erasing: " + dir.toString())
|
|
||||||
dir.toFile().deleteRecursively()
|
|
||||||
}
|
|
||||||
|
@ -2,58 +2,58 @@ package com.r3corda.core.testing
|
|||||||
|
|
||||||
import com.google.common.net.HostAndPort
|
import com.google.common.net.HostAndPort
|
||||||
import com.r3corda.core.testing.utilities.NodeApi
|
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.assertExitOrKill
|
||||||
import com.r3corda.core.testing.utilities.spawn
|
import com.r3corda.core.testing.utilities.spawn
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class TraderDemoTest {
|
class TraderDemoTest {
|
||||||
@Test fun `runs trader demo`() {
|
@Test fun `runs trader demo`() {
|
||||||
val buyerAddr = freeLocalHostAndPort()
|
val buyerAddr = freeLocalHostAndPort()
|
||||||
val buyerApiAddr = freeLocalHostAndPort()
|
val buyerApiAddr = freeLocalHostAndPort()
|
||||||
|
val directory = "./build/integration-test/${TestTimestamp.timestamp}/trader-demo"
|
||||||
var nodeProc: Process? = null
|
var nodeProc: Process? = null
|
||||||
try {
|
try {
|
||||||
cleanupFiles()
|
nodeProc = runBuyer(directory, buyerAddr, buyerApiAddr)
|
||||||
nodeProc = runBuyer(buyerAddr, buyerApiAddr)
|
runSeller(directory, buyerAddr)
|
||||||
runSeller(buyerAddr)
|
|
||||||
} finally {
|
} finally {
|
||||||
nodeProc?.destroy()
|
nodeProc?.destroy()
|
||||||
cleanupFiles()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun runBuyer(buyerAddr: HostAndPort, buyerApiAddr: HostAndPort): Process {
|
companion object {
|
||||||
println("Running Buyer")
|
private fun runBuyer(baseDirectory: String, buyerAddr: HostAndPort, buyerApiAddr: HostAndPort): Process {
|
||||||
val args = listOf(
|
println("Running Buyer")
|
||||||
"--role", "BUYER",
|
val args = listOf(
|
||||||
"--network-address", buyerAddr.toString(),
|
"--role", "BUYER",
|
||||||
"--api-address", buyerApiAddr.toString()
|
"--network-address", buyerAddr.toString(),
|
||||||
)
|
"--api-address", buyerApiAddr.toString(),
|
||||||
val proc = spawn("com.r3corda.demos.TraderDemoKt", args, "TradeDemoBuyer")
|
"--base-directory", baseDirectory
|
||||||
NodeApi.ensureNodeStartsOrKill(proc, buyerApiAddr)
|
)
|
||||||
return proc
|
val proc = spawn("com.r3corda.demos.TraderDemoKt", args, "TradeDemoBuyer")
|
||||||
}
|
NodeApi.ensureNodeStartsOrKill(proc, buyerApiAddr)
|
||||||
|
return proc
|
||||||
|
}
|
||||||
|
|
||||||
private fun runSeller(buyerAddr: HostAndPort) {
|
private fun runSeller(baseDirectory: String, buyerAddr: HostAndPort) {
|
||||||
println("Running Seller")
|
println("Running Seller")
|
||||||
val sellerAddr = freeLocalHostAndPort()
|
val sellerAddr = freeLocalHostAndPort()
|
||||||
val sellerApiAddr = freeLocalHostAndPort()
|
val sellerApiAddr = freeLocalHostAndPort()
|
||||||
val args = listOf(
|
val args = listOf(
|
||||||
"--role", "SELLER",
|
"--role", "SELLER",
|
||||||
"--network-address", sellerAddr.toString(),
|
"--network-address", sellerAddr.toString(),
|
||||||
"--api-address", sellerApiAddr.toString(),
|
"--api-address", sellerApiAddr.toString(),
|
||||||
"--other-network-address", buyerAddr.toString()
|
"--other-network-address", buyerAddr.toString(),
|
||||||
)
|
"--base-directory", baseDirectory
|
||||||
val proc = spawn("com.r3corda.demos.TraderDemoKt", args, "TradeDemoSeller")
|
)
|
||||||
assertExitOrKill(proc);
|
val proc = spawn("com.r3corda.demos.TraderDemoKt", args, "TradeDemoSeller")
|
||||||
assertEquals(proc.exitValue(), 0)
|
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()
|
|
||||||
}
|
}
|
||||||
|
@ -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())
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user