【问题标题】:Corda - Testing acceptor flows fails since Corda 4 upgradeCorda - 自 Corda 4 升级以来测试接受器流失败
【发布时间】:2019-05-24 22:47:59
【问题描述】:

以下流测试曾经在 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


    【解决方案1】:

    我已经在 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 }
            }
        }
    }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-07
      • 2018-11-27
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 2020-04-04
      • 1970-01-01
      相关资源
      最近更新 更多