mirror of
https://github.com/corda/corda.git
synced 2025-01-26 22:29:28 +00:00
Add missing @Suspendable
Add missing @Suspendable to CashIssueFlow, as well as adding sanity check to result of starting CashIssueFlow from IntegrationTestingTutorial.
This commit is contained in:
parent
5d6abb6387
commit
3b8d696379
@ -1,6 +1,7 @@
|
|||||||
package net.corda.docs
|
package net.corda.docs
|
||||||
|
|
||||||
import com.google.common.util.concurrent.Futures
|
import com.google.common.util.concurrent.Futures
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture
|
||||||
import net.corda.contracts.asset.Cash
|
import net.corda.contracts.asset.Cash
|
||||||
import net.corda.core.contracts.DOLLARS
|
import net.corda.core.contracts.DOLLARS
|
||||||
import net.corda.core.contracts.issuedBy
|
import net.corda.core.contracts.issuedBy
|
||||||
@ -21,6 +22,7 @@ import net.corda.testing.expectEvents
|
|||||||
import net.corda.testing.parallel
|
import net.corda.testing.parallel
|
||||||
import net.corda.testing.sequence
|
import net.corda.testing.sequence
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import java.util.*
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@ -58,16 +60,20 @@ class IntegrationTestingTutorial {
|
|||||||
|
|
||||||
// START 4
|
// START 4
|
||||||
val issueRef = OpaqueBytes.of(0)
|
val issueRef = OpaqueBytes.of(0)
|
||||||
|
val futures = Stack<ListenableFuture<*>>()
|
||||||
for (i in 1 .. 10) {
|
for (i in 1 .. 10) {
|
||||||
thread {
|
thread {
|
||||||
aliceProxy.startFlow(::CashIssueFlow,
|
futures.push(aliceProxy.startFlow(::CashIssueFlow,
|
||||||
i.DOLLARS,
|
i.DOLLARS,
|
||||||
issueRef,
|
issueRef,
|
||||||
bob.nodeInfo.legalIdentity,
|
bob.nodeInfo.legalIdentity,
|
||||||
notary.nodeInfo.notaryIdentity
|
notary.nodeInfo.notaryIdentity
|
||||||
)
|
).returnValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (!futures.empty()) {
|
||||||
|
futures.pop().getOrThrow()
|
||||||
|
}
|
||||||
|
|
||||||
bobVaultUpdates.expectEvents {
|
bobVaultUpdates.expectEvents {
|
||||||
parallel(
|
parallel(
|
||||||
@ -86,11 +92,10 @@ class IntegrationTestingTutorial {
|
|||||||
|
|
||||||
// START 5
|
// START 5
|
||||||
for (i in 1 .. 10) {
|
for (i in 1 .. 10) {
|
||||||
val flowHandle = bobProxy.startFlow(::CashPaymentFlow,
|
bobProxy.startFlow(::CashPaymentFlow,
|
||||||
i.DOLLARS.issuedBy(alice.nodeInfo.legalIdentity.ref(issueRef)),
|
i.DOLLARS.issuedBy(alice.nodeInfo.legalIdentity.ref(issueRef)),
|
||||||
alice.nodeInfo.legalIdentity
|
alice.nodeInfo.legalIdentity
|
||||||
)
|
).returnValue.getOrThrow()
|
||||||
flowHandle.returnValue.getOrThrow()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aliceVaultUpdates.expectEvents {
|
aliceVaultUpdates.expectEvents {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.corda.flows
|
package net.corda.flows
|
||||||
|
|
||||||
|
import co.paralleluniverse.fibers.Suspendable
|
||||||
import net.corda.contracts.asset.Cash
|
import net.corda.contracts.asset.Cash
|
||||||
import net.corda.core.contracts.Amount
|
import net.corda.core.contracts.Amount
|
||||||
import net.corda.core.contracts.PartyAndReference
|
import net.corda.core.contracts.PartyAndReference
|
||||||
@ -30,6 +31,7 @@ class CashIssueFlow(val amount: Amount<Currency>,
|
|||||||
recipient: Party,
|
recipient: Party,
|
||||||
notary: Party) : this(amount, issueRef, recipient, notary, tracker())
|
notary: Party) : this(amount, issueRef, recipient, notary, tracker())
|
||||||
|
|
||||||
|
@Suspendable
|
||||||
override fun call(): SignedTransaction {
|
override fun call(): SignedTransaction {
|
||||||
progressTracker.currentStep = GENERATING_TX
|
progressTracker.currentStep = GENERATING_TX
|
||||||
val builder: TransactionBuilder = TransactionType.General.Builder(notary = null)
|
val builder: TransactionBuilder = TransactionType.General.Builder(notary = null)
|
||||||
|
@ -32,7 +32,7 @@ open class CashPaymentFlow(val amount: Amount<Issued<Currency>>, val recipient:
|
|||||||
recipient.owningKey,
|
recipient.owningKey,
|
||||||
setOf(amount.token.issuer.party))
|
setOf(amount.token.issuer.party))
|
||||||
} catch (e: InsufficientBalanceException) {
|
} catch (e: InsufficientBalanceException) {
|
||||||
throw CashException("Insufficent cash for spend", e)
|
throw CashException("Insufficient cash for spend", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
progressTracker.currentStep = SIGNING_TX
|
progressTracker.currentStep = SIGNING_TX
|
||||||
|
@ -130,7 +130,7 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
|
|||||||
internal fun commitTransaction() {
|
internal fun commitTransaction() {
|
||||||
val transaction = TransactionManager.current()
|
val transaction = TransactionManager.current()
|
||||||
try {
|
try {
|
||||||
logger.trace { "Commiting database transaction $transaction on ${Strand.currentStrand()}." }
|
logger.trace { "Committing database transaction $transaction on ${Strand.currentStrand()}." }
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
} catch (e: SQLException) {
|
} catch (e: SQLException) {
|
||||||
// TODO: we will get here if the database is not available. Think about how to shutdown and restart cleanly.
|
// TODO: we will get here if the database is not available. Think about how to shutdown and restart cleanly.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user