mirror of
https://github.com/corda/corda.git
synced 2024-12-22 14:22:28 +00:00
Combines Parameters with Builder.
This commit is contained in:
parent
b92306b82b
commit
e3ddf84cf8
@ -146,6 +146,7 @@ interface DriverDSLExposedInterface : CordformContext {
|
||||
* @return A future that completes with the non-null value [check] has returned.
|
||||
*/
|
||||
fun <A> pollUntilNonNull(pollName: String, pollInterval: Duration = 500.millis, warnCount: Int = 120, check: () -> A?): CordaFuture<A>
|
||||
|
||||
/**
|
||||
* Polls the given function until it returns true.
|
||||
* @see pollUntilNonNull
|
||||
@ -242,11 +243,10 @@ sealed class PortAllocation {
|
||||
* @param dsl The dsl itself.
|
||||
* @return The value returned in the [dsl] closure.
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun <A> driver(
|
||||
defaultParameters: DriverParameters = DriverParameters(),
|
||||
isDebug: Boolean = defaultParameters.isDebug,
|
||||
driverDirectory: Path = defaultParameters.driverDirectory,
|
||||
// The directory must be different for each call to `driver`.
|
||||
driverDirectory: Path = Paths.get("build", getTimestampAsDirectoryName()),
|
||||
portAllocation: PortAllocation = defaultParameters.portAllocation,
|
||||
debugPortAllocation: PortAllocation = defaultParameters.debugPortAllocation,
|
||||
systemProperties: Map<String, String> = defaultParameters.systemProperties,
|
||||
@ -274,10 +274,21 @@ fun <A> driver(
|
||||
}
|
||||
|
||||
fun <A> driver(
|
||||
builder: DriverBuilder,
|
||||
parameters: DriverParameters,
|
||||
dsl: DriverDSLExposedInterface.() -> A
|
||||
): A {
|
||||
return driver(defaultParameters = builder.parameters, dsl = dsl)
|
||||
return driver(
|
||||
isDebug = parameters.isDebug,
|
||||
driverDirectory = parameters.driverDirectory,
|
||||
portAllocation = parameters.portAllocation,
|
||||
debugPortAllocation = parameters.debugPortAllocation,
|
||||
systemProperties = parameters.systemProperties,
|
||||
useTestClock = parameters.useTestClock,
|
||||
initialiseSerialization = parameters.initialiseSerialization,
|
||||
networkMapStartStrategy = parameters.networkMapStartStrategy,
|
||||
startNodesInProcess = parameters.startNodesInProcess,
|
||||
dsl = dsl
|
||||
)
|
||||
}
|
||||
|
||||
data class DriverParameters(
|
||||
@ -290,21 +301,20 @@ data class DriverParameters(
|
||||
val initialiseSerialization: Boolean = true,
|
||||
val networkMapStartStrategy: NetworkMapStartStrategy = NetworkMapStartStrategy.Dedicated(startAutomatically = true),
|
||||
val startNodesInProcess: Boolean = false
|
||||
)
|
||||
|
||||
class DriverBuilder(val parameters: DriverParameters) {
|
||||
constructor() : this(DriverParameters())
|
||||
fun setIsDebug(newValue: Boolean) = DriverBuilder(parameters.copy(isDebug = newValue))
|
||||
fun setDriverDirectory(newValue: Path) = DriverBuilder(parameters.copy(driverDirectory = newValue))
|
||||
fun setPortAllocation(newValue: PortAllocation) = DriverBuilder(parameters.copy(portAllocation = newValue))
|
||||
fun setDebugPortAllocation(newValue: PortAllocation) = DriverBuilder(parameters.copy(debugPortAllocation = newValue))
|
||||
fun setSystemProperties(newValue: Map<String, String>) = DriverBuilder(parameters.copy(systemProperties = newValue))
|
||||
fun setUseTestClock(newValue: Boolean) = DriverBuilder(parameters.copy(useTestClock = newValue))
|
||||
fun setInitialiseSerialization(newValue: Boolean) = DriverBuilder(parameters.copy(initialiseSerialization = newValue))
|
||||
fun setNetworkMapStartStrategy(newValue: NetworkMapStartStrategy) = DriverBuilder(parameters.copy(networkMapStartStrategy = newValue))
|
||||
fun setStartNodesInProcess(newValue: Boolean) = DriverBuilder(parameters.copy(startNodesInProcess = newValue))
|
||||
) {
|
||||
fun setIsDebug(isDebug: Boolean) = copy(isDebug = isDebug)
|
||||
fun setDriverDirectory(driverDirectory: Path) = copy(driverDirectory = driverDirectory)
|
||||
fun setPortAllocation(portAllocation: PortAllocation) = copy(portAllocation = portAllocation)
|
||||
fun setDebugPortAllocation(debugPortAllocation: PortAllocation) = copy(debugPortAllocation = debugPortAllocation)
|
||||
fun setSystemProperties(systemProperties: Map<String, String>) = copy(systemProperties = systemProperties)
|
||||
fun setUseTestClock(useTestClock: Boolean) = copy(useTestClock = useTestClock)
|
||||
fun setInitialiseSerialization(initialiseSerialization: Boolean) = copy(initialiseSerialization = initialiseSerialization)
|
||||
fun setNetworkMapStartStrategy(networkMapStartStrategy: NetworkMapStartStrategy) = copy(networkMapStartStrategy = networkMapStartStrategy)
|
||||
fun setStartNodesInProcess(startNodesInProcess: Boolean) = copy(startNodesInProcess = startNodesInProcess)
|
||||
}
|
||||
|
||||
private val defaultParameters = DriverParameters()
|
||||
|
||||
/**
|
||||
* This is a helper method to allow extending of the DSL, along the lines of
|
||||
* interface SomeOtherExposedDSLInterface : DriverDSLExposedInterface
|
||||
@ -438,7 +448,8 @@ class ShutdownManager(private val executorService: ExecutorService) {
|
||||
}
|
||||
}
|
||||
val shutdowns = shutdownActionFutures.map { Try.on { it.getOrThrow(1.seconds) } }
|
||||
shutdowns.reversed().forEach { when (it) {
|
||||
shutdowns.reversed().forEach {
|
||||
when (it) {
|
||||
is Try.Success ->
|
||||
try {
|
||||
it.value()
|
||||
@ -446,7 +457,8 @@ class ShutdownManager(private val executorService: ExecutorService) {
|
||||
log.warn("Exception while shutting down", t)
|
||||
}
|
||||
is Try.Failure -> log.warn("Exception while getting shutdown method, disregarding", it.exception)
|
||||
} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun registerShutdown(shutdown: CordaFuture<() -> Unit>) {
|
||||
@ -455,6 +467,7 @@ class ShutdownManager(private val executorService: ExecutorService) {
|
||||
registeredShutdowns.add(shutdown)
|
||||
}
|
||||
}
|
||||
|
||||
fun registerShutdown(shutdown: () -> Unit) = registerShutdown(doneFuture(shutdown))
|
||||
|
||||
fun registerProcessShutdown(processFuture: CordaFuture<Process>) {
|
||||
@ -746,10 +759,12 @@ class DriverDSL(
|
||||
if (startInProcess ?: startNodesInProcess) {
|
||||
val nodeAndThreadFuture = startInProcessNode(executorService, nodeConfiguration, config)
|
||||
shutdownManager.registerShutdown(
|
||||
nodeAndThreadFuture.map { (node, thread) -> {
|
||||
nodeAndThreadFuture.map { (node, thread) ->
|
||||
{
|
||||
node.stop()
|
||||
thread.interrupt()
|
||||
} }
|
||||
}
|
||||
}
|
||||
)
|
||||
return nodeAndThreadFuture.flatMap { (node, thread) ->
|
||||
establishRpc(nodeConfiguration.p2pAddress, nodeConfiguration, openFuture()).flatMap { rpc ->
|
||||
@ -857,8 +872,8 @@ class DriverDSL(
|
||||
workingDirectory = nodeConf.baseDirectory
|
||||
)
|
||||
}
|
||||
return processFuture.flatMap {
|
||||
process -> addressMustBeBoundFuture(executorService, nodeConf.p2pAddress, process).map { process }
|
||||
return processFuture.flatMap { process ->
|
||||
addressMustBeBoundFuture(executorService, nodeConf.p2pAddress, process).map { process }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user