From fa607024c285e0b9870fb05e61492648092c565e Mon Sep 17 00:00:00 2001 From: Adel El-Beik <adel.el-beik@r3.com> Date: Wed, 23 Mar 2022 13:45:21 +0000 Subject: [PATCH 1/2] ENT-6743: Contains method of flow hospital now correctly returns if flow is in hospital. Historic patient records not used. --- .../statemachine/StaffedFlowHospital.kt | 13 +---------- .../statemachine/RetryFlowMockTest.kt | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/StaffedFlowHospital.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/StaffedFlowHospital.kt index 519b2bd3d5..0548af8a4b 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/StaffedFlowHospital.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/StaffedFlowHospital.kt @@ -103,17 +103,6 @@ class StaffedFlowHospital(private val flowMessaging: FlowMessaging, * Flows should be removed from [flowsInHospital] when they have completed a successful transition. */ private val flowsInHospital = ConcurrentHashMap<StateMachineRunId, FlowFiber>() - - /** - * Returns true if the flow is currently being treated in the hospital. - * The differs to flows with a medical history (which can accessed via [StaffedFlowHospital.contains]). - */ - @VisibleForTesting - internal fun flowInHospital(runId: StateMachineRunId): Boolean { - // The .keys avoids https://youtrack.jetbrains.com/issue/KT-18053 - return runId in flowsInHospital.keys - } - private val mutex = ThreadBox(object { /** * Contains medical history of every flow (a patient) that has entered the hospital. A flow can leave the hospital, @@ -347,7 +336,7 @@ class StaffedFlowHospital(private val flowMessaging: FlowMessaging, } } - operator fun contains(flowId: StateMachineRunId) = mutex.locked { flowId in flowPatients } + operator fun contains(flowId: StateMachineRunId) = flowId in flowsInHospital.keys override fun close() { hospitalJobTimer.cancel() diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt index 2e4ccdecc2..bd6b3fcd93 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt @@ -6,6 +6,7 @@ import net.corda.core.flows.Destination import net.corda.core.flows.FlowInfo import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowSession +import net.corda.core.flows.HospitalizeFlowException import net.corda.core.flows.InitiatedBy import net.corda.core.flows.InitiatingFlow import net.corda.core.flows.KilledFlowException @@ -29,6 +30,7 @@ import net.corda.testing.node.internal.MessagingServiceSpy import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.enclosedCordapp import net.corda.testing.node.internal.newContext +import net.corda.testing.node.internal.startFlow import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.h2.util.Utils @@ -47,6 +49,7 @@ import java.util.concurrent.Semaphore import java.util.concurrent.TimeUnit import kotlin.test.assertEquals import kotlin.test.assertFailsWith +import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -324,6 +327,25 @@ class RetryFlowMockTest { } } + class HospitalizeThenSucceedFlow : FlowLogic<Boolean>() { + companion object { + var runs = 0 + var flowRetried = Semaphore(0) + var flowWillReturn = Semaphore(0) + } + + @Suspendable + override fun call(): Boolean { + if (runs == 0) { + runs++ + throw HospitalizeFlowException("Hospitalize on first run") + } + flowRetried.release() + flowWillReturn.acquire() + return true + } + } + @InitiatingFlow class UnbalancedSendAndReceiveFlow(private val other: Party) : FlowLogic<Unit>() { From c1002697c733369d8779a2e15fdb905a093ca4c8 Mon Sep 17 00:00:00 2001 From: Adel El-Beik <adel.el-beik@r3.com> Date: Mon, 25 Apr 2022 11:30:24 +0100 Subject: [PATCH 2/2] ENT-6743: Reverted RetryFlowMockTest as the retry op only available on ENT. --- .../statemachine/RetryFlowMockTest.kt | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt index bd6b3fcd93..2e4ccdecc2 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt @@ -6,7 +6,6 @@ import net.corda.core.flows.Destination import net.corda.core.flows.FlowInfo import net.corda.core.flows.FlowLogic import net.corda.core.flows.FlowSession -import net.corda.core.flows.HospitalizeFlowException import net.corda.core.flows.InitiatedBy import net.corda.core.flows.InitiatingFlow import net.corda.core.flows.KilledFlowException @@ -30,7 +29,6 @@ import net.corda.testing.node.internal.MessagingServiceSpy import net.corda.testing.node.internal.TestStartedNode import net.corda.testing.node.internal.enclosedCordapp import net.corda.testing.node.internal.newContext -import net.corda.testing.node.internal.startFlow import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.h2.util.Utils @@ -49,7 +47,6 @@ import java.util.concurrent.Semaphore import java.util.concurrent.TimeUnit import kotlin.test.assertEquals import kotlin.test.assertFailsWith -import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -327,25 +324,6 @@ class RetryFlowMockTest { } } - class HospitalizeThenSucceedFlow : FlowLogic<Boolean>() { - companion object { - var runs = 0 - var flowRetried = Semaphore(0) - var flowWillReturn = Semaphore(0) - } - - @Suspendable - override fun call(): Boolean { - if (runs == 0) { - runs++ - throw HospitalizeFlowException("Hospitalize on first run") - } - flowRetried.release() - flowWillReturn.acquire() - return true - } - } - @InitiatingFlow class UnbalancedSendAndReceiveFlow(private val other: Party) : FlowLogic<Unit>() {