mirror of
https://github.com/corda/corda.git
synced 2025-02-21 09:51:57 +00:00
Minor: ProcessUtilities clean up (#3533)
This commit is contained in:
parent
0de7c2aaf4
commit
aefd90f062
@ -35,7 +35,6 @@ import org.junit.After
|
|||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import rx.subjects.PublishSubject
|
import rx.subjects.PublishSubject
|
||||||
import java.io.File.pathSeparator
|
|
||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -231,15 +230,12 @@ class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance")) {
|
|||||||
@Test
|
@Test
|
||||||
fun `additional class loader used by WireTransaction when it deserialises its components`() {
|
fun `additional class loader used by WireTransaction when it deserialises its components`() {
|
||||||
val financeLocation = Cash::class.java.location.toPath().toString()
|
val financeLocation = Cash::class.java.location.toPath().toString()
|
||||||
val classpathWithoutFinance = ProcessUtilities.defaultClassPath
|
val classPathWithoutFinance = ProcessUtilities.defaultClassPath.filter { financeLocation !in it }
|
||||||
.split(pathSeparator)
|
|
||||||
.filter { financeLocation !in it }
|
|
||||||
.joinToString(pathSeparator)
|
|
||||||
|
|
||||||
// Create a Cash.State object for the StandaloneCashRpcClient to get
|
// Create a Cash.State object for the StandaloneCashRpcClient to get
|
||||||
node.services.startFlow(CashIssueFlow(100.POUNDS, OpaqueBytes.of(1), identity), InvocationContext.shell()).flatMap { it.resultFuture }.getOrThrow()
|
node.services.startFlow(CashIssueFlow(100.POUNDS, OpaqueBytes.of(1), identity), InvocationContext.shell()).flatMap { it.resultFuture }.getOrThrow()
|
||||||
val outOfProcessRpc = ProcessUtilities.startJavaProcess<StandaloneCashRpcClient>(
|
val outOfProcessRpc = ProcessUtilities.startJavaProcess<StandaloneCashRpcClient>(
|
||||||
classpath = classpathWithoutFinance,
|
classPath = classPathWithoutFinance,
|
||||||
arguments = listOf(node.internals.configuration.rpcOptions.address.toString(), financeLocation)
|
arguments = listOf(node.internals.configuration.rpcOptions.address.toString(), financeLocation)
|
||||||
)
|
)
|
||||||
assertThat(outOfProcessRpc.waitFor()).isZero() // i.e. no exceptions were thrown
|
assertThat(outOfProcessRpc.waitFor()).isZero() // i.e. no exceptions were thrown
|
||||||
|
@ -56,20 +56,18 @@ class IRSDemoTest {
|
|||||||
isDebug = true,
|
isDebug = true,
|
||||||
extraCordappPackagesToScan = listOf("net.corda.irs")
|
extraCordappPackagesToScan = listOf("net.corda.irs")
|
||||||
)) {
|
)) {
|
||||||
val (nodeA, nodeB) = listOf(
|
val (controller, nodeA, nodeB) = listOf(
|
||||||
|
defaultNotaryNode,
|
||||||
startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = rpcUsers),
|
startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = rpcUsers),
|
||||||
startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = rpcUsers),
|
startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = rpcUsers),
|
||||||
startNode(providedName = CordaX500Name("Regulator", "Moscow", "RU"))
|
startNode(providedName = CordaX500Name("Regulator", "Moscow", "RU"))
|
||||||
).map { it.getOrThrow() }
|
).map { it.getOrThrow() }
|
||||||
val controller = defaultNotaryNode.getOrThrow()
|
|
||||||
|
|
||||||
log.info("All nodes started")
|
log.info("All nodes started")
|
||||||
|
|
||||||
val controllerAddrFuture = startSpringBootWebapp(IrsDemoWebApplication::class.java, controller, "/api/irs/demodate")
|
val (controllerAddr, nodeAAddr, nodeBAddr) = listOf(controller, nodeA, nodeB).map {
|
||||||
val nodeAAddrFuture = startSpringBootWebapp(IrsDemoWebApplication::class.java, nodeA, "/api/irs/demodate")
|
startSpringBootWebapp(IrsDemoWebApplication::class.java, it, "/api/irs/demodate")
|
||||||
val nodeBAddrFuture = startSpringBootWebapp(IrsDemoWebApplication::class.java, nodeB, "/api/irs/demodate")
|
}.map { it.getOrThrow().listenAddress }
|
||||||
val (controllerAddr, nodeAAddr, nodeBAddr) =
|
|
||||||
listOf(controllerAddrFuture, nodeAAddrFuture, nodeBAddrFuture).map { it.getOrThrow().listenAddress }
|
|
||||||
|
|
||||||
log.info("All webservers started")
|
log.info("All webservers started")
|
||||||
|
|
||||||
|
@ -74,16 +74,14 @@ data class SpringBootDriverDSL(private val driverDSL: DriverDSLImpl) : InternalD
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startApplication(handle: NodeHandle, debugPort: Int?, clazz: Class<*>): Process {
|
private fun startApplication(handle: NodeHandle, debugPort: Int?, clazz: Class<*>): Process {
|
||||||
val className = clazz.canonicalName
|
return ProcessUtilities.startJavaProcess(
|
||||||
return ProcessUtilities.startJavaProcessImpl(
|
className = clazz.canonicalName, // cannot directly get class for this, so just use string
|
||||||
className = className, // cannot directly get class for this, so just use string
|
|
||||||
jdwpPort = debugPort,
|
jdwpPort = debugPort,
|
||||||
extraJvmArguments = listOf(
|
extraJvmArguments = listOf(
|
||||||
"-Dname=node-${handle.p2pAddress}-webserver",
|
"-Dname=node-${handle.p2pAddress}-webserver",
|
||||||
"-Djava.io.tmpdir=${System.getProperty("java.io.tmpdir")}"
|
"-Djava.io.tmpdir=${System.getProperty("java.io.tmpdir")}"
|
||||||
// Inherit from parent process
|
// Inherit from parent process
|
||||||
),
|
),
|
||||||
classpath = ProcessUtilities.defaultClassPath,
|
|
||||||
workingDirectory = handle.baseDirectory,
|
workingDirectory = handle.baseDirectory,
|
||||||
arguments = listOf(
|
arguments = listOf(
|
||||||
"--base-directory", handle.baseDirectory.toString(),
|
"--base-directory", handle.baseDirectory.toString(),
|
||||||
@ -91,8 +89,7 @@ data class SpringBootDriverDSL(private val driverDSL: DriverDSLImpl) : InternalD
|
|||||||
"--corda.host=${handle.rpcAddress}",
|
"--corda.host=${handle.rpcAddress}",
|
||||||
"--corda.user=${handle.rpcUsers.first().username}",
|
"--corda.user=${handle.rpcUsers.first().username}",
|
||||||
"--corda.password=${handle.rpcUsers.first().password}"
|
"--corda.password=${handle.rpcUsers.first().password}"
|
||||||
),
|
)
|
||||||
maximumHeapSize = null
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import net.corda.core.utilities.getOrThrow
|
|||||||
import net.corda.core.utilities.millis
|
import net.corda.core.utilities.millis
|
||||||
import net.corda.node.NodeRegistrationOption
|
import net.corda.node.NodeRegistrationOption
|
||||||
import net.corda.node.VersionInfo
|
import net.corda.node.VersionInfo
|
||||||
import net.corda.node.internal.ConfigurationException
|
|
||||||
import net.corda.node.internal.Node
|
import net.corda.node.internal.Node
|
||||||
import net.corda.node.internal.StartedNode
|
import net.corda.node.internal.StartedNode
|
||||||
import net.corda.node.services.Permissions
|
import net.corda.node.services.Permissions
|
||||||
@ -838,7 +837,7 @@ class DriverDSLImpl(
|
|||||||
it += extraCmdLineFlag
|
it += extraCmdLineFlag
|
||||||
}.toList()
|
}.toList()
|
||||||
|
|
||||||
return ProcessUtilities.startCordaProcess(
|
return ProcessUtilities.startJavaProcess(
|
||||||
className = "net.corda.node.Corda", // cannot directly get class for this, so just use string
|
className = "net.corda.node.Corda", // cannot directly get class for this, so just use string
|
||||||
arguments = arguments,
|
arguments = arguments,
|
||||||
jdwpPort = debugPort,
|
jdwpPort = debugPort,
|
||||||
@ -851,13 +850,12 @@ class DriverDSLImpl(
|
|||||||
private fun startWebserver(handle: NodeHandleInternal, debugPort: Int?, maximumHeapSize: String): Process {
|
private fun startWebserver(handle: NodeHandleInternal, debugPort: Int?, maximumHeapSize: String): Process {
|
||||||
val className = "net.corda.webserver.WebServer"
|
val className = "net.corda.webserver.WebServer"
|
||||||
writeConfig(handle.baseDirectory, "web-server.conf", handle.toWebServerConfig())
|
writeConfig(handle.baseDirectory, "web-server.conf", handle.toWebServerConfig())
|
||||||
return ProcessUtilities.startCordaProcess(
|
return ProcessUtilities.startJavaProcess(
|
||||||
className = className, // cannot directly get class for this, so just use string
|
className = className, // cannot directly get class for this, so just use string
|
||||||
arguments = listOf("--base-directory", handle.baseDirectory.toString()),
|
arguments = listOf("--base-directory", handle.baseDirectory.toString()),
|
||||||
jdwpPort = debugPort,
|
jdwpPort = debugPort,
|
||||||
extraJvmArguments = listOf("-Dname=node-${handle.p2pAddress}-webserver") +
|
extraJvmArguments = listOf("-Dname=node-${handle.p2pAddress}-webserver") +
|
||||||
inheritFromParentProcess().map { "-D${it.first}=${it.second}" },
|
inheritFromParentProcess().map { "-D${it.first}=${it.second}" },
|
||||||
workingDirectory = null,
|
|
||||||
maximumHeapSize = maximumHeapSize
|
maximumHeapSize = maximumHeapSize
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,32 @@
|
|||||||
package net.corda.testing.node.internal
|
package net.corda.testing.node.internal
|
||||||
|
|
||||||
import net.corda.core.internal.div
|
import net.corda.core.internal.div
|
||||||
|
import java.io.File
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
object ProcessUtilities {
|
object ProcessUtilities {
|
||||||
inline fun <reified C : Any> startJavaProcess(
|
inline fun <reified C : Any> startJavaProcess(
|
||||||
arguments: List<String>,
|
arguments: List<String>,
|
||||||
classpath: String = defaultClassPath,
|
classPath: List<String> = defaultClassPath,
|
||||||
|
workingDirectory: Path? = null,
|
||||||
jdwpPort: Int? = null,
|
jdwpPort: Int? = null,
|
||||||
extraJvmArguments: List<String> = emptyList()
|
extraJvmArguments: List<String> = emptyList(),
|
||||||
|
maximumHeapSize: String? = null
|
||||||
): Process {
|
): Process {
|
||||||
return startJavaProcessImpl(C::class.java.name, arguments, classpath, jdwpPort, extraJvmArguments, null, null)
|
return startJavaProcess(C::class.java.name, arguments, classPath, workingDirectory, jdwpPort, extraJvmArguments, maximumHeapSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startCordaProcess(
|
fun startJavaProcess(
|
||||||
className: String,
|
className: String,
|
||||||
arguments: List<String>,
|
arguments: List<String>,
|
||||||
jdwpPort: Int?,
|
classPath: List<String> = defaultClassPath,
|
||||||
extraJvmArguments: List<String>,
|
workingDirectory: Path? = null,
|
||||||
workingDirectory: Path?,
|
jdwpPort: Int? = null,
|
||||||
maximumHeapSize: String
|
extraJvmArguments: List<String> = emptyList(),
|
||||||
): Process {
|
maximumHeapSize: String? = null
|
||||||
return startJavaProcessImpl(className, arguments, defaultClassPath, jdwpPort, extraJvmArguments, workingDirectory, maximumHeapSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun startJavaProcessImpl(
|
|
||||||
className: String,
|
|
||||||
arguments: List<String>,
|
|
||||||
classpath: String,
|
|
||||||
jdwpPort: Int?,
|
|
||||||
extraJvmArguments: List<String>,
|
|
||||||
workingDirectory: Path?,
|
|
||||||
maximumHeapSize: String?
|
|
||||||
): Process {
|
): Process {
|
||||||
val command = mutableListOf<String>().apply {
|
val command = mutableListOf<String>().apply {
|
||||||
add((System.getProperty("java.home") / "bin" / "java").toString())
|
add(javaPath)
|
||||||
(jdwpPort != null) && add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$jdwpPort")
|
(jdwpPort != null) && add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$jdwpPort")
|
||||||
if (maximumHeapSize != null) add("-Xmx$maximumHeapSize")
|
if (maximumHeapSize != null) add("-Xmx$maximumHeapSize")
|
||||||
add("-XX:+UseG1GC")
|
add("-XX:+UseG1GC")
|
||||||
@ -44,7 +36,7 @@ object ProcessUtilities {
|
|||||||
}
|
}
|
||||||
return ProcessBuilder(command).apply {
|
return ProcessBuilder(command).apply {
|
||||||
inheritIO()
|
inheritIO()
|
||||||
environment()["CLASSPATH"] = classpath
|
environment()["CLASSPATH"] = classPath.joinToString(File.pathSeparator)
|
||||||
if (workingDirectory != null) {
|
if (workingDirectory != null) {
|
||||||
redirectError((workingDirectory / "$className.stderr.log").toFile())
|
redirectError((workingDirectory / "$className.stderr.log").toFile())
|
||||||
redirectOutput((workingDirectory / "$className.stdout.log").toFile())
|
redirectOutput((workingDirectory / "$className.stdout.log").toFile())
|
||||||
@ -53,5 +45,7 @@ object ProcessUtilities {
|
|||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
val defaultClassPath: String get() = System.getProperty("java.class.path")
|
private val javaPath = (System.getProperty("java.home") / "bin" / "java").toString()
|
||||||
|
|
||||||
|
val defaultClassPath: List<String> = System.getProperty("java.class.path").split(File.pathSeparator)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user