diff --git a/.ci/api-current.txt b/.ci/api-current.txt index e62c8cf108..37a43f06ce 100644 --- a/.ci/api-current.txt +++ b/.ci/api-current.txt @@ -6081,7 +6081,7 @@ public abstract class net.corda.testing.driver.PortAllocation extends java.lang. public abstract int nextPort() ## @DoNotImplement -public static final class net.corda.testing.driver.PortAllocation$Incremental extends net.corda.testing.driver.PortAllocation +public static class net.corda.testing.driver.PortAllocation$Incremental extends net.corda.testing.driver.PortAllocation public (int) @NotNull public final java.util.concurrent.atomic.AtomicInteger getPortCounter() diff --git a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/RPCStabilityTests.kt b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/RPCStabilityTests.kt index b05e33c729..14b9df8ebd 100644 --- a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/RPCStabilityTests.kt +++ b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/RPCStabilityTests.kt @@ -13,7 +13,7 @@ import net.corda.node.services.messaging.RPCServerConfiguration import net.corda.nodeapi.RPCApi import net.corda.nodeapi.eventually import net.corda.testing.core.SerializationEnvironmentRule -import net.corda.testing.driver.PortAllocation +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.testThreadFactory import net.corda.testing.node.internal.* import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration @@ -39,7 +39,7 @@ class RPCStabilityTests { val testSerialization = SerializationEnvironmentRule(true) private val pool = Executors.newFixedThreadPool(10, testThreadFactory()) - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) @After fun shutdown() { diff --git a/experimental/notary-raft/src/test/kotlin/net/corda/notary/raft/RaftTransactionCommitLogTests.kt b/experimental/notary-raft/src/test/kotlin/net/corda/notary/raft/RaftTransactionCommitLogTests.kt index f8848a4746..ee8edaea98 100644 --- a/experimental/notary-raft/src/test/kotlin/net/corda/notary/raft/RaftTransactionCommitLogTests.kt +++ b/experimental/notary-raft/src/test/kotlin/net/corda/notary/raft/RaftTransactionCommitLogTests.kt @@ -15,13 +15,13 @@ import net.corda.core.internal.concurrent.transpose import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.getOrThrow import net.corda.node.services.schema.NodeSchemaService -import net.corda.testing.internal.TestingNamedCacheFactory import net.corda.nodeapi.internal.persistence.CordaPersistence import net.corda.nodeapi.internal.persistence.DatabaseConfig import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.SerializationEnvironmentRule -import net.corda.testing.driver.PortAllocation +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.LogHelper +import net.corda.testing.internal.TestingNamedCacheFactory import net.corda.testing.internal.configureDatabase import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties import org.hamcrest.Matchers.instanceOf @@ -44,7 +44,7 @@ class RaftTransactionCommitLogTests { val testSerialization = SerializationEnvironmentRule(true) private val databases: MutableList = mutableListOf() - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) private lateinit var cluster: List diff --git a/node/src/integration-test/kotlin/net/corda/node/AddressBindingFailureTests.kt b/node/src/integration-test/kotlin/net/corda/node/AddressBindingFailureTests.kt index 802893b7a6..bc1da1cfad 100644 --- a/node/src/integration-test/kotlin/net/corda/node/AddressBindingFailureTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/AddressBindingFailureTests.kt @@ -1,12 +1,12 @@ package net.corda.node import net.corda.core.identity.CordaX500Name +import net.corda.core.internal.errors.AddressBindingException 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.driver.internal.incrementalPortAllocation import net.corda.testing.node.NotarySpec import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy @@ -17,7 +17,7 @@ import java.net.ServerSocket class AddressBindingFailureTests { companion object { - private val portAllocation = PortAllocation.Incremental(20_000) + private val portAllocation = incrementalPortAllocation(20_000) } @Test diff --git a/node/src/integration-test/kotlin/net/corda/node/amqp/AMQPBridgeTest.kt b/node/src/integration-test/kotlin/net/corda/node/amqp/AMQPBridgeTest.kt index 7cc77b2d96..02350108f0 100644 --- a/node/src/integration-test/kotlin/net/corda/node/amqp/AMQPBridgeTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/amqp/AMQPBridgeTest.kt @@ -18,9 +18,9 @@ import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.MAX_MESSAGE_SIZE import net.corda.testing.core.TestIdentity -import net.corda.testing.driver.PortAllocation -import net.corda.testing.internal.stubs.CertificateStoreStubs +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.rigorousMock +import net.corda.testing.internal.stubs.CertificateStoreStubs import org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID import org.apache.activemq.artemis.api.core.RoutingType import org.apache.activemq.artemis.api.core.SimpleString @@ -40,7 +40,7 @@ class AMQPBridgeTest { private val BOB = TestIdentity(BOB_NAME) - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) private val artemisAddress = portAllocation.nextHostAndPort() private val amqpAddress = portAllocation.nextHostAndPort() diff --git a/node/src/integration-test/kotlin/net/corda/node/amqp/CertificateRevocationListNodeTests.kt b/node/src/integration-test/kotlin/net/corda/node/amqp/CertificateRevocationListNodeTests.kt index 4b18fa28be..f7a1136f93 100644 --- a/node/src/integration-test/kotlin/net/corda/node/amqp/CertificateRevocationListNodeTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/amqp/CertificateRevocationListNodeTests.kt @@ -24,7 +24,7 @@ import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.CHARLIE_NAME import net.corda.testing.core.MAX_MESSAGE_SIZE -import net.corda.testing.driver.PortAllocation +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.DEV_INTERMEDIATE_CA import net.corda.testing.internal.DEV_ROOT_CA import net.corda.testing.internal.rigorousMock @@ -72,7 +72,7 @@ class CertificateRevocationListNodeTests { private val ROOT_CA = DEV_ROOT_CA private lateinit var INTERMEDIATE_CA: CertificateAndKeyPair - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) private val serverPort = portAllocation.nextPort() private lateinit var server: CrlServer diff --git a/node/src/integration-test/kotlin/net/corda/node/amqp/ProtonWrapperTests.kt b/node/src/integration-test/kotlin/net/corda/node/amqp/ProtonWrapperTests.kt index bc717e7109..94594f0339 100644 --- a/node/src/integration-test/kotlin/net/corda/node/amqp/ProtonWrapperTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/amqp/ProtonWrapperTests.kt @@ -28,7 +28,7 @@ import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.CHARLIE_NAME import net.corda.testing.core.MAX_MESSAGE_SIZE -import net.corda.testing.driver.PortAllocation +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.createDevIntermediateCaCertPath import net.corda.testing.internal.rigorousMock import net.corda.testing.internal.stubs.CertificateStoreStubs @@ -49,7 +49,7 @@ class ProtonWrapperTests { @JvmField val temporaryFolder = TemporaryFolder() - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) private val serverPort = portAllocation.nextPort() private val serverPort2 = portAllocation.nextPort() private val artemisPort = portAllocation.nextPort() diff --git a/node/src/integration-test/kotlin/net/corda/node/modes/draining/FlowsDrainingModeContentionTest.kt b/node/src/integration-test/kotlin/net/corda/node/modes/draining/FlowsDrainingModeContentionTest.kt index 47cb6339c7..a9ca103741 100644 --- a/node/src/integration-test/kotlin/net/corda/node/modes/draining/FlowsDrainingModeContentionTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/modes/draining/FlowsDrainingModeContentionTest.kt @@ -22,8 +22,8 @@ import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.singleIdentity import net.corda.testing.driver.DriverParameters -import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.driver +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.node.User import org.assertj.core.api.Assertions.assertThat import org.junit.After @@ -33,7 +33,7 @@ import java.util.concurrent.Executors import java.util.concurrent.ScheduledExecutorService class FlowsDrainingModeContentionTest { - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) private val user = User("mark", "dadada", setOf(all())) private val users = listOf(user) diff --git a/node/src/integration-test/kotlin/net/corda/node/modes/draining/P2PFlowsDrainingModeTest.kt b/node/src/integration-test/kotlin/net/corda/node/modes/draining/P2PFlowsDrainingModeTest.kt index 40b172e162..3fed0afbe4 100644 --- a/node/src/integration-test/kotlin/net/corda/node/modes/draining/P2PFlowsDrainingModeTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/modes/draining/P2PFlowsDrainingModeTest.kt @@ -1,11 +1,7 @@ package net.corda.node.modes.draining import co.paralleluniverse.fibers.Suspendable -import net.corda.core.flows.FlowLogic -import net.corda.core.flows.FlowSession -import net.corda.core.flows.InitiatedBy -import net.corda.core.flows.InitiatingFlow -import net.corda.core.flows.StartableByRPC +import net.corda.core.flows.* import net.corda.core.identity.Party import net.corda.core.internal.concurrent.map import net.corda.core.messaging.startFlow @@ -18,8 +14,8 @@ import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.singleIdentity import net.corda.testing.driver.DriverParameters -import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.driver +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.chooseIdentity import net.corda.testing.node.User import net.corda.testing.node.internal.waitForShutdown @@ -38,7 +34,7 @@ class P2PFlowsDrainingModeTest { private val logger = contextLogger() } - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) private val user = User("mark", "dadada", setOf(Permissions.all())) private val users = listOf(user) diff --git a/node/src/integration-test/kotlin/net/corda/node/modes/draining/RpcFlowsDrainingModeTest.kt b/node/src/integration-test/kotlin/net/corda/node/modes/draining/RpcFlowsDrainingModeTest.kt index 07c9aca738..923428adbe 100644 --- a/node/src/integration-test/kotlin/net/corda/node/modes/draining/RpcFlowsDrainingModeTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/modes/draining/RpcFlowsDrainingModeTest.kt @@ -8,8 +8,8 @@ import net.corda.core.utilities.getOrThrow import net.corda.node.services.Permissions import net.corda.nodeapi.exceptions.RejectedCommandException import net.corda.testing.driver.DriverParameters -import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.driver +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.node.User import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable @@ -17,7 +17,7 @@ import org.junit.Test class RpcFlowsDrainingModeTest { - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) private val user = User("mark", "dadada", setOf(Permissions.all())) private val users = listOf(user) diff --git a/node/src/integration-test/kotlin/net/corda/node/persistence/H2SecurityTests.kt b/node/src/integration-test/kotlin/net/corda/node/persistence/H2SecurityTests.kt index 57dad79ea5..5552a36a37 100644 --- a/node/src/integration-test/kotlin/net/corda/node/persistence/H2SecurityTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/persistence/H2SecurityTests.kt @@ -9,8 +9,8 @@ import net.corda.core.utilities.getOrThrow import net.corda.node.services.Permissions import net.corda.nodeapi.internal.persistence.CouldNotCreateDataSourceException import net.corda.testing.driver.DriverParameters -import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.driver +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.node.User import org.junit.Test import java.net.InetAddress @@ -21,7 +21,7 @@ import kotlin.test.assertTrue class H2SecurityTests { companion object { - private val port = PortAllocation.Incremental(21_000) + private val port = incrementalPortAllocation(21_000) private fun getFreePort() = port.nextPort() private const val h2AddressKey = "h2Settings.address" private const val dbPasswordKey = "dataSourceProperties.dataSource.password" diff --git a/node/src/integration-test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTest.kt index 75fee6d040..34c588b763 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTest.kt @@ -18,7 +18,7 @@ import net.corda.nodeapi.internal.persistence.DatabaseConfig import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.MAX_MESSAGE_SIZE import net.corda.testing.core.SerializationEnvironmentRule -import net.corda.testing.driver.PortAllocation +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.LogHelper import net.corda.testing.internal.TestingNamedCacheFactory import net.corda.testing.internal.configureDatabase @@ -58,7 +58,7 @@ class ArtemisMessagingTest { val temporaryFolder = TemporaryFolder() // THe - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) private val serverPort = portAllocation.nextPort() private val identity = generateKeyPair() diff --git a/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt index a466ab5310..4547efe023 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/network/NetworkMapTest.kt @@ -16,8 +16,8 @@ import net.corda.nodeapi.internal.network.SignedNetworkParameters import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.core.* import net.corda.testing.driver.NodeHandle -import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.internal.NodeHandleInternal +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.node.internal.* import net.corda.testing.node.internal.network.NetworkMapServer import org.assertj.core.api.Assertions.assertThat @@ -38,7 +38,7 @@ class NetworkMapTest(var initFunc: (URL, NetworkMapServer) -> CompatibilityZoneP val testSerialization = SerializationEnvironmentRule(true) private val cacheTimeout = 1.seconds - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) private lateinit var networkMapServer: NetworkMapServer private lateinit var compatibilityZone: CompatibilityZoneParams diff --git a/node/src/integration-test/kotlin/net/corda/node/services/rpc/ArtemisRpcTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/rpc/ArtemisRpcTests.kt index 75a2838286..04fad79cc1 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/rpc/ArtemisRpcTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/rpc/ArtemisRpcTests.kt @@ -23,6 +23,7 @@ import net.corda.nodeapi.internal.config.MutualSslConfiguration import net.corda.nodeapi.internal.config.User import net.corda.testing.core.SerializationEnvironmentRule import net.corda.testing.driver.PortAllocation +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.TestingNamedCacheFactory import net.corda.testing.internal.fromUserList import net.corda.testing.internal.p2pSslOptions @@ -37,7 +38,7 @@ import java.nio.file.Path import javax.security.auth.x500.X500Principal class ArtemisRpcTests { - private val ports: PortAllocation = PortAllocation.Incremental(10000) + private val ports: PortAllocation = incrementalPortAllocation(10000) private val user = User("mark", "dadada", setOf(all())) private val users = listOf(user) diff --git a/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt b/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt index 2878ef6d14..3b4c2c617d 100644 --- a/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt @@ -17,7 +17,7 @@ import net.corda.nodeapi.internal.crypto.X509Utilities.CORDA_ROOT_CA import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.core.SerializationEnvironmentRule import net.corda.testing.core.singleIdentity -import net.corda.testing.driver.PortAllocation +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.DEV_ROOT_CA import net.corda.testing.node.NotarySpec import net.corda.testing.node.internal.DriverDSLImpl.Companion.cordappsInCurrentAndAdditionalPackages @@ -57,7 +57,7 @@ class NodeRegistrationTest { @JvmField val testSerialization = SerializationEnvironmentRule(true) - private val portAllocation = PortAllocation.Incremental(13000) + private val portAllocation = incrementalPortAllocation(13000) private val registrationHandler = RegistrationHandler(DEV_ROOT_CA) private lateinit var server: NetworkMapServer private lateinit var serverHostAndPort: NetworkHostAndPort diff --git a/node/src/integration-test/kotlin/net/corda/services/messaging/AdditionP2PAddressModeTest.kt b/node/src/integration-test/kotlin/net/corda/services/messaging/AdditionP2PAddressModeTest.kt index e4087fe3f7..d5903b0ce5 100644 --- a/node/src/integration-test/kotlin/net/corda/services/messaging/AdditionP2PAddressModeTest.kt +++ b/node/src/integration-test/kotlin/net/corda/services/messaging/AdditionP2PAddressModeTest.kt @@ -17,14 +17,14 @@ import net.corda.testing.core.DUMMY_BANK_B_NAME import net.corda.testing.core.expect import net.corda.testing.core.expectEvents import net.corda.testing.driver.DriverParameters -import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.driver +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.node.User import org.junit.Test import java.util.* class AdditionP2PAddressModeTest { - private val portAllocation = PortAllocation.Incremental(27182) + private val portAllocation = incrementalPortAllocation(27182) @Test fun `runs nodes with one configured to use additionalP2PAddresses`() { val testUser = User("test", "test", setOf(all())) diff --git a/samples/attachment-demo/src/integration-test/kotlin/net/corda/attachmentdemo/AttachmentDemoTest.kt b/samples/attachment-demo/src/integration-test/kotlin/net/corda/attachmentdemo/AttachmentDemoTest.kt index 5e2d1aa04b..053957b81d 100644 --- a/samples/attachment-demo/src/integration-test/kotlin/net/corda/attachmentdemo/AttachmentDemoTest.kt +++ b/samples/attachment-demo/src/integration-test/kotlin/net/corda/attachmentdemo/AttachmentDemoTest.kt @@ -6,8 +6,8 @@ import net.corda.node.services.Permissions.Companion.all import net.corda.testing.core.DUMMY_BANK_A_NAME import net.corda.testing.core.DUMMY_BANK_B_NAME import net.corda.testing.driver.DriverParameters -import net.corda.testing.driver.PortAllocation import net.corda.testing.driver.driver +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.node.User import org.junit.Test import java.util.concurrent.CompletableFuture.supplyAsync @@ -17,7 +17,7 @@ class AttachmentDemoTest { @Test fun `attachment demo using a 10MB zip file`() { val numOfExpectedBytes = 10_000_000 - driver(DriverParameters(portAllocation = PortAllocation.Incremental(20000), startNodesInProcess = true)) { + driver(DriverParameters(portAllocation = incrementalPortAllocation(20000), startNodesInProcess = true)) { val demoUser = listOf(User("demo", "demo", setOf(all()))) val (nodeA, nodeB) = listOf( startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = demoUser, maximumHeapSize = "1g"), 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 2ff7b69742..50baa62ea3 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 @@ -16,7 +16,7 @@ import net.corda.core.utilities.getOrThrow import net.corda.node.internal.Node import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.core.DUMMY_NOTARY_NAME -import net.corda.testing.driver.PortAllocation.Incremental +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.driver.internal.internalServices import net.corda.testing.node.NotarySpec import net.corda.testing.node.TestCordapp @@ -114,7 +114,7 @@ abstract class PortAllocation { /** * An implementation of [PortAllocation] which allocates ports sequentially */ - class Incremental(startingPort: Int) : PortAllocation() { + open class Incremental(startingPort: Int) : PortAllocation() { /** The backing [AtomicInteger] used to keep track of the currently allocated port */ val portCounter = AtomicInteger(startingPort) @@ -307,7 +307,7 @@ data class NodeParameters( */ data class JmxPolicy(val startJmxHttpServer: Boolean = false, val jmxHttpServerPortAllocation: PortAllocation? = - if (startJmxHttpServer) PortAllocation.Incremental(7005) else null) + if (startJmxHttpServer) incrementalPortAllocation(7005) else null) /** * [driver] allows one to start up nodes like this: @@ -388,8 +388,8 @@ fun driver(defaultParameters: DriverParameters = DriverParameters(), dsl: Dr data class DriverParameters( val isDebug: Boolean = false, val driverDirectory: Path = Paths.get("build", getTimestampAsDirectoryName()), - val portAllocation: PortAllocation = PortAllocation.Incremental(10000), - val debugPortAllocation: PortAllocation = PortAllocation.Incremental(5005), + val portAllocation: PortAllocation = incrementalPortAllocation(10000), + val debugPortAllocation: PortAllocation = incrementalPortAllocation(5005), val systemProperties: Map = emptyMap(), val useTestClock: Boolean = false, val startNodesInProcess: Boolean = false, @@ -406,8 +406,8 @@ data class DriverParameters( constructor( isDebug: Boolean = false, driverDirectory: Path = Paths.get("build", getTimestampAsDirectoryName()), - portAllocation: PortAllocation = PortAllocation.Incremental(10000), - debugPortAllocation: PortAllocation = PortAllocation.Incremental(5005), + portAllocation: PortAllocation = incrementalPortAllocation(10000), + debugPortAllocation: PortAllocation = incrementalPortAllocation(5005), systemProperties: Map = emptyMap(), useTestClock: Boolean = false, startNodesInProcess: Boolean = false, 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 new file mode 100644 index 0000000000..cfd3fc9004 --- /dev/null +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/internal/GlobalTestPortAllocation.kt @@ -0,0 +1,20 @@ +package net.corda.testing.driver.internal + +import net.corda.testing.driver.PortAllocation + +fun incrementalPortAllocation(startingPortIfNoEnv: Int): PortAllocation { + + return when { + System.getenv(GlobalTestPortAllocation.enablingEnvVar)?.toBoolean() == true -> GlobalTestPortAllocation + else -> PortAllocation.Incremental(startingPortIfNoEnv) + } +} + +private object GlobalTestPortAllocation : PortAllocation.Incremental(startingPort = startingPort) { + + const val enablingEnvVar = "CORDA_TEST_GLOBAL_PORT_ALLOCATION_ENABLED" + const val startingPortEnvVariable = "CORDA_TEST_GLOBAL_PORT_ALLOCATION_STARTING_PORT" + const val startingPortDefaultValue = 5000 +} + +private val startingPort: Int = System.getenv(GlobalTestPortAllocation.startingPortEnvVariable)?.toIntOrNull() ?: GlobalTestPortAllocation.startingPortDefaultValue \ No newline at end of file diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt index 1b53ddc6b5..73041eb8f7 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/NodeBasedTest.kt @@ -19,7 +19,7 @@ import net.corda.nodeapi.internal.config.toConfig import net.corda.nodeapi.internal.network.NetworkParametersCopier import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.core.SerializationEnvironmentRule -import net.corda.testing.driver.PortAllocation +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.testThreadFactory import net.corda.testing.node.User import org.apache.commons.lang.SystemUtils @@ -52,7 +52,7 @@ abstract class NodeBasedTest(private val cordappPackages: List = emptyLi private lateinit var defaultNetworkParameters: NetworkParametersCopier private val nodes = mutableListOf() private val nodeInfos = mutableListOf() - private val portAllocation = PortAllocation.Incremental(10000) + private val portAllocation = incrementalPortAllocation(10000) init { System.setProperty("consoleLogLevel", Level.DEBUG.name().toLowerCase()) diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt index ad019e9222..26a87592cc 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/RPCDriver.kt @@ -28,6 +28,7 @@ import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.core.MAX_MESSAGE_SIZE import net.corda.testing.driver.JmxPolicy import net.corda.testing.driver.PortAllocation +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.internal.TestingNamedCacheFactory import net.corda.testing.internal.fromUserList import net.corda.testing.node.NotarySpec @@ -102,8 +103,8 @@ val rpcTestUser = User("user1", "test", permissions = emptySet()) val fakeNodeLegalName = CordaX500Name(organisation = "Not:a:real:name", locality = "Nowhere", country = "GB") // Use a global pool so that we can run RPC tests in parallel -private val globalPortAllocation = PortAllocation.Incremental(10000) -private val globalDebugPortAllocation = PortAllocation.Incremental(5005) +private val globalPortAllocation = incrementalPortAllocation(10000) +private val globalDebugPortAllocation = incrementalPortAllocation(5005) fun rpcDriver( isDebug: Boolean = false, diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/ExplorerSimulation.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/ExplorerSimulation.kt index fd4c43fcf9..7f772e6f4b 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/ExplorerSimulation.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/ExplorerSimulation.kt @@ -29,6 +29,7 @@ import net.corda.node.services.Permissions.Companion.startFlow import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.driver.* +import net.corda.testing.driver.internal.incrementalPortAllocation import net.corda.testing.node.User import net.corda.testing.node.internal.FINANCE_CORDAPP import java.time.Instant @@ -67,7 +68,7 @@ class ExplorerSimulation(private val options: OptionSet) { } private fun startDemoNodes() { - val portAllocation = PortAllocation.Incremental(20000) + val portAllocation = incrementalPortAllocation(20000) driver(DriverParameters( portAllocation = portAllocation, cordappsForAllNodes = listOf(FINANCE_CORDAPP), diff --git a/tools/loadtest/src/main/kotlin/net/corda/loadtest/LoadTest.kt b/tools/loadtest/src/main/kotlin/net/corda/loadtest/LoadTest.kt index 152eda8997..41e0c93a37 100644 --- a/tools/loadtest/src/main/kotlin/net/corda/loadtest/LoadTest.kt +++ b/tools/loadtest/src/main/kotlin/net/corda/loadtest/LoadTest.kt @@ -4,7 +4,7 @@ import com.google.common.util.concurrent.RateLimiter import net.corda.client.mock.Generator import net.corda.core.utilities.loggerFor import net.corda.core.utilities.toBase58String -import net.corda.testing.driver.PortAllocation +import net.corda.testing.driver.internal.incrementalPortAllocation import java.util.* import java.util.concurrent.Callable import java.util.concurrent.ConcurrentHashMap @@ -170,7 +170,7 @@ fun runLoadTests(configuration: LoadTestConfiguration, tests: List + connectToNodes(remoteNodes, incrementalPortAllocation(configuration.localTunnelStartingPort)) { connections -> log.info("Connected to all nodes!") val hostNodeMap = ConcurrentHashMap() connections.parallelStream().forEach { connection ->