From 10e686bc82e2542c0965d1bb90c18c4bb19004fd Mon Sep 17 00:00:00 2001 From: Andrzej Cichocki Date: Thu, 30 Nov 2017 16:28:58 +0000 Subject: [PATCH] Inline DriverConstants. (#2156) --- .../statemachine/LargeTransactionsTest.kt | 23 ++++---- .../net/corda/testing/DriverConstants.kt | 52 ------------------- 2 files changed, 12 insertions(+), 63 deletions(-) delete mode 100644 testing/node-driver/src/main/kotlin/net/corda/testing/DriverConstants.kt diff --git a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt index 9f0212d2cb..980a29bb2e 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt @@ -4,15 +4,15 @@ import co.paralleluniverse.fibers.Suspendable import net.corda.core.crypto.SecureHash import net.corda.core.flows.* import net.corda.core.internal.InputStreamAndHash +import net.corda.core.internal.concurrent.transpose import net.corda.core.messaging.startFlow import net.corda.core.transactions.TransactionBuilder -import net.corda.testing.BOB -import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.aliceAndBob +import net.corda.core.utilities.getOrThrow +import net.corda.nodeapi.User +import net.corda.testing.* import net.corda.testing.contracts.DummyContract import net.corda.testing.contracts.DummyState import net.corda.testing.driver.driver -import net.corda.testing.dummyCommand import org.junit.Test import kotlin.test.assertEquals @@ -65,15 +65,16 @@ class LargeTransactionsTest { val bigFile3 = InputStreamAndHash.createInMemoryTestZip(1024 * 1024 * 3, 2) val bigFile4 = InputStreamAndHash.createInMemoryTestZip(1024 * 1024 * 3, 3) driver(startNodesInProcess = true, extraCordappPackagesToScan = listOf("net.corda.testing.contracts")) { - val (alice, _) = aliceAndBob() - alice.useRPC { - val hash1 = it.uploadAttachment(bigFile1.inputStream) - val hash2 = it.uploadAttachment(bigFile2.inputStream) - val hash3 = it.uploadAttachment(bigFile3.inputStream) - val hash4 = it.uploadAttachment(bigFile4.inputStream) + val rpcUser = User("admin", "admin", setOf("ALL")) + val (alice, _) = listOf(ALICE_NAME, BOB_NAME).map { startNode(providedName = it, rpcUsers = listOf(rpcUser)) }.transpose().getOrThrow() + alice.rpcClientToNode().use(rpcUser.username, rpcUser.password) { + val hash1 = it.proxy.uploadAttachment(bigFile1.inputStream) + val hash2 = it.proxy.uploadAttachment(bigFile2.inputStream) + val hash3 = it.proxy.uploadAttachment(bigFile3.inputStream) + val hash4 = it.proxy.uploadAttachment(bigFile4.inputStream) assertEquals(hash1, bigFile1.sha256) // Should not throw any exceptions. - it.startFlow(::SendLargeTransactionFlow, hash1, hash2, hash3, hash4).returnValue.get() + it.proxy.startFlow(::SendLargeTransactionFlow, hash1, hash2, hash3, hash4).returnValue.getOrThrow() } } } diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/DriverConstants.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/DriverConstants.kt deleted file mode 100644 index 6c050f24b8..0000000000 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/DriverConstants.kt +++ /dev/null @@ -1,52 +0,0 @@ -@file:JvmName("DriverConstants") - -package net.corda.testing - -import net.corda.core.identity.Party -import net.corda.core.internal.concurrent.transpose -import net.corda.core.messaging.CordaRPCOps -import net.corda.nodeapi.User -import net.corda.testing.driver.DriverDSLExposedInterface - -// -// Extensions to the Driver DSL to auto-manufacture nodes by name. -// - -/** - * A simple wrapper for objects provided by the integration test driver DSL. The fields are lazy so - * node construction won't start until you access the members. You can get one of these from the - * [alice], [bob] and [aliceAndBob] functions. - */ -class PredefinedTestNode internal constructor(party: Party, driver: DriverDSLExposedInterface) { - val rpcUsers = listOf(User("admin", "admin", setOf("ALL"))) // TODO: Randomize? - val nodeFuture by lazy { driver.startNode(providedName = party.name, rpcUsers = rpcUsers) } - val node by lazy { nodeFuture.get()!! } - val rpc by lazy { node.rpcClientToNode() } - - fun useRPC(block: (CordaRPCOps) -> R) = rpc.use(rpcUsers[0].username, rpcUsers[0].password) { block(it.proxy) } -} - -// TODO: Probably we should inject the above keys through the driver to make the nodes use it, rather than have the warnings below. - -/** - * Returns a plain, entirely stock node pre-configured with the [ALICE] identity. Note that a random key will be generated - * for it: you won't have [ALICE_KEY]. - */ -fun DriverDSLExposedInterface.alice(): PredefinedTestNode = PredefinedTestNode(ALICE, this) - -/** - * Returns a plain, entirely stock node pre-configured with the [BOB] identity. Note that a random key will be generated - * for it: you won't have [BOB_KEY]. - */ -fun DriverDSLExposedInterface.bob(): PredefinedTestNode = PredefinedTestNode(BOB, this) - -/** - * Returns plain, entirely stock nodes pre-configured with the [ALICE] and [BOB] X.500 names in that order. They have been - * started up in parallel and are now ready to use. - */ -fun DriverDSLExposedInterface.aliceAndBob(): List { - val alice = alice() - val bob = bob() - listOf(alice.nodeFuture, bob.nodeFuture).transpose().get() - return listOf(alice, bob) -}