Added a method to NodeHandle to simplify using RPC in the Driver

This commit is contained in:
Shams Asari
2017-01-06 11:33:00 +00:00
parent 0867a05ad7
commit 59456cb6b1
17 changed files with 146 additions and 148 deletions

View File

@ -1,8 +1,10 @@
package net.corda.docs
import com.google.common.util.concurrent.Futures
import net.corda.contracts.asset.Cash
import net.corda.core.contracts.DOLLARS
import net.corda.core.contracts.issuedBy
import net.corda.core.getOrThrow
import net.corda.core.messaging.startFlow
import net.corda.core.node.services.ServiceInfo
import net.corda.core.node.services.Vault
@ -12,9 +14,6 @@ import net.corda.flows.CashFlow
import net.corda.flows.CashFlowResult
import net.corda.node.driver.driver
import net.corda.node.services.User
import net.corda.node.services.config.configureTestSSL
import net.corda.node.services.messaging.ArtemisMessagingComponent
import net.corda.node.services.messaging.CordaRPCClient
import net.corda.node.services.startFlowPermission
import net.corda.node.services.transactions.ValidatingNotaryService
import net.corda.testing.expect
@ -26,31 +25,25 @@ import kotlin.concurrent.thread
import kotlin.test.assertEquals
class IntegrationTestingTutorial {
@Test
fun aliceBobCashExchangeExample() {
fun `alice bob cash exchange example`() {
// START 1
driver {
val testUser = User("testUser", "testPassword", permissions = setOf(startFlowPermission<CashFlow>()))
val aliceFuture = startNode("Alice", rpcUsers = listOf(testUser))
val bobFuture = startNode("Bob", rpcUsers = listOf(testUser))
val notaryFuture = startNode("Notary", advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type)))
val alice = aliceFuture.get()
val bob = bobFuture.get()
val notary = notaryFuture.get()
val (alice, bob, notary) = Futures.allAsList(
startNode("Alice", rpcUsers = listOf(testUser)),
startNode("Bob", rpcUsers = listOf(testUser)),
startNode("Notary", advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type)))
).getOrThrow()
// END 1
// START 2
val aliceClient = CordaRPCClient(
host = ArtemisMessagingComponent.toHostAndPort(alice.nodeInfo.address),
config = configureTestSSL()
)
val aliceClient = alice.rpcClientToNode()
aliceClient.start("testUser", "testPassword")
val aliceProxy = aliceClient.proxy()
val bobClient = CordaRPCClient(
host = ArtemisMessagingComponent.toHostAndPort(bob.nodeInfo.address),
config = configureTestSSL()
)
val bobClient = bob.rpcClientToNode()
bobClient.start("testUser", "testPassword")
val bobProxy = bobClient.proxy()
// END 2

View File

@ -6,7 +6,6 @@ import net.corda.core.contracts.Amount
import net.corda.core.contracts.Issued
import net.corda.core.contracts.PartyAndReference
import net.corda.core.contracts.USD
import net.corda.core.div
import net.corda.core.messaging.CordaRPCOps
import net.corda.core.messaging.startFlow
import net.corda.core.node.CordaPluginRegistry
@ -17,9 +16,6 @@ import net.corda.flows.CashCommand
import net.corda.flows.CashFlow
import net.corda.node.driver.driver
import net.corda.node.services.User
import net.corda.node.services.config.FullNodeConfiguration
import net.corda.node.services.config.NodeSSLConfiguration
import net.corda.node.services.messaging.CordaRPCClient
import net.corda.node.services.startFlowPermission
import net.corda.node.services.transactions.ValidatingNotaryService
import org.graphstream.graph.Edge
@ -41,9 +37,7 @@ enum class PrintOrVisualise {
}
fun main(args: Array<String>) {
if (args.size < 1) {
throw IllegalArgumentException("Usage: <binary> [Print|Visualise]")
}
require(args.isNotEmpty()) { "Usage: <binary> [Print|Visualise]" }
val printOrVisualise = PrintOrVisualise.valueOf(args[0])
val baseDirectory = Paths.get("build/rpc-api-tutorial")
@ -52,15 +46,10 @@ fun main(args: Array<String>) {
driver(driverDirectory = baseDirectory) {
startNode("Notary", advertisedServices = setOf(ServiceInfo(ValidatingNotaryService.type)))
val node = startNode("Alice", rpcUsers = listOf(user)).get()
val sslConfig = object : NodeSSLConfiguration {
override val certificatesPath = baseDirectory / "Alice" / "certificates"
override val keyStorePassword = "cordacadevpass"
override val trustStorePassword = "trustpass"
}
// END 1
// START 2
val client = CordaRPCClient(FullNodeConfiguration(node.config).artemisAddress, sslConfig)
val client = node.rpcClientToNode()
client.start("user", "password")
val proxy = client.proxy()