From 3b8d6963798ced33505fa67026effce76613abdd Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Fri, 17 Feb 2017 12:23:14 +0000 Subject: [PATCH] Add missing @Suspendable Add missing @Suspendable to CashIssueFlow, as well as adding sanity check to result of starting CashIssueFlow from IntegrationTestingTutorial. --- .../net/corda/docs/IntegrationTestingTutorial.kt | 15 ++++++++++----- .../main/kotlin/net/corda/flows/CashIssueFlow.kt | 2 ++ .../kotlin/net/corda/flows/CashPaymentFlow.kt | 2 +- .../services/statemachine/FlowStateMachineImpl.kt | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) 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 bc2ee289fd..a5dd4b4640 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 @@ -1,6 +1,7 @@ package net.corda.docs import com.google.common.util.concurrent.Futures +import com.google.common.util.concurrent.ListenableFuture import net.corda.contracts.asset.Cash import net.corda.core.contracts.DOLLARS import net.corda.core.contracts.issuedBy @@ -21,6 +22,7 @@ import net.corda.testing.expectEvents import net.corda.testing.parallel import net.corda.testing.sequence import org.junit.Test +import java.util.* import kotlin.concurrent.thread import kotlin.test.assertEquals @@ -58,16 +60,20 @@ class IntegrationTestingTutorial { // START 4 val issueRef = OpaqueBytes.of(0) + val futures = Stack>() for (i in 1 .. 10) { thread { - aliceProxy.startFlow(::CashIssueFlow, + futures.push(aliceProxy.startFlow(::CashIssueFlow, i.DOLLARS, issueRef, bob.nodeInfo.legalIdentity, notary.nodeInfo.notaryIdentity - ) + ).returnValue) } } + while (!futures.empty()) { + futures.pop().getOrThrow() + } bobVaultUpdates.expectEvents { parallel( @@ -86,11 +92,10 @@ class IntegrationTestingTutorial { // START 5 for (i in 1 .. 10) { - val flowHandle = bobProxy.startFlow(::CashPaymentFlow, + bobProxy.startFlow(::CashPaymentFlow, i.DOLLARS.issuedBy(alice.nodeInfo.legalIdentity.ref(issueRef)), alice.nodeInfo.legalIdentity - ) - flowHandle.returnValue.getOrThrow() + ).returnValue.getOrThrow() } aliceVaultUpdates.expectEvents { diff --git a/finance/src/main/kotlin/net/corda/flows/CashIssueFlow.kt b/finance/src/main/kotlin/net/corda/flows/CashIssueFlow.kt index f36006acc6..dccba79c55 100644 --- a/finance/src/main/kotlin/net/corda/flows/CashIssueFlow.kt +++ b/finance/src/main/kotlin/net/corda/flows/CashIssueFlow.kt @@ -1,5 +1,6 @@ package net.corda.flows +import co.paralleluniverse.fibers.Suspendable import net.corda.contracts.asset.Cash import net.corda.core.contracts.Amount import net.corda.core.contracts.PartyAndReference @@ -30,6 +31,7 @@ class CashIssueFlow(val amount: Amount, recipient: Party, notary: Party) : this(amount, issueRef, recipient, notary, tracker()) + @Suspendable override fun call(): SignedTransaction { progressTracker.currentStep = GENERATING_TX val builder: TransactionBuilder = TransactionType.General.Builder(notary = null) diff --git a/finance/src/main/kotlin/net/corda/flows/CashPaymentFlow.kt b/finance/src/main/kotlin/net/corda/flows/CashPaymentFlow.kt index 7c0100dd88..d78f310177 100644 --- a/finance/src/main/kotlin/net/corda/flows/CashPaymentFlow.kt +++ b/finance/src/main/kotlin/net/corda/flows/CashPaymentFlow.kt @@ -32,7 +32,7 @@ open class CashPaymentFlow(val amount: Amount>, val recipient: recipient.owningKey, setOf(amount.token.issuer.party)) } catch (e: InsufficientBalanceException) { - throw CashException("Insufficent cash for spend", e) + throw CashException("Insufficient cash for spend", e) } progressTracker.currentStep = SIGNING_TX diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt index 5758aa9312..864049e787 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt @@ -130,7 +130,7 @@ class FlowStateMachineImpl(override val id: StateMachineRunId, internal fun commitTransaction() { val transaction = TransactionManager.current() try { - logger.trace { "Commiting database transaction $transaction on ${Strand.currentStrand()}." } + logger.trace { "Committing database transaction $transaction on ${Strand.currentStrand()}." } transaction.commit() } catch (e: SQLException) { // TODO: we will get here if the database is not available. Think about how to shutdown and restart cleanly.