mirror of
https://github.com/corda/corda.git
synced 2025-02-20 09:26:41 +00:00
Inline DriverConstants. (#2156)
This commit is contained in:
parent
a314a6a125
commit
10e686bc82
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 <R> 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<PredefinedTestNode> {
|
||||
val alice = alice()
|
||||
val bob = bob()
|
||||
listOf(alice.nodeFuture, bob.nodeFuture).transpose().get()
|
||||
return listOf(alice, bob)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user