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 40b922c1f2)
This commit is contained in:
Dan Newton 2018-08-04 13:26:41 +01:00 committed by Shams Asari
parent 0df77d5b64
commit 43272594f7
2 changed files with 16 additions and 19 deletions

View File

@ -125,22 +125,22 @@ class DriverTests {
} }
@Test @Test
fun `driver rejects multiple nodes with the same name`() { fun `driver rejects multiple nodes with the same name parallel`() {
driver(DriverParameters(startNodesInProcess = true)) { driver(DriverParameters(startNodesInProcess = true)) {
val nodes = listOf(newNode(DUMMY_BANK_A_NAME), newNode(DUMMY_BANK_B_NAME), newNode(DUMMY_BANK_A_NAME))
assertThatThrownBy { listOf(newNode(DUMMY_BANK_A_NAME)(), newNode(DUMMY_BANK_B_NAME)(), newNode(DUMMY_BANK_A_NAME)()).transpose().getOrThrow() }.isInstanceOf(IllegalArgumentException::class.java) assertThatIllegalArgumentException().isThrownBy {
nodes.parallelStream().map { it.invoke() }.toList().transpose().getOrThrow()
}
} }
} }
@Test @Test
fun `driver rejects multiple nodes with the same name parallel`() { fun `driver rejects multiple nodes with the same organisation name`() {
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) {
driver(DriverParameters(startNodesInProcess = true)) { newNode(CordaX500Name(commonName = "Notary", organisation = "R3CEV", locality = "New York", country = "US"))().getOrThrow()
assertThatIllegalArgumentException().isThrownBy {
val nodes = listOf(newNode(DUMMY_BANK_A_NAME), newNode(DUMMY_BANK_B_NAME), newNode(DUMMY_BANK_A_NAME)) newNode(CordaX500Name(commonName = "Regulator", organisation = "R3CEV", locality = "New York", country = "US"))().getOrThrow()
}
assertThatThrownBy { nodes.parallelStream().map { it.invoke() }.toList().transpose().getOrThrow() }.isInstanceOf(IllegalArgumentException::class.java)
} }
} }

View File

@ -103,7 +103,7 @@ class DriverDSLImpl(
private val cordappPackages = extraCordappPackagesToScan + getCallerPackage() private val cordappPackages = extraCordappPackagesToScan + getCallerPackage()
// Map from a nodes legal name to an observable emitting the number of nodes in its network map. // Map from a nodes legal name to an observable emitting the number of nodes in its network map.
private val countObservables = mutableMapOf<CordaX500Name, Observable<Int>>() private val countObservables = mutableMapOf<CordaX500Name, Observable<Int>>()
private val nodeNames = mutableSetOf<CordaX500Name>() private val nodeOrgs = mutableSetOf<String>()
/** /**
* Future which completes when the network map is available, whether a local one or one from the CZ. This future acts * 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 * 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() val p2pAddress = portAllocation.nextHostAndPort()
// TODO: Derive name from the full picked name, don't just wrap the common name // 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") val name = providedName ?: CordaX500Name("${oneOf(names).organisation}-${p2pAddress.port}", "London", "GB")
synchronized(nodeNames) { synchronized(nodeOrgs) {
val wasANewNode = nodeNames.add(name) require(nodeOrgs.add(name.organisation)) { "Node with organisation name ${name.organisation} is already started or starting" }
if (!wasANewNode) {
throw IllegalArgumentException("Node with name $name is already started or starting.")
}
} }
val registrationFuture = if (compatibilityZone?.rootCert != null) { val registrationFuture = if (compatibilityZone?.rootCert != null) {
// We don't need the network map to be available to be able to register the node // 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 = { val onNodeExit: () -> Unit = {
localNetworkMap?.nodeInfosCopier?.removeConfig(baseDirectory) localNetworkMap?.nodeInfosCopier?.removeConfig(baseDirectory)
countObservables.remove(config.corda.myLegalName) countObservables.remove(config.corda.myLegalName)
synchronized(nodeNames) { synchronized(nodeOrgs) {
nodeNames.remove(config.corda.myLegalName) nodeOrgs -= config.corda.myLegalName.organisation
} }
} }