From b1e2d6a48c748555c3ec39196689db4da3c55c72 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Tue, 1 Sep 2020 19:40:39 +0100 Subject: [PATCH] NOTICK Reformat DriverDSLImpl.kt (#6685) Reformat DriverDSLImpl to standard IntelliJ style --- .../testing/node/internal/DriverDSLImpl.kt | 198 +++++++++--------- 1 file changed, 102 insertions(+), 96 deletions(-) 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 eb724758c5..7dc567f54a 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 @@ -1,4 +1,5 @@ @file:Suppress("TooManyFunctions", "Deprecation") + package net.corda.testing.node.internal import co.paralleluniverse.fibers.instrument.JavaAgent @@ -147,7 +148,7 @@ class DriverDSLImpl( val cordappsForAllNodes: Collection?, val djvmBootstrapSource: Path?, val djvmCordaSource: List, - val environmentVariables : Map, + val environmentVariables: Map, val allowHibernateToManageAppSchema: Boolean = true ) : InternalDriverDSL { @@ -156,8 +157,10 @@ class DriverDSLImpl( private var _shutdownManager: ShutdownManager? = null override val shutdownManager get() = _shutdownManager!! private lateinit var extraCustomCordapps: Set + // Map from a nodes legal name to an observable emitting the number of nodes in its network map. private val networkVisibilityController = NetworkVisibilityController() + /** * Future which completes when the network map infrastructure is available, whether a local one or one from the CZ. * This future acts as a gate to prevent nodes from starting too early. The value of the future is a [LocalNetworkMap] @@ -274,7 +277,7 @@ class DriverDSLImpl( } return registrationFuture.flatMap { conf -> - networkMapAvailability.flatMap {networkMap -> + networkMapAvailability.flatMap { networkMap -> // But starting the node proper does require the network map startRegisteredNode(conf, networkMap, parameters, bytemanPort) } @@ -380,9 +383,9 @@ class DriverDSLImpl( startOutOfProcessMiniNode( config, arrayOf( - "initial-registration", - "--network-root-truststore=${rootTruststorePath.toAbsolutePath()}", - "--network-root-truststore-password=$rootTruststorePassword" + "initial-registration", + "--network-root-truststore=${rootTruststorePath.toAbsolutePath()}", + "--network-root-truststore-password=$rootTruststorePassword" ) ).map { config } } @@ -424,13 +427,13 @@ class DriverDSLImpl( _shutdownManager = ShutdownManager(executorService) val callerPackage = getCallerPackage().toMutableList() - if(callerPackage.firstOrNull()?.startsWith("net.corda.node") == true) callerPackage.add("net.corda.testing") + if (callerPackage.firstOrNull()?.startsWith("net.corda.node") == true) callerPackage.add("net.corda.testing") extraCustomCordapps = cordappsForPackages(extraCordappPackagesToScan + callerPackage) val notaryInfosFuture = if (compatibilityZone == null) { // If no CZ is specified then the driver does the generation of the network parameters and the copying of the // node info files. - startNotaryIdentityGeneration().map { notaryInfos -> Pair(notaryInfos, LocalNetworkMap(notaryInfos.map{it.second})) } + startNotaryIdentityGeneration().map { notaryInfos -> Pair(notaryInfos, LocalNetworkMap(notaryInfos.map { it.second })) } } else { // Otherwise it's the CZ's job to distribute thse via the HTTP network map, as that is what the nodes will be expecting. val notaryInfosFuture = if (compatibilityZone.rootCert == null) { @@ -441,7 +444,7 @@ class DriverDSLImpl( startAllNotaryRegistrations(compatibilityZone.rootCert, compatibilityZone) } notaryInfosFuture.map { notaryInfos -> - compatibilityZone.publishNotaries(notaryInfos.map{it.second}) + compatibilityZone.publishNotaries(notaryInfos.map { it.second }) Pair(notaryInfos, null) } } @@ -449,14 +452,15 @@ class DriverDSLImpl( networkMapAvailability = notaryInfosFuture.map { it.second } _notaries = notaryInfosFuture.map { (notaryInfos, localNetworkMap) -> - val listOfFutureNodeHandles = startNotaries(notaryInfos.map{it.first}, localNetworkMap, notaryCustomOverrides) + val listOfFutureNodeHandles = startNotaries(notaryInfos.map { it.first }, localNetworkMap, notaryCustomOverrides) notaryInfos.zip(listOfFutureNodeHandles) { (_, notaryInfo), nodeHandlesFuture -> NotaryHandle(notaryInfo.identity, notaryInfo.validating, nodeHandlesFuture) } } try { - _notaries.map { notary -> notary.map { handle -> handle.nodeHandles } }.getOrThrow(notaryHandleTimeout).forEach { future -> future.getOrThrow(notaryHandleTimeout) } - } catch(e: NodeListenProcessDeathException) { + _notaries.map { notary -> notary.map { handle -> handle.nodeHandles } }.getOrThrow(notaryHandleTimeout) + .forEach { future -> future.getOrThrow(notaryHandleTimeout) } + } catch (e: NodeListenProcessDeathException) { val message = if (e.causeFromStdError.isNotBlank()) { "Unable to start notaries. Failed with the following error: ${e.causeFromStdError}" } else { @@ -491,7 +495,7 @@ class DriverDSLImpl( } } - private fun startNotaryIdentityGeneration(): CordaFuture>> { + private fun startNotaryIdentityGeneration(): CordaFuture>> { return executorService.fork { notarySpecs.map { spec -> val notaryConfig = mapOf("notary" to mapOf("validating" to spec.validating)) @@ -541,32 +545,32 @@ class DriverDSLImpl( spec: NotarySpec, rootCert: X509Certificate, compatibilityZone: CompatibilityZoneParams - ): CordaFuture> { + ): CordaFuture> { val parameters = NodeParameters(rpcUsers = spec.rpcUsers, verifierType = spec.verifierType, customOverrides = notaryCustomOverrides, maximumHeapSize = spec.maximumHeapSize) return createSchema(createConfig(spec.name, parameters), false).flatMap { config -> - startNodeRegistration(config, rootCert, compatibilityZone.config())}.flatMap { config -> - // Node registration only gives us the node CA cert, not the identity cert. That is only created on first - // startup or when the node is told to just generate its node info file. We do that here. - if (startNodesInProcess) { - executorService.fork { - val nodeInfo = Node(config.corda, MOCK_VERSION_INFO, initialiseSerialization = false).generateAndSaveNodeInfo() - Pair(config.withNotaryDefinition(spec.validating), NotaryInfo(nodeInfo.legalIdentities[0], spec.validating)) - } - } else { - // TODO The config we use here is uses a hardocded p2p port which changes when the node is run proper - // This causes two node info files to be generated. - startOutOfProcessMiniNode(config, arrayOf("generate-node-info")).map { - // Once done we have to read the signed node info file that's been generated - val nodeInfoFile = config.corda.baseDirectory.list { paths -> - paths.filter { it.fileName.toString().startsWith(NodeInfoFilesCopier.NODE_INFO_FILE_NAME_PREFIX) }.findFirst() - .get() - } - val nodeInfo = nodeInfoFile.readObject().verified() - Pair(config.withNotaryDefinition(spec.validating), NotaryInfo(nodeInfo.legalIdentities[0], spec.validating)) + startNodeRegistration(config, rootCert, compatibilityZone.config()) + }.flatMap { config -> + // Node registration only gives us the node CA cert, not the identity cert. That is only created on first + // startup or when the node is told to just generate its node info file. We do that here. + if (startNodesInProcess) { + executorService.fork { + val nodeInfo = Node(config.corda, MOCK_VERSION_INFO, initialiseSerialization = false).generateAndSaveNodeInfo() + Pair(config.withNotaryDefinition(spec.validating), NotaryInfo(nodeInfo.legalIdentities[0], spec.validating)) + } + } else { + // TODO The config we use here is uses a hardocded p2p port which changes when the node is run proper + // This causes two node info files to be generated. + startOutOfProcessMiniNode(config, arrayOf("generate-node-info")).map { + // Once done we have to read the signed node info file that's been generated + val nodeInfoFile = config.corda.baseDirectory.list { paths -> + paths.filter { it.fileName.toString().startsWith(NodeInfoFilesCopier.NODE_INFO_FILE_NAME_PREFIX) }.findFirst() + .get() } + val nodeInfo = nodeInfoFile.readObject().verified() + Pair(config.withNotaryDefinition(spec.validating), NotaryInfo(nodeInfo.legalIdentities[0], spec.validating)) } } - + } } private fun generateNodeNames(spec: NotarySpec): List { @@ -575,7 +579,7 @@ class DriverDSLImpl( private fun startNotaries(configs: List, localNetworkMap: LocalNetworkMap?, customOverrides: Map): List>> { return notarySpecs.zip(configs).map { (spec, config) -> - when (spec.cluster) { + when (spec.cluster) { null -> startSingleNotary(config, spec, localNetworkMap, customOverrides) is ClusterSpec.Raft, // DummyCluster is used for testing the notary communication path, and it does not matter @@ -589,13 +593,13 @@ class DriverDSLImpl( private fun startSingleNotary(config: NodeConfig, spec: NotarySpec, localNetworkMap: LocalNetworkMap?, customOverrides: Map): CordaFuture> { val notaryConfig = mapOf("notary" to mapOf("validating" to spec.validating)) return startRegisteredNode( - config, - localNetworkMap, - NodeParameters(rpcUsers = spec.rpcUsers, - verifierType = spec.verifierType, - startInSameProcess = spec.startInProcess, - customOverrides = notaryConfig + customOverrides, - maximumHeapSize = spec.maximumHeapSize) + config, + localNetworkMap, + NodeParameters(rpcUsers = spec.rpcUsers, + verifierType = spec.verifierType, + startInSameProcess = spec.startInProcess, + customOverrides = notaryConfig + customOverrides, + maximumHeapSize = spec.maximumHeapSize) ).map { listOf(it) } } @@ -762,14 +766,14 @@ class DriverDSLImpl( } val effectiveP2PAddress = config.corda.messagingServerAddress ?: config.corda.p2pAddress val p2pReadyFuture = nodeMustBeStartedFuture( - executorService, - config.corda.baseDirectory / "net.corda.node.Corda.${identifier}.stdout.log", - process + executorService, + config.corda.baseDirectory / "net.corda.node.Corda.${identifier}.stdout.log", + process ) { NodeListenProcessDeathException( - effectiveP2PAddress, - process, - (config.corda.baseDirectory / "net.corda.node.Corda.$identifier.stderr.log").readText() + effectiveP2PAddress, + process, + (config.corda.baseDirectory / "net.corda.node.Corda.$identifier.stderr.log").readText() ) } @@ -808,6 +812,7 @@ class DriverDSLImpl( */ inner class LocalNetworkMap(notaryInfos: List) { val networkParametersCopier = NetworkParametersCopier(networkParameters.copy(notaries = notaryInfos)) + // TODO: this object will copy NodeInfo files from started nodes to other nodes additional-node-infos/ // This uses the FileSystem and adds a delay (~5 seconds) given by the time we wait before polling the file system. // Investigate whether we can avoid that. @@ -836,6 +841,7 @@ class DriverDSLImpl( 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) + /** * A sub-set of permissions that grant most of the essential operations used in the unit/integration tests as well as * in demo application like NodeExplorer. @@ -860,14 +866,14 @@ class DriverDSLImpl( private const val CORDA_TESTING_ATTRIBUTE = "Corda-Testing" private val CORDAPP_MANIFEST_ATTRIBUTES: List = unmodifiableList(listOf( - CORDAPP_CONTRACT_NAME, - CORDAPP_CONTRACT_LICENCE, - CORDAPP_CONTRACT_VENDOR, - CORDAPP_CONTRACT_VERSION, - CORDAPP_WORKFLOW_NAME, - CORDAPP_WORKFLOW_LICENCE, - CORDAPP_WORKFLOW_VENDOR, - CORDAPP_WORKFLOW_VERSION + CORDAPP_CONTRACT_NAME, + CORDAPP_CONTRACT_LICENCE, + CORDAPP_CONTRACT_VENDOR, + CORDAPP_CONTRACT_VERSION, + CORDAPP_WORKFLOW_NAME, + CORDAPP_WORKFLOW_LICENCE, + CORDAPP_WORKFLOW_VENDOR, + CORDAPP_WORKFLOW_VERSION )) /** @@ -942,7 +948,7 @@ class DriverDSLImpl( maximumHeapSize: String, logLevelOverride: String?, identifier: String, - environmentVariables : Map, + environmentVariables: Map, extraCmdLineFlag: Array = emptyArray() ): Process { log.info("Starting out-of-process Node ${config.corda.myLegalName.organisation}, " + @@ -983,7 +989,6 @@ class DriverDSLImpl( else -> "DEBUG" } - val arguments = mutableListOf( "--base-directory=${config.corda.baseDirectory}", "--logging-level=$loggingLevel", @@ -1007,11 +1012,11 @@ class DriverDSLImpl( // The following dependencies are excluded from the classpath of the created JVM, // so that the environment resembles a real one as close as possible. - val cp = ProcessUtilities.defaultClassPath.filter { cpEntry -> + val cp = ProcessUtilities.defaultClassPath.filter { cpEntry -> val cpPathEntry = Paths.get(cpEntry) cpPathEntry.isRegularFile() - && !isTestArtifact(cpPathEntry.fileName.toString()) - && !cpPathEntry.isExcludedJar + && !isTestArtifact(cpPathEntry.fileName.toString()) + && !cpPathEntry.isExcludedJar } return ProcessUtilities.startJavaProcess( @@ -1050,12 +1055,13 @@ class DriverDSLImpl( || (manifest[TARGET_PLATFORM_VERSION] != null && manifest[MIN_PLATFORM_VERSION] != null) } - private val Path.isExcludedJar: Boolean get() { - return JarInputStream(Files.newInputStream(this).buffered()).use { jar -> - val manifest = jar.manifest ?: return false - isCordapp(manifest) || isTestArtifact(manifest) + private val Path.isExcludedJar: Boolean + get() { + return JarInputStream(Files.newInputStream(this).buffered()).use { jar -> + val manifest = jar.manifest ?: return false + isCordapp(manifest) || isTestArtifact(manifest) + } } - } private fun startWebserver(handle: NodeHandleInternal, debugPort: Int?, maximumHeapSize: String): Process { val className = "net.corda.webserver.WebServer" @@ -1224,8 +1230,8 @@ interface InternalDriverDSL : DriverDSL { fun shutdown() fun startNode( - parameters: NodeParameters = NodeParameters(), - bytemanPort: Int? = null + parameters: NodeParameters = NodeParameters(), + bytemanPort: Int? = null ): CordaFuture } @@ -1272,28 +1278,28 @@ fun genericDriver( ): A { setDriverSerialization().use { _ -> val driverDsl = driverDslWrapper( - DriverDSLImpl( - portAllocation = defaultParameters.portAllocation, - debugPortAllocation = defaultParameters.debugPortAllocation, - systemProperties = defaultParameters.systemProperties, - driverDirectory = defaultParameters.driverDirectory.toAbsolutePath(), - useTestClock = defaultParameters.useTestClock, - isDebug = defaultParameters.isDebug, - startNodesInProcess = defaultParameters.startNodesInProcess, - waitForAllNodesToFinish = defaultParameters.waitForAllNodesToFinish, - extraCordappPackagesToScan = @Suppress("DEPRECATION") defaultParameters.extraCordappPackagesToScan, - jmxPolicy = defaultParameters.jmxPolicy, - notarySpecs = defaultParameters.notarySpecs, - compatibilityZone = null, - networkParameters = defaultParameters.networkParameters, - notaryCustomOverrides = defaultParameters.notaryCustomOverrides, - inMemoryDB = defaultParameters.inMemoryDB, - cordappsForAllNodes = uncheckedCast(defaultParameters.cordappsForAllNodes), - djvmBootstrapSource = defaultParameters.djvmBootstrapSource, - djvmCordaSource = defaultParameters.djvmCordaSource, - environmentVariables = defaultParameters.environmentVariables, - allowHibernateToManageAppSchema = defaultParameters.allowHibernateToManageAppSchema - ) + DriverDSLImpl( + portAllocation = defaultParameters.portAllocation, + debugPortAllocation = defaultParameters.debugPortAllocation, + systemProperties = defaultParameters.systemProperties, + driverDirectory = defaultParameters.driverDirectory.toAbsolutePath(), + useTestClock = defaultParameters.useTestClock, + isDebug = defaultParameters.isDebug, + startNodesInProcess = defaultParameters.startNodesInProcess, + waitForAllNodesToFinish = defaultParameters.waitForAllNodesToFinish, + extraCordappPackagesToScan = @Suppress("DEPRECATION") defaultParameters.extraCordappPackagesToScan, + jmxPolicy = defaultParameters.jmxPolicy, + notarySpecs = defaultParameters.notarySpecs, + compatibilityZone = null, + networkParameters = defaultParameters.networkParameters, + notaryCustomOverrides = defaultParameters.notaryCustomOverrides, + inMemoryDB = defaultParameters.inMemoryDB, + cordappsForAllNodes = uncheckedCast(defaultParameters.cordappsForAllNodes), + djvmBootstrapSource = defaultParameters.djvmBootstrapSource, + djvmCordaSource = defaultParameters.djvmCordaSource, + environmentVariables = defaultParameters.environmentVariables, + allowHibernateToManageAppSchema = defaultParameters.allowHibernateToManageAppSchema + ) ) val shutdownHook = addShutdownHook(driverDsl::shutdown) try { @@ -1328,7 +1334,7 @@ sealed class CompatibilityZoneParams( ) { abstract fun networkMapURL(): URL abstract fun doormanURL(): URL - abstract fun config() : NetworkServicesConfig + abstract fun config(): NetworkServicesConfig } /** @@ -1336,18 +1342,18 @@ sealed class CompatibilityZoneParams( */ class SharedCompatibilityZoneParams( private val url: URL, - private val pnm : UUID?, + private val pnm: UUID?, publishNotaries: (List) -> Unit, rootCert: X509Certificate? = null ) : CompatibilityZoneParams(publishNotaries, rootCert) { - val config : NetworkServicesConfig by lazy { + val config: NetworkServicesConfig by lazy { NetworkServicesConfig(url, url, pnm, false) } override fun doormanURL() = url override fun networkMapURL() = url - override fun config() : NetworkServicesConfig = config + override fun config(): NetworkServicesConfig = config } /** @@ -1356,17 +1362,17 @@ class SharedCompatibilityZoneParams( class SplitCompatibilityZoneParams( private val doormanURL: URL, private val networkMapURL: URL, - private val pnm : UUID?, + private val pnm: UUID?, publishNotaries: (List) -> Unit, rootCert: X509Certificate? = null ) : CompatibilityZoneParams(publishNotaries, rootCert) { - val config : NetworkServicesConfig by lazy { + val config: NetworkServicesConfig by lazy { NetworkServicesConfig(doormanURL, networkMapURL, pnm, false) } override fun doormanURL() = doormanURL override fun networkMapURL() = networkMapURL - override fun config() : NetworkServicesConfig = config + override fun config(): NetworkServicesConfig = config } @Suppress("LongParameterList")