mirror of
https://github.com/corda/corda.git
synced 2024-12-27 08:22:35 +00:00
Merge pull request #3873 from corda/CORDA-1837-v3
CORDA-1837: Reject nodes that have the same organisation name in driver tests
This commit is contained in:
commit
56a1e59443
@ -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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user