gpt4 book ai didi

Corda - 自 Corda 4 升级以来测试接受器流程失败

转载 作者:行者123 更新时间:2023-12-01 09:50:12 25 4
gpt4 key购买 nike

以下流测试曾经在 Corda 3 中工作...

@Test
fun `can ping counterparties`() {

val acceptorFlowFutures = listOf(nodeB, nodeC).map {
it.registerInitiatedFlow(SendPingAcceptorFlow::class.java).toFuture()
}

nodeA.startFlow(SendPingInitiatorFlow("Ping!"))
network.runNetwork()

acceptorFlowFutures.forEach {
val result = it
.getOrThrow(Duration.ofMinutes(1)) // Timeout failure here
.stateMachine
.resultFuture
.getOrThrow(Duration.ofMinutes(1)) as String

assertEquals("Ping!", result)
}
}

但自从更新为使用 Corda 4 后,它现在出现以下异常:

java.util.concurrent.TimeoutException

这可能是什么原因造成的?

最佳答案

我已经在给定的场景下在 Corda 4 上成功测试了以下代码。

import co.paralleluniverse.fibers.Suspendable
import net.corda.core.flows.*
import net.corda.core.identity.Party
import net.corda.core.toFuture
import net.corda.core.utilities.getOrThrow
import net.corda.core.utilities.unwrap
import net.corda.testing.internal.chooseIdentity
import net.corda.testing.node.MockNetwork
import net.corda.testing.node.StartedMockNode
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.time.Duration
import kotlin.test.assertEquals

class DummyFlowUnitTests2 {
lateinit var network: MockNetwork
lateinit var nodeA: StartedMockNode
lateinit var nodeB: StartedMockNode
lateinit var nodeC: StartedMockNode

lateinit var partyA: Party
lateinit var partyB: Party
lateinit var partyC: Party

@Before
fun setup() {
network = MockNetwork(listOf("com.corda.cordapp"))

//Create nodes.
nodeA = network.createNode()
nodeB = network.createNode()
nodeC = network.createNode()

partyA = nodeA.info.chooseIdentity()
partyB = nodeB.info.chooseIdentity()
partyC = nodeC.info.chooseIdentity()

nodeB.registerInitiatedFlow(SendPingAcceptorFlow::class.java)
nodeC.registerInitiatedFlow(SendPingAcceptorFlow::class.java)
}

@After
fun tearDown() {
network.stopNodes()
}

@Test
fun `can ping counterparties`() {

val acceptorFlowFutures = listOf(nodeB, nodeC).map {
it.registerInitiatedFlow(SendPingAcceptorFlow::class.java).toFuture()
}

nodeA.startFlow(SendPingInitiatorFlow("Ping!", listOf(partyB, partyC)))
network.runNetwork()

acceptorFlowFutures.forEach {
val result = it
.getOrThrow(Duration.ofMinutes(1)) // Timeout failure here
.stateMachine
.resultFuture
.getOrThrow(Duration.ofMinutes(1)) as String

assertEquals("Ping!", result)
}
}

@InitiatingFlow
@StartableByRPC
data class SendPingInitiatorFlow(val msg: String, val parties: List<Party>) : FlowLogic<Unit>() {

@Suspendable
override fun call() {
parties.map { initiateFlow(it) }.forEach {
it.send(msg)
}
}
}

@InitiatedBy(SendPingInitiatorFlow::class)
data class SendPingAcceptorFlow(val othersideSession: FlowSession) : FlowLogic<String>() {

@Suspendable
override fun call(): String {
return othersideSession.receive<String>().unwrap { it }
}
}
}

关于Corda - 自 Corda 4 升级以来测试接受器流程失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56170362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com