From 83d0095142d1dc2caeb0485cd814a3f1fbf79f02 Mon Sep 17 00:00:00 2001 From: joeldudleyr3 Date: Fri, 1 Sep 2017 16:45:00 +0100 Subject: [PATCH] Adds a builder for configuring nodes in the driver for Java interop. --- .../corda/client/jfx/NodeMonitorModelTest.kt | 8 +-- .../corda/docs/IntegrationTestingTutorial.kt | 6 +-- .../net/corda/docs/ClientRpcTutorial.kt | 4 +- .../kotlin/net/corda/node/BootTests.kt | 6 +-- .../corda/node/CordappScanningDriverTest.kt | 4 +- .../node/services/DistributedServiceTests.kt | 2 +- .../attachmentdemo/AttachmentDemoTest.kt | 6 +-- .../kotlin/net/corda/attachmentdemo/Main.kt | 6 +-- .../net/corda/bank/BankOfCordaHttpAPITest.kt | 4 +- .../corda/bank/BankOfCordaRPCClientTest.kt | 6 ++- .../net/corda/bank/BankOfCordaDriver.kt | 7 +-- .../kotlin/net/corda/irs/IRSDemoTest.kt | 6 +-- .../src/test/kotlin/net/corda/irs/Main.kt | 6 +-- .../net/corda/vega/SimmValuationTest.kt | 4 +- .../src/test/kotlin/net/corda/vega/Main.kt | 8 +-- .../test/kotlin/net/corda/traderdemo/Main.kt | 8 +-- .../net/corda/testing/driver/DriverTests.kt | 10 ++-- .../kotlin/net/corda/testing/TestConstants.kt | 2 +- .../kotlin/net/corda/testing/driver/Driver.kt | 53 +++++++++++++++---- .../net/corda/explorer/ExplorerSimulation.kt | 10 ++-- .../net/corda/verifier/VerifierTests.kt | 4 +- .../corda/webserver/WebserverDriverTests.kt | 2 +- 22 files changed, 105 insertions(+), 67 deletions(-) diff --git a/client/jfx/src/integration-test/kotlin/net/corda/client/jfx/NodeMonitorModelTest.kt b/client/jfx/src/integration-test/kotlin/net/corda/client/jfx/NodeMonitorModelTest.kt index 83453feddd..20e9c8dda5 100644 --- a/client/jfx/src/integration-test/kotlin/net/corda/client/jfx/NodeMonitorModelTest.kt +++ b/client/jfx/src/integration-test/kotlin/net/corda/client/jfx/NodeMonitorModelTest.kt @@ -58,13 +58,13 @@ class NodeMonitorModelTest : DriverBasedTest() { startFlowPermission(), startFlowPermission()) ) - val aliceNodeFuture = startNode(ALICE.name, rpcUsers = listOf(cashUser)) - val notaryNodeFuture = startNode(DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))) + val aliceNodeFuture = startNode(providedName = ALICE.name, rpcUsers = listOf(cashUser)) + val notaryNodeFuture = startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))) val aliceNodeHandle = aliceNodeFuture.getOrThrow() val notaryNodeHandle = notaryNodeFuture.getOrThrow() aliceNode = aliceNodeHandle.nodeInfo notaryNode = notaryNodeHandle.nodeInfo - newNode = { nodeName -> startNode(nodeName).getOrThrow().nodeInfo } + newNode = { nodeName -> startNode(providedName = nodeName).getOrThrow().nodeInfo } val monitor = NodeMonitorModel() stateMachineTransactionMapping = monitor.stateMachineTransactionMapping.bufferUntilSubscribed() stateMachineUpdates = monitor.stateMachineUpdates.bufferUntilSubscribed() @@ -76,7 +76,7 @@ class NodeMonitorModelTest : DriverBasedTest() { monitor.register(aliceNodeHandle.configuration.rpcAddress!!, cashUser.username, cashUser.password, initialiseSerialization = false) rpc = monitor.proxyObservable.value!! - val bobNodeHandle = startNode(BOB.name, rpcUsers = listOf(cashUser)).getOrThrow() + val bobNodeHandle = startNode(providedName = BOB.name, rpcUsers = listOf(cashUser)).getOrThrow() bobNode = bobNodeHandle.nodeInfo val monitorBob = NodeMonitorModel() stateMachineUpdatesBob = monitorBob.stateMachineUpdates.bufferUntilSubscribed() diff --git a/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt b/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt index e0ad68a957..e14a4e4bbb 100644 --- a/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt +++ b/docs/source/example-code/src/integration-test/kotlin/net/corda/docs/IntegrationTestingTutorial.kt @@ -32,9 +32,9 @@ class IntegrationTestingTutorial { startFlowPermission() )) val (alice, bob, notary) = listOf( - startNode(ALICE.name, rpcUsers = listOf(aliceUser)), - startNode(BOB.name, rpcUsers = listOf(bobUser)), - startNode(DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type))) + startNode(providedName = ALICE.name, rpcUsers = listOf(aliceUser)), + startNode(providedName = BOB.name, rpcUsers = listOf(bobUser)), + startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type))) ).transpose().getOrThrow() // END 1 diff --git a/docs/source/example-code/src/main/kotlin/net/corda/docs/ClientRpcTutorial.kt b/docs/source/example-code/src/main/kotlin/net/corda/docs/ClientRpcTutorial.kt index 6f6c080322..64992a788f 100644 --- a/docs/source/example-code/src/main/kotlin/net/corda/docs/ClientRpcTutorial.kt +++ b/docs/source/example-code/src/main/kotlin/net/corda/docs/ClientRpcTutorial.kt @@ -49,8 +49,8 @@ fun main(args: Array) { startFlowPermission())) driver(driverDirectory = baseDirectory) { - startNode(DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type))) - val node = startNode(ALICE.name, rpcUsers = listOf(user)).get() + startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type))) + val node = startNode(providedName = ALICE.name, rpcUsers = listOf(user)).get() // END 1 // START 2 diff --git a/node/src/integration-test/kotlin/net/corda/node/BootTests.kt b/node/src/integration-test/kotlin/net/corda/node/BootTests.kt index f1bb21c2d0..67cf30d78c 100644 --- a/node/src/integration-test/kotlin/net/corda/node/BootTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/BootTests.kt @@ -41,12 +41,12 @@ class BootTests { val logConfigFile = projectRootDir / "config" / "dev" / "log4j2.xml" assertThat(logConfigFile).isRegularFile() driver(isDebug = true, systemProperties = mapOf("log4j.configurationFile" to logConfigFile.toString())) { - val alice = startNode(ALICE.name).get() + val alice = startNode(providedName = ALICE.name).get() val logFolder = alice.configuration.baseDirectory / NodeStartup.LOGS_DIRECTORY_NAME val logFile = logFolder.toFile().listFiles { _, name -> name.endsWith(".log") }.single() // Start second Alice, should fail assertThatThrownBy { - startNode(ALICE.name).getOrThrow() + startNode(providedName = ALICE.name).getOrThrow() } // We count the number of nodes that wrote into the logfile by counting "Logs can be found in" val numberOfNodesThatLogged = Files.lines(logFile.toPath()).filter { NodeStartup.LOGS_CAN_BE_FOUND_IN_STRING in it }.count() @@ -58,7 +58,7 @@ class BootTests { fun `node quits on failure to register with network map`() { val tooManyAdvertisedServices = (1..100).map { ServiceInfo(ServiceType.regulator.getSubType("$it")) }.toSet() driver(networkMapStartStrategy = NetworkMapStartStrategy.Nominated(ALICE.name)) { - val future = startNode(ALICE.name, advertisedServices = tooManyAdvertisedServices) + val future = startNode(providedName = ALICE.name, advertisedServices = tooManyAdvertisedServices) assertFailsWith(ListenProcessDeathException::class) { future.getOrThrow() } } } diff --git a/node/src/integration-test/kotlin/net/corda/node/CordappScanningDriverTest.kt b/node/src/integration-test/kotlin/net/corda/node/CordappScanningDriverTest.kt index 2417f1d329..926dfb1baa 100644 --- a/node/src/integration-test/kotlin/net/corda/node/CordappScanningDriverTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/CordappScanningDriverTest.kt @@ -25,8 +25,8 @@ class CordappScanningDriverTest { // The driver will automatically pick up the annotated flows below driver { val (alice, bob) = listOf( - startNode(ALICE.name, rpcUsers = listOf(user)), - startNode(BOB.name)).transpose().getOrThrow() + startNode(providedName = ALICE.name, rpcUsers = listOf(user)), + startNode(providedName = BOB.name)).transpose().getOrThrow() val initiatedFlowClass = alice.rpcClientToNode() .start(user.username, user.password) .proxy diff --git a/node/src/integration-test/kotlin/net/corda/node/services/DistributedServiceTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/DistributedServiceTests.kt index 26442c108c..1e6daa63e6 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/DistributedServiceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/DistributedServiceTests.kt @@ -38,7 +38,7 @@ class DistributedServiceTests : DriverBasedTest() { startFlowPermission(), startFlowPermission()) ) - val aliceFuture = startNode(ALICE.name, rpcUsers = listOf(testUser)) + val aliceFuture = startNode(providedName = ALICE.name, rpcUsers = listOf(testUser)) val notariesFuture = startNotaryCluster( DUMMY_NOTARY.name, rpcUsers = listOf(testUser), 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 a8e2787c3a..34ce666450 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 @@ -20,9 +20,9 @@ class AttachmentDemoTest { driver(dsl = { val demoUser = listOf(User("demo", "demo", setOf(startFlowPermission()))) val (nodeA, nodeB) = listOf( - startNode(DUMMY_BANK_A.name, rpcUsers = demoUser), - startNode(DUMMY_BANK_B.name, rpcUsers = demoUser), - startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type))) + startNode(providedName = DUMMY_BANK_A.name, rpcUsers = demoUser), + startNode(providedName = DUMMY_BANK_B.name, rpcUsers = demoUser), + startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))) ).transpose().getOrThrow() val senderThread = CompletableFuture.supplyAsync { diff --git a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt index bd586c7542..9f9c269e13 100644 --- a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt +++ b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/Main.kt @@ -16,9 +16,9 @@ import net.corda.testing.driver.driver fun main(args: Array) { val demoUser = listOf(User("demo", "demo", setOf("StartFlow.net.corda.flows.FinalityFlow"))) driver(isDebug = true, driverDirectory = "build" / "attachment-demo-nodes") { - startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type))) - startNode(DUMMY_BANK_A.name, rpcUsers = demoUser) - startNode(DUMMY_BANK_B.name, rpcUsers = demoUser) + startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))) + startNode(providedName = DUMMY_BANK_A.name, rpcUsers = demoUser) + startNode(providedName = DUMMY_BANK_B.name, rpcUsers = demoUser) waitForAllNodesToFinish() } } diff --git a/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaHttpAPITest.kt b/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaHttpAPITest.kt index d6d24385bf..394ed0bf7f 100644 --- a/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaHttpAPITest.kt +++ b/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaHttpAPITest.kt @@ -16,8 +16,8 @@ class BankOfCordaHttpAPITest { fun `issuer flow via Http`() { driver(dsl = { val (nodeBankOfCorda) = listOf( - startNode(BOC.name, setOf(ServiceInfo(SimpleNotaryService.type))), - startNode(BIGCORP_LEGAL_NAME) + startNode(providedName = BOC.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))), + startNode(providedName = BIGCORP_LEGAL_NAME) ).transpose().getOrThrow() val anonymous = false val nodeBankOfCordaApiAddr = startWebserver(nodeBankOfCorda).getOrThrow().listenAddress diff --git a/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaRPCClientTest.kt b/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaRPCClientTest.kt index 4df2768692..31481cf3d4 100644 --- a/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaRPCClientTest.kt +++ b/samples/bank-of-corda-demo/src/integration-test/kotlin/net/corda/bank/BankOfCordaRPCClientTest.kt @@ -24,8 +24,10 @@ class BankOfCordaRPCClientTest { startFlowPermission())) val bigCorpCFO = User("bigCorpCFO", "password2", permissions = emptySet()) val (nodeBankOfCorda, nodeBigCorporation) = listOf( - startNode(BOC.name, setOf(ServiceInfo(SimpleNotaryService.type)), listOf(bocManager)), - startNode(BIGCORP_LEGAL_NAME, rpcUsers = listOf(bigCorpCFO)) + startNode(providedName = BOC.name, + advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type)), + rpcUsers = listOf(bocManager)), + startNode(providedName = BIGCORP_LEGAL_NAME, rpcUsers = listOf(bigCorpCFO)) ).transpose().getOrThrow() // Bank of Corda RPC Client diff --git a/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/BankOfCordaDriver.kt b/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/BankOfCordaDriver.kt index 0f61b602e0..d1f93ff00c 100644 --- a/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/BankOfCordaDriver.kt +++ b/samples/bank-of-corda-demo/src/main/kotlin/net/corda/bank/BankOfCordaDriver.kt @@ -71,12 +71,13 @@ private class BankOfCordaDriver { val bigCorpUser = User(BIGCORP_USERNAME, "test", permissions = setOf( startFlowPermission())) - startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type))) + startNode(providedName = DUMMY_NOTARY.name, + advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))) val bankOfCorda = startNode( - BOC.name, + providedName = BOC.name, rpcUsers = listOf(bankUser), advertisedServices = setOf(ServiceInfo(ServiceType.corda.getSubType("issuer.USD")))) - startNode(BIGCORP_LEGAL_NAME, rpcUsers = listOf(bigCorpUser)) + startNode(providedName = BIGCORP_LEGAL_NAME, rpcUsers = listOf(bigCorpUser)) startWebserver(bankOfCorda.get()) waitForAllNodesToFinish() }, isDebug = true) diff --git a/samples/irs-demo/src/integration-test/kotlin/net/corda/irs/IRSDemoTest.kt b/samples/irs-demo/src/integration-test/kotlin/net/corda/irs/IRSDemoTest.kt index 8c98accf78..fbea2e1a83 100644 --- a/samples/irs-demo/src/integration-test/kotlin/net/corda/irs/IRSDemoTest.kt +++ b/samples/irs-demo/src/integration-test/kotlin/net/corda/irs/IRSDemoTest.kt @@ -45,9 +45,9 @@ class IRSDemoTest : IntegrationTestCategory { fun `runs IRS demo`() { driver(useTestClock = true, isDebug = true) { val (controller, nodeA, nodeB) = listOf( - startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type), ServiceInfo(NodeInterestRates.Oracle.type))), - startNode(DUMMY_BANK_A.name, rpcUsers = listOf(rpcUser)), - startNode(DUMMY_BANK_B.name) + startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type), ServiceInfo(NodeInterestRates.Oracle.type))), + startNode(providedName = DUMMY_BANK_A.name, rpcUsers = listOf(rpcUser)), + startNode(providedName = DUMMY_BANK_B.name) ).transpose().getOrThrow() log.info("All nodes started") diff --git a/samples/irs-demo/src/test/kotlin/net/corda/irs/Main.kt b/samples/irs-demo/src/test/kotlin/net/corda/irs/Main.kt index f66fbe7a96..4f9117ed44 100644 --- a/samples/irs-demo/src/test/kotlin/net/corda/irs/Main.kt +++ b/samples/irs-demo/src/test/kotlin/net/corda/irs/Main.kt @@ -17,9 +17,9 @@ import net.corda.testing.driver.driver fun main(args: Array) { driver(dsl = { val (controller, nodeA, nodeB) = listOf( - startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type), ServiceInfo(NodeInterestRates.Oracle.type))), - startNode(DUMMY_BANK_A.name), - startNode(DUMMY_BANK_B.name) + startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type), ServiceInfo(NodeInterestRates.Oracle.type))), + startNode(providedName = DUMMY_BANK_A.name), + startNode(providedName = DUMMY_BANK_B.name) ).transpose().getOrThrow() startWebserver(controller) diff --git a/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt b/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt index b10b1ea541..ed78ffd6aa 100644 --- a/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt +++ b/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt @@ -33,8 +33,8 @@ class SimmValuationTest : IntegrationTestCategory { @Test fun `runs SIMM valuation demo`() { driver(isDebug = true) { - startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type))).getOrThrow() - val (nodeA, nodeB) = listOf(startNode(nodeALegalName), startNode(nodeBLegalName)).transpose().getOrThrow() + startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))).getOrThrow() + val (nodeA, nodeB) = listOf(startNode(providedName = nodeALegalName), startNode(providedName = nodeBLegalName)).transpose().getOrThrow() val (nodeAApi, nodeBApi) = listOf(startWebserver(nodeA), startWebserver(nodeB)).transpose() .getOrThrow() .map { HttpApi.fromHostAndPort(it.listenAddress, "api/simmvaluationdemo") } diff --git a/samples/simm-valuation-demo/src/test/kotlin/net/corda/vega/Main.kt b/samples/simm-valuation-demo/src/test/kotlin/net/corda/vega/Main.kt index 2ad314e6c6..81b13ae98c 100644 --- a/samples/simm-valuation-demo/src/test/kotlin/net/corda/vega/Main.kt +++ b/samples/simm-valuation-demo/src/test/kotlin/net/corda/vega/Main.kt @@ -17,11 +17,11 @@ import net.corda.testing.driver.driver */ fun main(args: Array) { driver(dsl = { - startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type))) + startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))) val (nodeA, nodeB, nodeC) = listOf( - startNode(DUMMY_BANK_A.name), - startNode(DUMMY_BANK_B.name), - startNode(DUMMY_BANK_C.name) + startNode(providedName = DUMMY_BANK_A.name), + startNode(providedName = DUMMY_BANK_B.name), + startNode(providedName = DUMMY_BANK_C.name) ).transpose().getOrThrow() startWebserver(nodeA) diff --git a/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/Main.kt b/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/Main.kt index 1661b70ad7..7ed7f689cd 100644 --- a/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/Main.kt +++ b/samples/trader-demo/src/test/kotlin/net/corda/traderdemo/Main.kt @@ -27,10 +27,10 @@ fun main(args: Array) { val user = User("user1", "test", permissions = setOf(startFlowPermission(), startFlowPermission(), startFlowPermission())) - startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type))) - startNode(DUMMY_BANK_A.name, rpcUsers = demoUser) - startNode(DUMMY_BANK_B.name, rpcUsers = demoUser) - startNode(BOC.name, rpcUsers = listOf(user)) + startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))) + startNode(providedName = DUMMY_BANK_A.name, rpcUsers = demoUser) + startNode(providedName = DUMMY_BANK_B.name, rpcUsers = demoUser) + startNode(providedName = BOC.name, rpcUsers = listOf(user)) waitForAllNodesToFinish() } } diff --git a/test-utils/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt b/test-utils/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt index 11f099dc5b..2ebcea15d2 100644 --- a/test-utils/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt +++ b/test-utils/src/integration-test/kotlin/net/corda/testing/driver/DriverTests.kt @@ -41,8 +41,8 @@ class DriverTests { @Test fun `simple node startup and shutdown`() { val handles = driver { - val notary = startNode(DUMMY_NOTARY.name, setOf(ServiceInfo(SimpleNotaryService.type))) - val regulator = startNode(DUMMY_REGULATOR.name, setOf(ServiceInfo(RegulatorService.type))) + val notary = startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type))) + val regulator = startNode(providedName = DUMMY_REGULATOR.name, advertisedServices = setOf(ServiceInfo(RegulatorService.type))) listOf(nodeMustBeUp(notary), nodeMustBeUp(regulator)) } handles.map { nodeMustBeDown(it) } @@ -51,7 +51,7 @@ class DriverTests { @Test fun `starting node with no services`() { val noService = driver { - val noService = startNode(DUMMY_BANK_A.name) + val noService = startNode(providedName = DUMMY_BANK_A.name) nodeMustBeUp(noService) } nodeMustBeDown(noService) @@ -60,7 +60,7 @@ class DriverTests { @Test fun `random free port allocation`() { val nodeHandle = driver(portAllocation = PortAllocation.RandomFree) { - val nodeInfo = startNode(DUMMY_BANK_A.name) + val nodeInfo = startNode(providedName = DUMMY_BANK_A.name) nodeMustBeUp(nodeInfo) } nodeMustBeDown(nodeHandle) @@ -72,7 +72,7 @@ class DriverTests { val logConfigFile = projectRootDir / "config" / "dev" / "log4j2.xml" assertThat(logConfigFile).isRegularFile() driver(isDebug = true, systemProperties = mapOf("log4j.configurationFile" to logConfigFile.toString())) { - val baseDirectory = startNode(DUMMY_BANK_A.name).getOrThrow().configuration.baseDirectory + val baseDirectory = startNode(providedName = DUMMY_BANK_A.name).getOrThrow().configuration.baseDirectory val logFile = (baseDirectory / NodeStartup.LOGS_DIRECTORY_NAME).list { it.sorted().findFirst().get() } val debugLinesPresent = logFile.readLines { lines -> lines.anyMatch { line -> line.startsWith("[DEBUG]") } } assertThat(debugLinesPresent).isTrue() diff --git a/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt b/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt index 77f65fa25d..3a8669e7cb 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/TestConstants.kt @@ -93,7 +93,7 @@ val DUMMY_PARTY: Party get() = Party(X500Name("CN=Dummy,O=Dummy,L=Madrid,C=ES"), */ class PredefinedTestNode internal constructor(party: Party, driver: DriverDSLExposedInterface, services: Set) { val rpcUsers = listOf(User("admin", "admin", setOf("ALL"))) // TODO: Randomize? - val nodeFuture by lazy { driver.startNode(party.name, rpcUsers = rpcUsers, advertisedServices = services) } + val nodeFuture by lazy { driver.startNode(providedName = party.name, rpcUsers = rpcUsers, advertisedServices = services) } val node by lazy { nodeFuture.get()!! } val rpc by lazy { node.rpcClientToNode() } diff --git a/test-utils/src/main/kotlin/net/corda/testing/driver/Driver.kt b/test-utils/src/main/kotlin/net/corda/testing/driver/Driver.kt index e2c2539f10..620f27a79a 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/driver/Driver.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/driver/Driver.kt @@ -78,6 +78,8 @@ interface DriverDSLExposedInterface : CordformContext { /** * Starts a [net.corda.node.internal.Node] in a separate process. * + * @param defaultParameters The default parameters for the node. Allows the node to be configured in builder style + * when called from Java code. * @param providedName Optional name of the node, which will be its legal name in [Party]. Defaults to something * random. Note that this must be unique as the driver uses it as a primary key! * @param advertisedServices The set of services to be advertised by the node. Defaults to empty set. @@ -87,12 +89,25 @@ interface DriverDSLExposedInterface : CordformContext { * in. If null the Driver-level value will be used. * @return The [NodeInfo] of the started up node retrieved from the network map service. */ - fun startNode(providedName: X500Name? = null, - advertisedServices: Set = emptySet(), - rpcUsers: List = emptyList(), - verifierType: VerifierType = VerifierType.InMemory, - customOverrides: Map = emptyMap(), - startInSameProcess: Boolean? = null): CordaFuture + fun startNode( + defaultParameters: NodeParameters = NodeParameters(), + providedName: X500Name? = defaultParameters.providedName, + advertisedServices: Set = defaultParameters.advertisedServices, + rpcUsers: List = defaultParameters.rpcUsers, + verifierType: VerifierType = defaultParameters.verifierType, + customOverrides: Map = defaultParameters.customOverrides, + startInSameProcess: Boolean? = defaultParameters.startInSameProcess): CordaFuture + + /** + * Helper function for starting a [node] with custom parameters from Java. + * + * @param defaultParameters The default parameters for the driver. + * @param dsl The dsl itself. + * @return The value returned in the [dsl] closure. + */ + fun startNode(parameters: NodeParameters): CordaFuture { + return startNode(defaultParameters = parameters) + } fun startNodes( nodes: List, @@ -214,11 +229,30 @@ sealed class PortAllocation { } } +/** + * Helper builder for configuring a [node] from Java. + */ +data class NodeParameters( + val providedName: X500Name? = null, + val advertisedServices: Set = emptySet(), + val rpcUsers: List = emptyList(), + val verifierType: VerifierType = VerifierType.InMemory, + val customOverrides: Map = emptyMap(), + val startInSameProcess: Boolean? = null +) { + fun setProvidedName(providedName: X500Name?) = copy(providedName = providedName) + fun setAdvertisedServices(advertisedServices: Set) = copy(advertisedServices = advertisedServices) + fun setRpcUsers(rpcUsers: List) = copy(rpcUsers = rpcUsers) + fun setVerifierType(verifierType: VerifierType) = copy(verifierType = verifierType) + fun setCustomerOverrides(customOverrides: Map) = copy(customOverrides = customOverrides) + fun setStartInSameProcess(startInSameProcess: Boolean?) = copy(startInSameProcess = startInSameProcess) +} + /** * [driver] allows one to start up nodes like this: * driver { - * val noService = startNode(DUMMY_BANK_A.name) - * val notary = startNode(DUMMY_NOTARY.name) + * val noService = startNode(providedName = DUMMY_BANK_A.name) + * val notary = startNode(providedName = DUMMY_NOTARY.name) * * (...) * } @@ -603,6 +637,7 @@ class DriverDSL( } override fun startNode( + defaultParameters: NodeParameters, providedName: X500Name?, advertisedServices: Set, rpcUsers: List, @@ -687,7 +722,7 @@ class DriverDSL( val nodeAddress = portAllocation.nextHostAndPort() val configOverride = mapOf("notaryNodeAddress" to nodeAddress.toString(), "notaryClusterAddresses" to listOf(notaryClusterAddress.toString()), "database.serverNameTablePrefix" to it.toString().replace(Regex("[^0-9A-Za-z]+"), "")) - startNode(it, advertisedServices, rpcUsers, verifierType, configOverride) + startNode(providedName = it, advertisedServices = advertisedServices, rpcUsers = rpcUsers, verifierType = verifierType, customOverrides = configOverride) } return firstNotaryFuture.flatMap { firstNotary -> 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 3eda29511e..9983ede708 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/ExplorerSimulation.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/ExplorerSimulation.kt @@ -71,20 +71,20 @@ class ExplorerSimulation(val options: OptionSet) { val portAllocation = PortAllocation.Incremental(20000) driver(portAllocation = portAllocation) { // TODO : Supported flow should be exposed somehow from the node instead of set of ServiceInfo. - val notary = startNode(DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type)), + val notary = startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(SimpleNotaryService.type)), customOverrides = mapOf("nearestCity" to "Zurich")) - val alice = startNode(ALICE.name, rpcUsers = arrayListOf(user), + val alice = startNode(providedName = ALICE.name, rpcUsers = arrayListOf(user), advertisedServices = setOf(ServiceInfo(ServiceType.corda.getSubType("cash"))), customOverrides = mapOf("nearestCity" to "Milan")) - val bob = startNode(BOB.name, rpcUsers = arrayListOf(user), + val bob = startNode(providedName = BOB.name, rpcUsers = arrayListOf(user), advertisedServices = setOf(ServiceInfo(ServiceType.corda.getSubType("cash"))), customOverrides = mapOf("nearestCity" to "Madrid")) val ukBankName = X500Name("CN=UK Bank Plc,O=UK Bank Plc,L=London,C=GB") val usaBankName = X500Name("CN=USA Bank Corp,O=USA Bank Corp,L=New York,C=USA") - val issuerGBP = startNode(ukBankName, rpcUsers = arrayListOf(manager), + val issuerGBP = startNode(providedName = ukBankName, rpcUsers = arrayListOf(manager), advertisedServices = setOf(ServiceInfo(ServiceType.corda.getSubType("issuer.GBP"))), customOverrides = mapOf("nearestCity" to "London")) - val issuerUSD = startNode(usaBankName, rpcUsers = arrayListOf(manager), + val issuerUSD = startNode(providedName = usaBankName, rpcUsers = arrayListOf(manager), advertisedServices = setOf(ServiceInfo(ServiceType.corda.getSubType("issuer.USD"))), customOverrides = mapOf("nearestCity" to "New York")) diff --git a/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt b/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt index 3698019574..6fa26cf776 100644 --- a/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt +++ b/verifier/src/integration-test/kotlin/net/corda/verifier/VerifierTests.kt @@ -113,8 +113,8 @@ class VerifierTests { @Test fun `single verifier works with a node`() { verifierDriver(networkMapStartStrategy = NetworkMapStartStrategy.Dedicated(startAutomatically = true)) { - val aliceFuture = startNode(ALICE.name) - val notaryFuture = startNode(DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type)), verifierType = VerifierType.OutOfProcess) + val aliceFuture = startNode(providedName = ALICE.name) + val notaryFuture = startNode(providedName = DUMMY_NOTARY.name, advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type)), verifierType = VerifierType.OutOfProcess) val alice = aliceFuture.get() val notary = notaryFuture.get() startVerifier(notary) diff --git a/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt b/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt index bac83b0eab..cd4f35577d 100644 --- a/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt +++ b/webserver/src/integration-test/kotlin/net/corda/webserver/WebserverDriverTests.kt @@ -27,7 +27,7 @@ class DriverTests { @Test fun `starting a node and independent web server works`() { val addr = driver { - val node = startNode(DUMMY_BANK_A.name).getOrThrow() + val node = startNode(providedName = DUMMY_BANK_A.name).getOrThrow() val webserverHandle = startWebserver(node).getOrThrow() webserverMustBeUp(webserverHandle) webserverHandle.listenAddress