CORDA-2759: Use GlobalTestPortAllocation for Node's integration tests. (#4899)

This commit is contained in:
Chris Rankin 2019-03-18 14:48:13 +00:00 committed by josecoll
parent a90f394d43
commit 1fc8e1d7ae
3 changed files with 20 additions and 4 deletions

View File

@ -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 {

View File

@ -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
}
}
}
}
}

View File

@ -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