[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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 ->

View File

@ -71,6 +71,7 @@ import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import java.util.concurrent.atomic.AtomicInteger
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
@ -396,6 +397,13 @@ class DriverDSLImpl(
NotaryHandle(identity, validating, nodeHandlesFuture)
}
}
try {
_notaries.map { notary -> notary.map { handle -> handle.nodeHandles } }.getOrThrow(notaryHandleTimeout).forEach { future -> future.getOrThrow(notaryHandleTimeout) }
} catch (e: ListenProcessDeathException) {
throw IllegalStateException("Unable to start notaries. A required port might be bound already.", e)
} catch (e: TimeoutException) {
throw IllegalStateException("Unable to start notaries. A required port might be bound already.", e)
}
}
private fun startNotaryIdentityGeneration(): CordaFuture<List<NotaryInfo>> {
@ -700,6 +708,7 @@ class DriverDSLImpl(
companion object {
internal val log = contextLogger()
private val notaryHandleTimeout = Duration.ofMinutes(1)
private val defaultRpcUserList = listOf(InternalUser("default", "default", setOf("ALL")).toConfig().root().unwrapped())
private val names = arrayOf(ALICE_NAME, BOB_NAME, DUMMY_BANK_A_NAME)
/**