forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CORDA-1659]: Improve handling/logging of failed address binding. (co…
- Loading branch information
1 parent
c4d3522
commit 54161a6
Showing
11 changed files
with
220 additions
and
34 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
core/src/main/kotlin/net/corda/core/internal/errors/AddressBindingException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package net.corda.core.internal.errors | ||
|
||
import net.corda.core.CordaRuntimeException | ||
import net.corda.core.utilities.NetworkHostAndPort | ||
|
||
class AddressBindingException(val addresses: Set<NetworkHostAndPort>) : CordaRuntimeException(message(addresses)) { | ||
|
||
constructor(address: NetworkHostAndPort) : this(setOf(address)) | ||
|
||
private companion object { | ||
private fun message(addresses: Set<NetworkHostAndPort>): String { | ||
require(addresses.isNotEmpty()) | ||
return if (addresses.size > 1) { | ||
"Failed to bind on an address in ${addresses.joinToString(", ", "[", "]")}." | ||
} else { | ||
"Failed to bind on address ${addresses.single()}." | ||
} | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
node/src/integration-test/kotlin/net/corda/node/AddressBindingFailureTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.corda.node | ||
|
||
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 org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.api.Assertions.assertThatThrownBy | ||
import org.junit.Test | ||
import java.net.InetSocketAddress | ||
import java.net.ServerSocket | ||
|
||
class AddressBindingFailureTests { | ||
|
||
companion object { | ||
private val portAllocation = PortAllocation.Incremental(20_000) | ||
} | ||
|
||
@Test | ||
fun `p2p address`() = assertBindExceptionForOverrides { address -> mapOf("p2pAddress" to address.toString()) } | ||
|
||
@Test | ||
fun `rpc address`() = assertBindExceptionForOverrides { address -> mapOf("rpcSettings" to mapOf("address" to address.toString())) } | ||
|
||
@Test | ||
fun `rpc admin address`() = assertBindExceptionForOverrides { address -> mapOf("rpcSettings" to mapOf("adminAddress" to address.toString())) } | ||
|
||
@Test | ||
fun `H2 address`() = assertBindExceptionForOverrides { address -> mapOf("h2Settings" to mapOf("address" to address.toString())) } | ||
|
||
private fun assertBindExceptionForOverrides(overrides: (NetworkHostAndPort) -> Map<String, Any?>) { | ||
|
||
ServerSocket(0).use { socket -> | ||
|
||
val address = InetSocketAddress(socket.localPort).toNetworkHostAndPort() | ||
driver(DriverParameters(startNodesInProcess = true, notarySpecs = emptyList(), inMemoryDB = false, portAllocation = portAllocation)) { | ||
|
||
assertThatThrownBy { startNode(customOverrides = overrides(address)).getOrThrow() }.isInstanceOfSatisfying(AddressBindingException::class.java) { exception -> | ||
assertThat(exception.addresses).contains(address).withFailMessage("Expected addresses to contain $address but was ${exception.addresses}.") | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun InetSocketAddress.toNetworkHostAndPort() = NetworkHostAndPort(hostName, port) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.