CORDA-1837: Reject nodes that have the same organisation name in driver tests (#3740)

* Reject nodes that have the same organisation name as a previously registered node rather than the same X500 name

DriverDSLImpl -> NetworkVisibilityController -> register check organisation name rather than X500 name and throw IllegalStateException if already exists
Added test to DriverTests to test multiple organisation names end exceptionally

* Remove redundant test and store the organisation names rather than X500 names for driver tests
This commit is contained in:
Dan Newton 2018-08-04 13:26:41 +01:00 committed by Shams Asari
parent 286dc7b77d
commit 40b922c1f2
2 changed files with 15 additions and 15 deletions

View File

@ -134,25 +134,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, notarySpecs = emptyList())) {
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`() {
fun `driver rejects multiple nodes with the same organisation name`() {
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList())) {
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)
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()
}
}
}

View File

@ -933,12 +933,15 @@ class DriverDSLImpl(
* current nodes see everyone.
*/
private class NetworkVisibilityController {
private val nodeVisibilityHandles = ThreadBox(HashMap<CordaX500Name, VisibilityHandle>())
private val nodeVisibilityHandles = ThreadBox(HashMap<String, VisibilityHandle>())
fun register(name: CordaX500Name): VisibilityHandle {
val handle = VisibilityHandle()
nodeVisibilityHandles.locked {
require(putIfAbsent(name, handle) == null) { "Node with name $name is already started or starting" }
require(name.organisation !in keys) {
"Node with organisation name ${name.organisation} is already started or starting"
}
put(name.organisation, handle)
}
return handle
}