mirror of
https://github.com/corda/corda.git
synced 2025-01-30 08:04:16 +00:00
Demos now fully handle process managment except in the case where the process is killed with something like pkill or the JVM being ended by task manager.
This commit is contained in:
parent
9d4f75f241
commit
5bf5e37572
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@ -22,7 +22,6 @@
|
|||||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/node/node_test.iml" filepath="$PROJECT_DIR$/.idea/modules/node/node_test.iml" group="node" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/modules/node/node_test.iml" filepath="$PROJECT_DIR$/.idea/modules/node/node_test.iml" group="node" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/r3prototyping.iml" filepath="$PROJECT_DIR$/.idea/modules/r3prototyping.iml" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/modules/r3prototyping.iml" filepath="$PROJECT_DIR$/.idea/modules/r3prototyping.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/r3prototyping_integrationTest.iml" filepath="$PROJECT_DIR$/.idea/modules/r3prototyping_integrationTest.iml" group="r3prototyping" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/modules/r3prototyping_integrationTest.iml" filepath="$PROJECT_DIR$/.idea/modules/r3prototyping_integrationTest.iml" group="r3prototyping" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/r3prototyping_integrationTest.iml" filepath="$PROJECT_DIR$/.idea/modules/r3prototyping_integrationTest.iml" group="r3prototyping" />
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/r3prototyping_main.iml" filepath="$PROJECT_DIR$/.idea/modules/r3prototyping_main.iml" group="r3prototyping" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/modules/r3prototyping_main.iml" filepath="$PROJECT_DIR$/.idea/modules/r3prototyping_main.iml" group="r3prototyping" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/r3prototyping_test.iml" filepath="$PROJECT_DIR$/.idea/modules/r3prototyping_test.iml" group="r3prototyping" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/modules/r3prototyping_test.iml" filepath="$PROJECT_DIR$/.idea/modules/r3prototyping_test.iml" group="r3prototyping" />
|
||||||
</modules>
|
</modules>
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package com.r3corda.core.testing
|
package com.r3corda.core.testing
|
||||||
|
|
||||||
import com.r3corda.core.testing.utilities.spawn
|
import com.r3corda.core.testing.utilities.*
|
||||||
import com.r3corda.core.testing.utilities.waitForNodeStartup
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
class IRSDemoTest {
|
class IRSDemoTest {
|
||||||
@Test fun `runs IRS demo`() {
|
@Test fun `runs IRS demo`() {
|
||||||
@ -32,34 +30,35 @@ class IRSDemoTest {
|
|||||||
private fun setupNode(dir: Path, nodeType: String) {
|
private fun setupNode(dir: Path, nodeType: String) {
|
||||||
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)
|
||||||
assertEquals(proc.waitFor(2, TimeUnit.MINUTES), true);
|
assertExitOrKill(proc)
|
||||||
assertEquals(proc.exitValue(), 0)
|
assertEquals(proc.exitValue(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startNode(dir: Path, nodeType: String, nodeAddr: String): Process {
|
private fun startNode(dir: Path, nodeType: String, nodeAddr: String): Process {
|
||||||
val args = listOf("--role", nodeType, "--dir", dir.toString())
|
val args = listOf("--role", nodeType, "--dir", dir.toString())
|
||||||
val proc = spawn("com.r3corda.demos.IRSDemoKt", args)
|
val proc = spawn("com.r3corda.demos.IRSDemoKt", args)
|
||||||
waitForNodeStartup(nodeAddr)
|
ensureNodeStartsOrKill(proc, nodeAddr)
|
||||||
return proc
|
return proc
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runTrade() {
|
private fun runTrade() {
|
||||||
val args = listOf("--role", "Trade", "trade1")
|
val args = listOf("--role", "Trade", "trade1")
|
||||||
val proc = spawn("com.r3corda.demos.IRSDemoKt", args)
|
val proc = spawn("com.r3corda.demos.IRSDemoKt", args)
|
||||||
assertEquals(proc.waitFor(2, TimeUnit.MINUTES), true);
|
assertExitOrKill(proc)
|
||||||
assertEquals(proc.exitValue(), 0)
|
assertEquals(proc.exitValue(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runDateChange() {
|
private fun runDateChange() {
|
||||||
val args = listOf("--role", "Date", "2017-01-02")
|
val args = listOf("--role", "Date", "2017-01-02")
|
||||||
val proc = spawn("com.r3corda.demos.IRSDemoKt", args)
|
val proc = spawn("com.r3corda.demos.IRSDemoKt", args)
|
||||||
assertEquals(proc.waitFor(2, TimeUnit.MINUTES), true);
|
assertExitOrKill(proc)
|
||||||
assertEquals(proc.exitValue(), 0)
|
assertEquals(proc.exitValue(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopNode(nodeProc: Process?) {
|
private fun stopNode(nodeProc: Process?) {
|
||||||
assertEquals(nodeProc?.isAlive, true)
|
if(nodeProc != null) {
|
||||||
nodeProc?.destroy()
|
assertAliveAndKill(nodeProc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanup(dir: Path) {
|
private fun cleanup(dir: Path) {
|
||||||
|
@ -1,40 +1,44 @@
|
|||||||
package com.r3corda.core.testing
|
package com.r3corda.core.testing
|
||||||
|
|
||||||
|
import com.r3corda.core.testing.utilities.assertExitOrKill
|
||||||
|
import com.r3corda.core.testing.utilities.ensureNodeStartsOrKill
|
||||||
import com.r3corda.core.testing.utilities.spawn
|
import com.r3corda.core.testing.utilities.spawn
|
||||||
import com.r3corda.core.testing.utilities.waitForNodeStartup
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class TraderDemoTest {
|
class TraderDemoTest {
|
||||||
@Test fun `runs trader demo`() {
|
@Test fun `runs trader demo`() {
|
||||||
var nodeProc: Process? = null
|
var nodeProc: Process? = null
|
||||||
try {
|
try {
|
||||||
|
cleanupFiles()
|
||||||
nodeProc = runBuyer()
|
nodeProc = runBuyer()
|
||||||
runSeller()
|
runSeller()
|
||||||
} finally {
|
} finally {
|
||||||
nodeProc?.destroy()
|
nodeProc?.destroy()
|
||||||
cleanup()
|
cleanupFiles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runBuyer(): Process {
|
private fun runBuyer(): Process {
|
||||||
|
println("Running Buyer")
|
||||||
val args = listOf("--role", "BUYER")
|
val args = listOf("--role", "BUYER")
|
||||||
val proc = spawn("com.r3corda.demos.TraderDemoKt", args)
|
val proc = spawn("com.r3corda.demos.TraderDemoKt", args)
|
||||||
waitForNodeStartup("http://localhost:31338")
|
ensureNodeStartsOrKill(proc, "http://localhost:31338")
|
||||||
return proc
|
return proc
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runSeller() {
|
private fun runSeller() {
|
||||||
|
println("Running Seller")
|
||||||
val args = listOf("--role", "SELLER")
|
val args = listOf("--role", "SELLER")
|
||||||
val proc = spawn("com.r3corda.demos.TraderDemoKt", args)
|
val proc = spawn("com.r3corda.demos.TraderDemoKt", args)
|
||||||
assertEquals(proc.waitFor(30, TimeUnit.SECONDS), true);
|
assertExitOrKill(proc);
|
||||||
assertEquals(proc.exitValue(), 0)
|
assertEquals(proc.exitValue(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanup() {
|
private fun cleanupFiles() {
|
||||||
|
println("Cleaning up TraderDemoTest files")
|
||||||
val dir = Paths.get("trader-demo")
|
val dir = Paths.get("trader-demo")
|
||||||
println("Erasing " + dir)
|
println("Erasing " + dir)
|
||||||
dir.toFile().deleteRecursively()
|
dir.toFile().deleteRecursively()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.r3corda.core.testing.utilities
|
package com.r3corda.core.testing.utilities
|
||||||
|
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
fun spawn(className: String, args: List<String>): Process {
|
fun spawn(className: String, args: List<String>): Process {
|
||||||
val separator = System.getProperty("file.separator")
|
val separator = System.getProperty("file.separator")
|
||||||
@ -9,7 +11,23 @@ fun spawn(className: String, args: List<String>): Process {
|
|||||||
val javaArgs = listOf(path, "-javaagent:lib/quasar.jar", "-cp", classpath, className)
|
val javaArgs = listOf(path, "-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()
|
|
||||||
val process = builder.start();
|
val process = builder.start();
|
||||||
return process
|
return process
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun assertExitOrKill(proc: Process) {
|
||||||
|
try {
|
||||||
|
assertEquals(proc.waitFor(2, TimeUnit.MINUTES), true)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
proc.destroy()
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun assertAliveAndKill(proc: Process) {
|
||||||
|
try {
|
||||||
|
assertEquals(proc.isAlive, true)
|
||||||
|
} finally {
|
||||||
|
proc.destroy()
|
||||||
|
}
|
||||||
|
}
|
@ -2,14 +2,26 @@ package com.r3corda.core.testing.utilities
|
|||||||
|
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.net.ConnectException
|
import java.net.ConnectException
|
||||||
|
import java.net.SocketException
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class NodeDidNotStartException: Throwable {
|
class NodeDidNotStartException: Throwable {
|
||||||
constructor(message: String): super(message) {}
|
constructor(message: String): super(message) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun waitForNodeStartup(nodeAddr: String) {
|
fun ensureNodeStartsOrKill(proc: Process, nodeAddr: String) {
|
||||||
|
try {
|
||||||
|
assertEquals(proc.isAlive, true)
|
||||||
|
waitForNodeStartup(nodeAddr)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
proc.destroy()
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun waitForNodeStartup(nodeAddr: String) {
|
||||||
var retries = 0
|
var retries = 0
|
||||||
var respCode: Int
|
var respCode: Int
|
||||||
do {
|
do {
|
||||||
@ -24,6 +36,9 @@ fun waitForNodeStartup(nodeAddr: String) {
|
|||||||
// This is to be expected while it loads up
|
// This is to be expected while it loads up
|
||||||
respCode = 404
|
respCode = 404
|
||||||
"Node hasn't started"
|
"Node hasn't started"
|
||||||
|
} catch(e: SocketException) {
|
||||||
|
respCode = -1
|
||||||
|
"Could not connect: ${e.toString()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if(retries > 200) {
|
if(retries > 200) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user