[CORDA-1877]: Ensured Driver fails to start when Notary tried to bind an already bound port. (#4246)

This commit is contained in:
Michele Sollecito
2018-11-19 18:06:27 +00:00
committed by GitHub
parent cb9fc3391f
commit 2762c34ebe
2 changed files with 30 additions and 0 deletions

View File

@ -1,11 +1,13 @@
package net.corda.node
import net.corda.core.identity.CordaX500Name
import net.corda.core.utilities.NetworkHostAndPort
import net.corda.core.utilities.getOrThrow
import net.corda.core.internal.errors.AddressBindingException
import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.PortAllocation
import net.corda.testing.driver.driver
import net.corda.testing.node.NotarySpec
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.Test
@ -30,6 +32,25 @@ class AddressBindingFailureTests {
@Test
fun `H2 address`() = assertBindExceptionForOverrides { address -> mapOf("h2Settings" to mapOf("address" to address.toString()), "dataSourceProperties.dataSource.password" to "password") }
@Test
fun `notary P2P address`() {
ServerSocket(0).use { socket ->
val notaryName = CordaX500Name.parse("O=Notary Cleaning Service, L=Zurich, C=CH")
val address = InetSocketAddress(socket.localPort).toNetworkHostAndPort()
assertThatThrownBy {
driver(DriverParameters(startNodesInProcess = false,
notarySpecs = listOf(NotarySpec(notaryName)),
notaryCustomOverrides = mapOf("p2pAddress" to address.toString()),
portAllocation = portAllocation)
) {} }.isInstanceOfSatisfying(IllegalStateException::class.java) { error ->
assertThat(error.message).contains("Unable to start notaries")
}
}
}
private fun assertBindExceptionForOverrides(overrides: (NetworkHostAndPort) -> Map<String, Any?>) {
ServerSocket(0).use { socket ->