From c43dd079e4966f8ca1886e6de6ecbcaa20f0f1c9 Mon Sep 17 00:00:00 2001 From: joeldudleyr3 Date: Fri, 1 Sep 2017 15:34:57 +0100 Subject: [PATCH] Addresses review feedback. --- .../kotlin/net/corda/testing/driver/Driver.kt | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/test-utils/src/main/kotlin/net/corda/testing/driver/Driver.kt b/test-utils/src/main/kotlin/net/corda/testing/driver/Driver.kt index 44933024c0..e2c2539f10 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/driver/Driver.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/driver/Driver.kt @@ -229,6 +229,8 @@ sealed class PortAllocation { * * The driver implicitly bootstraps a [NetworkMapService]. * + * @param defaultParameters The default parameters for the driver. Allows the driver to be configured in builder style + * when called from Java code. * @param isDebug Indicates whether the spawned nodes should start in jdwt debug mode and have debug level logging. * @param driverDirectory The base directory node directories go into, defaults to "build//". The node * directories themselves are "//", where legalName defaults to "-" @@ -244,9 +246,9 @@ sealed class PortAllocation { * @return The value returned in the [dsl] closure. */ fun driver( + defaultParameters: DriverParameters = DriverParameters(), isDebug: Boolean = defaultParameters.isDebug, - // The directory must be different for each call to `driver`. - driverDirectory: Path = Paths.get("build", getTimestampAsDirectoryName()), + driverDirectory: Path = defaultParameters.driverDirectory, portAllocation: PortAllocation = defaultParameters.portAllocation, debugPortAllocation: PortAllocation = defaultParameters.debugPortAllocation, systemProperties: Map = defaultParameters.systemProperties, @@ -273,24 +275,23 @@ fun driver( ) } +/** + * Helper function for starting a [driver] with custom parameters from Java. + * + * @param defaultParameters The default parameters for the driver. + * @param dsl The dsl itself. + * @return The value returned in the [dsl] closure. + */ fun driver( parameters: DriverParameters, dsl: DriverDSLExposedInterface.() -> A ): A { - 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 - ) + return driver(defaultParameters = parameters, dsl = dsl) } +/** + * Helper builder for configuring a [driver] from Java. + */ data class DriverParameters( val isDebug: Boolean = false, val driverDirectory: Path = Paths.get("build", getTimestampAsDirectoryName()), @@ -313,8 +314,6 @@ data class DriverParameters( 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