From e216b7715e05695db298c0bb2207a4ffee83c6ee Mon Sep 17 00:00:00 2001 From: Adel El-Beik <48713346+adelel1@users.noreply.github.com> Date: Fri, 3 Mar 2023 17:54:52 +0000 Subject: [PATCH] ENT-9476: Notary handle timeout can now be passed to driver. (#7302) * ENT-9476: Notary handle timeout can now be passed to driver. --- .../kotlin/net/corda/testing/driver/Driver.kt | 55 ++++++++++++++++++- .../testing/node/internal/DriverDSLImpl.kt | 11 ++-- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt index cfd06a585b..c17b8c3076 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt @@ -29,6 +29,7 @@ import rx.Observable import java.io.File import java.nio.file.Path import java.nio.file.Paths +import java.time.Duration import java.util.concurrent.atomic.AtomicInteger /** @@ -216,7 +217,8 @@ fun driver(defaultParameters: DriverParameters = DriverParameters(), dsl: Dr djvmCordaSource = defaultParameters.djvmCordaSource, environmentVariables = defaultParameters.environmentVariables, allowHibernateToManageAppSchema = defaultParameters.allowHibernateToManageAppSchema, - premigrateH2Database = defaultParameters.premigrateH2Database + premigrateH2Database = defaultParameters.premigrateH2Database, + notaryHandleTimeout = defaultParameters.notaryHandleTimeout ), coerce = { it }, dsl = dsl @@ -256,6 +258,8 @@ fun driver(defaultParameters: DriverParameters = DriverParameters(), dsl: Dr * @property djvmBootstrapSource Location of a JAR containing the Java APIs for the DJVM to use. * @property djvmCordaSource Locations of JARs of user-supplied classes to execute within the DJVM sandbox. * @property premigrateH2Database Whether to use a prebuilt H2 database schema or start from an empty schema. + * @property notaryHandleTimeout Specifies how long to wait to receive a notary handle. This waiting includes waiting for + * the notary to start. * This can save time for tests which do not need to migrate from a blank schema. */ @Suppress("unused") @@ -281,7 +285,8 @@ data class DriverParameters( val djvmCordaSource: List = emptyList(), val environmentVariables: Map = emptyMap(), val allowHibernateToManageAppSchema: Boolean = true, - val premigrateH2Database: Boolean = true + val premigrateH2Database: Boolean = true, + val notaryHandleTimeout: Duration = Duration.ofMinutes(1) ) { constructor(cordappsForAllNodes: Collection) : this(isDebug = false, cordappsForAllNodes = cordappsForAllNodes) @@ -464,6 +469,51 @@ data class DriverParameters( cordappsForAllNodes = null ) + constructor( + isDebug: Boolean, + driverDirectory: Path, + portAllocation: PortAllocation, + debugPortAllocation: PortAllocation, + systemProperties: Map, + useTestClock: Boolean, + startNodesInProcess: Boolean, + waitForAllNodesToFinish: Boolean, + notarySpecs: List, + extraCordappPackagesToScan: List, + jmxPolicy: JmxPolicy, + networkParameters: NetworkParameters, + notaryCustomOverrides: Map, + inMemoryDB: Boolean, + cordappsForAllNodes: Collection?, + djvmBootstrapSource: Path?, + djvmCordaSource: List, + environmentVariables: Map, + allowHibernateToManageAppSchema: Boolean, + premigrateH2Database: Boolean + ) : this( + isDebug, + driverDirectory, + portAllocation, + debugPortAllocation, + systemProperties, + useTestClock, + startNodesInProcess, + waitForAllNodesToFinish, + notarySpecs, + extraCordappPackagesToScan, + jmxPolicy, + networkParameters, + notaryCustomOverrides, + inMemoryDB, + cordappsForAllNodes, + djvmBootstrapSource, + djvmCordaSource, + environmentVariables, + allowHibernateToManageAppSchema, + premigrateH2Database, + notaryHandleTimeout = Duration.ofMinutes(1) + ) + fun withIsDebug(isDebug: Boolean): DriverParameters = copy(isDebug = isDebug) fun withDriverDirectory(driverDirectory: Path): DriverParameters = copy(driverDirectory = driverDirectory) fun withPortAllocation(portAllocation: PortAllocation): DriverParameters = copy(portAllocation = portAllocation) @@ -487,6 +537,7 @@ data class DriverParameters( fun withDjvmCordaSource(djvmCordaSource: List): DriverParameters = copy(djvmCordaSource = djvmCordaSource) fun withEnvironmentVariables(variables: Map): DriverParameters = copy(environmentVariables = variables) fun withAllowHibernateToManageAppSchema(value: Boolean): DriverParameters = copy(allowHibernateToManageAppSchema = value) + fun withNotaryHandleTimeout(value: Duration): DriverParameters = copy(notaryHandleTimeout = value) fun copy( isDebug: Boolean, diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt index 8f1c33c953..5dc744d1bf 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt @@ -154,7 +154,8 @@ class DriverDSLImpl( val djvmCordaSource: List, val environmentVariables: Map, val allowHibernateToManageAppSchema: Boolean = true, - val premigrateH2Database: Boolean = true + val premigrateH2Database: Boolean = true, + val notaryHandleTimeout: Duration = Duration.ofMinutes(1) ) : InternalDriverDSL { private var _executorService: ScheduledExecutorService? = null @@ -854,7 +855,6 @@ class DriverDSLImpl( // While starting with inProcess mode, we need to have different names to avoid clashes private val inMemoryCounter = AtomicInteger() - private val notaryHandleTimeout = Duration.ofMinutes(1) private val defaultRpcUserList = listOf(InternalUser("default", "default", setOf("ALL")).toConfig().root().unwrapped()) private val names = arrayOf(ALICE_NAME, BOB_NAME, DUMMY_BANK_A_NAME) @@ -1332,7 +1332,8 @@ fun genericDriver( djvmCordaSource = defaultParameters.djvmCordaSource, environmentVariables = defaultParameters.environmentVariables, allowHibernateToManageAppSchema = defaultParameters.allowHibernateToManageAppSchema, - premigrateH2Database = defaultParameters.premigrateH2Database + premigrateH2Database = defaultParameters.premigrateH2Database, + notaryHandleTimeout = defaultParameters.notaryHandleTimeout ) ) val shutdownHook = addShutdownHook(driverDsl::shutdown) @@ -1432,6 +1433,7 @@ fun internalDriver( environmentVariables: Map = emptyMap(), allowHibernateToManageAppSchema: Boolean = true, premigrateH2Database: Boolean = true, + notaryHandleTimeout: Duration = Duration.ofMinutes(1), dsl: DriverDSLImpl.() -> A ): A { return genericDriver( @@ -1456,7 +1458,8 @@ fun internalDriver( djvmCordaSource = djvmCordaSource, environmentVariables = environmentVariables, allowHibernateToManageAppSchema = allowHibernateToManageAppSchema, - premigrateH2Database = premigrateH2Database + premigrateH2Database = premigrateH2Database, + notaryHandleTimeout = notaryHandleTimeout ), coerce = { it }, dsl = dsl