diff --git a/node/build.gradle b/node/build.gradle index a536c9f275..bcd228fae2 100644 --- a/node/build.gradle +++ b/node/build.gradle @@ -209,6 +209,9 @@ tasks.withType(JavaCompile) { task integrationTest(type: Test) { testClassesDirs = sourceSets.integrationTest.output.classesDirs classpath = sourceSets.integrationTest.runtimeClasspath + + systemProperty 'testing.global.port.allocation.enabled', true + systemProperty 'testing.global.port.allocation.starting.port', 10000 } jar { diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt index 1b98472fec..4704416d0c 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt @@ -118,11 +118,24 @@ abstract class PortAllocation { /** * An implementation of [PortAllocation] which allocates ports sequentially */ - open class Incremental(startingPort: Int) : PortAllocation() { + open class Incremental(private val startingPort: Int) : PortAllocation() { + private companion object { + private const val FIRST_EPHEMERAL_PORT = 49152 + } + /** The backing [AtomicInteger] used to keep track of the currently allocated port */ val portCounter = AtomicInteger(startingPort) - override fun nextPort() = portCounter.andIncrement + override fun nextPort(): Int { + return portCounter.getAndUpdate { i -> + val next = i + 1 + if (next >= FIRST_EPHEMERAL_PORT) { + startingPort + } else { + next + } + } + } } } diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/GlobalTestPortAllocation.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/GlobalTestPortAllocation.kt index b6736bd5f0..f868bce7ef 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/GlobalTestPortAllocation.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/GlobalTestPortAllocation.kt @@ -12,8 +12,8 @@ fun incrementalPortAllocation(startingPortIfNoEnv: Int): PortAllocation { private object GlobalTestPortAllocation : PortAllocation.Incremental(startingPort = startingPort()) -private const val enablingEnvVar = "CORDA_TEST_GLOBAL_PORT_ALLOCATION_ENABLED" -private const val startingPortEnvVariable = "CORDA_TEST_GLOBAL_PORT_ALLOCATION_STARTING_PORT" +private const val enablingEnvVar = "TESTING_GLOBAL_PORT_ALLOCATION_ENABLED" +private const val startingPortEnvVariable = "TESTING_GLOBAL_PORT_ALLOCATION_STARTING_PORT" private val enablingSystemProperty = enablingEnvVar.toLowerCase().replace("_", ".") private val startingPortSystemProperty = startingPortEnvVariable.toLowerCase().replace("_", ".") private const val startingPortDefaultValue = 5000