Enabled system property / env variable cascade for global test port allocation toggles. (#4336)

This commit is contained in:
Michele Sollecito 2018-11-30 16:40:29 +00:00 committed by GitHub
parent 27a80900bd
commit 38438eadcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,11 +1,15 @@
package net.corda.testing.driver.internal
import net.corda.testing.driver.PortAllocation
import net.corda.testing.driver.internal.GlobalTestPortAllocation.enablingEnvVar
import net.corda.testing.driver.internal.GlobalTestPortAllocation.enablingSystemProperty
import net.corda.testing.driver.internal.GlobalTestPortAllocation.startingPortEnvVariable
import net.corda.testing.driver.internal.GlobalTestPortAllocation.startingPortSystemProperty
fun incrementalPortAllocation(startingPortIfNoEnv: Int): PortAllocation {
return when {
System.getenv(GlobalTestPortAllocation.enablingEnvVar)?.toBoolean() == true -> GlobalTestPortAllocation
System.getProperty(enablingSystemProperty)?.toBoolean() ?: System.getenv(enablingEnvVar)?.toBoolean() == true -> GlobalTestPortAllocation
else -> PortAllocation.Incremental(startingPortIfNoEnv)
}
}
@ -14,7 +18,9 @@ private object GlobalTestPortAllocation : PortAllocation.Incremental(startingPor
const val enablingEnvVar = "CORDA_TEST_GLOBAL_PORT_ALLOCATION_ENABLED"
const val startingPortEnvVariable = "CORDA_TEST_GLOBAL_PORT_ALLOCATION_STARTING_PORT"
val enablingSystemProperty = enablingEnvVar.toLowerCase().replace("_", ".")
val startingPortSystemProperty = startingPortEnvVariable.toLowerCase().replace("_", ".")
const val startingPortDefaultValue = 5000
}
private val startingPort: Int = System.getenv(GlobalTestPortAllocation.startingPortEnvVariable)?.toIntOrNull() ?: GlobalTestPortAllocation.startingPortDefaultValue
private val startingPort: Int = System.getProperty(startingPortSystemProperty)?.toIntOrNull() ?: System.getenv(startingPortEnvVariable)?.toIntOrNull() ?: GlobalTestPortAllocation.startingPortDefaultValue