mirror of
https://github.com/corda/corda.git
synced 2025-02-20 09:26:41 +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.Test
|
||||
import rx.subjects.PublishSubject
|
||||
import java.io.File.pathSeparator
|
||||
import java.net.URLClassLoader
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
@ -231,15 +230,12 @@ class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance")) {
|
||||
@Test
|
||||
fun `additional class loader used by WireTransaction when it deserialises its components`() {
|
||||
val financeLocation = Cash::class.java.location.toPath().toString()
|
||||
val classpathWithoutFinance = ProcessUtilities.defaultClassPath
|
||||
.split(pathSeparator)
|
||||
.filter { financeLocation !in it }
|
||||
.joinToString(pathSeparator)
|
||||
val classPathWithoutFinance = ProcessUtilities.defaultClassPath.filter { financeLocation !in it }
|
||||
|
||||
// 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()
|
||||
val outOfProcessRpc = ProcessUtilities.startJavaProcess<StandaloneCashRpcClient>(
|
||||
classpath = classpathWithoutFinance,
|
||||
classPath = classPathWithoutFinance,
|
||||
arguments = listOf(node.internals.configuration.rpcOptions.address.toString(), financeLocation)
|
||||
)
|
||||
assertThat(outOfProcessRpc.waitFor()).isZero() // i.e. no exceptions were thrown
|
||||
|
@ -56,20 +56,18 @@ class IRSDemoTest {
|
||||
isDebug = true,
|
||||
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_B_NAME, rpcUsers = rpcUsers),
|
||||
startNode(providedName = CordaX500Name("Regulator", "Moscow", "RU"))
|
||||
).map { it.getOrThrow() }
|
||||
val controller = defaultNotaryNode.getOrThrow()
|
||||
|
||||
log.info("All nodes started")
|
||||
|
||||
val controllerAddrFuture = startSpringBootWebapp(IrsDemoWebApplication::class.java, controller, "/api/irs/demodate")
|
||||
val nodeAAddrFuture = startSpringBootWebapp(IrsDemoWebApplication::class.java, nodeA, "/api/irs/demodate")
|
||||
val nodeBAddrFuture = startSpringBootWebapp(IrsDemoWebApplication::class.java, nodeB, "/api/irs/demodate")
|
||||
val (controllerAddr, nodeAAddr, nodeBAddr) =
|
||||
listOf(controllerAddrFuture, nodeAAddrFuture, nodeBAddrFuture).map { it.getOrThrow().listenAddress }
|
||||
val (controllerAddr, nodeAAddr, nodeBAddr) = listOf(controller, nodeA, nodeB).map {
|
||||
startSpringBootWebapp(IrsDemoWebApplication::class.java, it, "/api/irs/demodate")
|
||||
}.map { it.getOrThrow().listenAddress }
|
||||
|
||||
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 {
|
||||
val className = clazz.canonicalName
|
||||
return ProcessUtilities.startJavaProcessImpl(
|
||||
className = className, // cannot directly get class for this, so just use string
|
||||
return ProcessUtilities.startJavaProcess(
|
||||
className = clazz.canonicalName, // cannot directly get class for this, so just use string
|
||||
jdwpPort = debugPort,
|
||||
extraJvmArguments = listOf(
|
||||
"-Dname=node-${handle.p2pAddress}-webserver",
|
||||
"-Djava.io.tmpdir=${System.getProperty("java.io.tmpdir")}"
|
||||
// Inherit from parent process
|
||||
),
|
||||
classpath = ProcessUtilities.defaultClassPath,
|
||||
workingDirectory = handle.baseDirectory,
|
||||
arguments = listOf(
|
||||
"--base-directory", handle.baseDirectory.toString(),
|
||||
@ -91,8 +89,7 @@ data class SpringBootDriverDSL(private val driverDSL: DriverDSLImpl) : InternalD
|
||||
"--corda.host=${handle.rpcAddress}",
|
||||
"--corda.user=${handle.rpcUsers.first().username}",
|
||||
"--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.node.NodeRegistrationOption
|
||||
import net.corda.node.VersionInfo
|
||||
import net.corda.node.internal.ConfigurationException
|
||||
import net.corda.node.internal.Node
|
||||
import net.corda.node.internal.StartedNode
|
||||
import net.corda.node.services.Permissions
|
||||
@ -838,7 +837,7 @@ class DriverDSLImpl(
|
||||
it += extraCmdLineFlag
|
||||
}.toList()
|
||||
|
||||
return ProcessUtilities.startCordaProcess(
|
||||
return ProcessUtilities.startJavaProcess(
|
||||
className = "net.corda.node.Corda", // cannot directly get class for this, so just use string
|
||||
arguments = arguments,
|
||||
jdwpPort = debugPort,
|
||||
@ -851,13 +850,12 @@ class DriverDSLImpl(
|
||||
private fun startWebserver(handle: NodeHandleInternal, debugPort: Int?, maximumHeapSize: String): Process {
|
||||
val className = "net.corda.webserver.WebServer"
|
||||
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
|
||||
arguments = listOf("--base-directory", handle.baseDirectory.toString()),
|
||||
jdwpPort = debugPort,
|
||||
extraJvmArguments = listOf("-Dname=node-${handle.p2pAddress}-webserver") +
|
||||
inheritFromParentProcess().map { "-D${it.first}=${it.second}" },
|
||||
workingDirectory = null,
|
||||
maximumHeapSize = maximumHeapSize
|
||||
)
|
||||
}
|
||||
|
@ -1,40 +1,32 @@
|
||||
package net.corda.testing.node.internal
|
||||
|
||||
import net.corda.core.internal.div
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
|
||||
object ProcessUtilities {
|
||||
inline fun <reified C : Any> startJavaProcess(
|
||||
arguments: List<String>,
|
||||
classpath: String = defaultClassPath,
|
||||
classPath: List<String> = defaultClassPath,
|
||||
workingDirectory: Path? = null,
|
||||
jdwpPort: Int? = null,
|
||||
extraJvmArguments: List<String> = emptyList()
|
||||
extraJvmArguments: List<String> = emptyList(),
|
||||
maximumHeapSize: String? = null
|
||||
): 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,
|
||||
arguments: List<String>,
|
||||
jdwpPort: Int?,
|
||||
extraJvmArguments: List<String>,
|
||||
workingDirectory: Path?,
|
||||
maximumHeapSize: String
|
||||
): Process {
|
||||
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?
|
||||
classPath: List<String> = defaultClassPath,
|
||||
workingDirectory: Path? = null,
|
||||
jdwpPort: Int? = null,
|
||||
extraJvmArguments: List<String> = emptyList(),
|
||||
maximumHeapSize: String? = null
|
||||
): Process {
|
||||
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")
|
||||
if (maximumHeapSize != null) add("-Xmx$maximumHeapSize")
|
||||
add("-XX:+UseG1GC")
|
||||
@ -44,7 +36,7 @@ object ProcessUtilities {
|
||||
}
|
||||
return ProcessBuilder(command).apply {
|
||||
inheritIO()
|
||||
environment()["CLASSPATH"] = classpath
|
||||
environment()["CLASSPATH"] = classPath.joinToString(File.pathSeparator)
|
||||
if (workingDirectory != null) {
|
||||
redirectError((workingDirectory / "$className.stderr.log").toFile())
|
||||
redirectOutput((workingDirectory / "$className.stdout.log").toFile())
|
||||
@ -53,5 +45,7 @@ object ProcessUtilities {
|
||||
}.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