From 43272594f784b2dccfb577d2116a07a8452aa337 Mon Sep 17 00:00:00 2001 From: Dan Newton Date: Sat, 4 Aug 2018 13:26:41 +0100 Subject: [PATCH] CORDA-1837: Reject nodes that have the same organisation name in driver tests * Reject nodes that have the same organisation name as a previously registered node rather than the same X500 name (cherry picked from commit 40b922c1f2e620a5665f6f2385cdafd5e70bd780) --- .../net/corda/testing/driver/DriverTests.kt | 22 +++++++++---------- .../testing/node/internal/DriverDSLImpl.kt | 13 +++++------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/testing/node-driver/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt b/testing/node-driver/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt index f438548171..82cb45c8da 100644 --- a/testing/node-driver/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt +++ b/testing/node-driver/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt @@ -125,22 +125,22 @@ class DriverTests { } @Test - fun `driver rejects multiple nodes with the same name`() { - + fun `driver rejects multiple nodes with the same name parallel`() { driver(DriverParameters(startNodesInProcess = true)) { - - assertThatThrownBy { listOf(newNode(DUMMY_BANK_A_NAME)(), newNode(DUMMY_BANK_B_NAME)(), newNode(DUMMY_BANK_A_NAME)()).transpose().getOrThrow() }.isInstanceOf(IllegalArgumentException::class.java) + val nodes = listOf(newNode(DUMMY_BANK_A_NAME), newNode(DUMMY_BANK_B_NAME), newNode(DUMMY_BANK_A_NAME)) + assertThatIllegalArgumentException().isThrownBy { + nodes.parallelStream().map { it.invoke() }.toList().transpose().getOrThrow() + } } } @Test - fun `driver rejects multiple nodes with the same name parallel`() { - - driver(DriverParameters(startNodesInProcess = true)) { - - val nodes = listOf(newNode(DUMMY_BANK_A_NAME), newNode(DUMMY_BANK_B_NAME), newNode(DUMMY_BANK_A_NAME)) - - assertThatThrownBy { nodes.parallelStream().map { it.invoke() }.toList().transpose().getOrThrow() }.isInstanceOf(IllegalArgumentException::class.java) + fun `driver rejects multiple nodes with the same organisation name`() { + driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) { + newNode(CordaX500Name(commonName = "Notary", organisation = "R3CEV", locality = "New York", country = "US"))().getOrThrow() + assertThatIllegalArgumentException().isThrownBy { + newNode(CordaX500Name(commonName = "Regulator", organisation = "R3CEV", locality = "New York", country = "US"))().getOrThrow() + } } } 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 e255cdd499..0f95bdd1bc 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 @@ -103,7 +103,7 @@ class DriverDSLImpl( private val cordappPackages = extraCordappPackagesToScan + getCallerPackage() // Map from a nodes legal name to an observable emitting the number of nodes in its network map. private val countObservables = mutableMapOf>() - private val nodeNames = mutableSetOf() + private val nodeOrgs = mutableSetOf() /** * Future which completes when the network map 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] object, which @@ -194,11 +194,8 @@ class DriverDSLImpl( val p2pAddress = portAllocation.nextHostAndPort() // TODO: Derive name from the full picked name, don't just wrap the common name val name = providedName ?: CordaX500Name("${oneOf(names).organisation}-${p2pAddress.port}", "London", "GB") - synchronized(nodeNames) { - val wasANewNode = nodeNames.add(name) - if (!wasANewNode) { - throw IllegalArgumentException("Node with name $name is already started or starting.") - } + synchronized(nodeOrgs) { + require(nodeOrgs.add(name.organisation)) { "Node with organisation name ${name.organisation} is already started or starting" } } val registrationFuture = if (compatibilityZone?.rootCert != null) { // We don't need the network map to be available to be able to register the node @@ -664,8 +661,8 @@ class DriverDSLImpl( val onNodeExit: () -> Unit = { localNetworkMap?.nodeInfosCopier?.removeConfig(baseDirectory) countObservables.remove(config.corda.myLegalName) - synchronized(nodeNames) { - nodeNames.remove(config.corda.myLegalName) + synchronized(nodeOrgs) { + nodeOrgs -= config.corda.myLegalName.organisation } }