From 083efc22cfd5350b8b86b63f89506982a2129308 Mon Sep 17 00:00:00 2001 From: Dries Samyn Date: Mon, 2 Oct 2023 10:18:04 +0100 Subject: [PATCH] - Don't create if the correct config not passed in. - Fix FlowServiceTest --- .../flow/maintenance/FlowMaintenanceImpl.kt | 28 +++++++++++-------- .../maintenance/FlowMaintenanceImplTests.kt | 8 ++++++ .../net/corda/flow/service/FlowServiceTest.kt | 4 ++- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/components/flow/flow-service/src/main/kotlin/net/corda/flow/maintenance/FlowMaintenanceImpl.kt b/components/flow/flow-service/src/main/kotlin/net/corda/flow/maintenance/FlowMaintenanceImpl.kt index cddd0c6df6f..faeee069ac7 100644 --- a/components/flow/flow-service/src/main/kotlin/net/corda/flow/maintenance/FlowMaintenanceImpl.kt +++ b/components/flow/flow-service/src/main/kotlin/net/corda/flow/maintenance/FlowMaintenanceImpl.kt @@ -1,6 +1,5 @@ package net.corda.flow.maintenance -import net.corda.flow.service.FlowExecutor import net.corda.libs.configuration.SmartConfig import net.corda.libs.configuration.helper.getConfig import net.corda.libs.statemanager.api.StateManagerFactory @@ -35,19 +34,24 @@ class FlowMaintenanceImpl @Activate constructor( private val logger = LoggerFactory.getLogger(this::class.java.enclosingClass) } - private val coordinator = coordinatorFactory.createCoordinator(::eventHandler) + private val coordinator = coordinatorFactory.createCoordinator(::eventHandler) override fun onConfigChange(config: Map) { - val messagingConfig = config.getConfig(ConfigKeys.MESSAGING_CONFIG) // TODO - fix config key. The state manager has nothing to do with messaging. - val stateManagerConfig = config.getConfig(ConfigKeys.MESSAGING_CONFIG) - coordinator.createManagedResource("FLOW_MAINTENANCE_SUBSCRIPTION") { - subscriptionFactory.createDurableSubscription( - SubscriptionConfig("flow.maintenance.tasks", Schemas.ScheduledTask.SCHEDULED_TASK_TOPIC_FLOW_PROCESSOR), - SessionTimeoutTaskProcessor(stateManagerFactory.create(stateManagerConfig)), - messagingConfig, - null - ) - }.start() + if(config.containsKey(ConfigKeys.MESSAGING_CONFIG)) { + val messagingConfig = config.getConfig(ConfigKeys.MESSAGING_CONFIG) + val stateManagerConfig = config.getConfig(ConfigKeys.MESSAGING_CONFIG) + coordinator.createManagedResource("FLOW_MAINTENANCE_SUBSCRIPTION") { + subscriptionFactory.createDurableSubscription( + SubscriptionConfig( + "flow.maintenance.tasks", + Schemas.ScheduledTask.SCHEDULED_TASK_TOPIC_FLOW_PROCESSOR + ), + SessionTimeoutTaskProcessor(stateManagerFactory.create(stateManagerConfig)), + messagingConfig, + null + ) + }.start() + } } override val isRunning: Boolean diff --git a/components/flow/flow-service/src/test/kotlin/net/corda/flow/maintenance/FlowMaintenanceImplTests.kt b/components/flow/flow-service/src/test/kotlin/net/corda/flow/maintenance/FlowMaintenanceImplTests.kt index 80266cbc0ef..33ed1326776 100644 --- a/components/flow/flow-service/src/test/kotlin/net/corda/flow/maintenance/FlowMaintenanceImplTests.kt +++ b/components/flow/flow-service/src/test/kotlin/net/corda/flow/maintenance/FlowMaintenanceImplTests.kt @@ -18,6 +18,7 @@ import org.mockito.kotlin.doReturn import org.mockito.kotlin.eq import org.mockito.kotlin.isNull import org.mockito.kotlin.mock +import org.mockito.kotlin.never import org.mockito.kotlin.verify class FlowMaintenanceImplTests { @@ -60,4 +61,11 @@ class FlowMaintenanceImplTests { verify(stateManagerFactory).create(stateManagerConfig) verify(subscription).start() } + + @Test + fun `do nothing when messaging config not sent`() { + val m = FlowMaintenanceImpl(lifecycleCoordinatorFactory, subscriptionFactory, stateManagerFactory) + m.onConfigChange(mapOf("foo" to mock())) + verify(lifecycleCoordinator, never()).createManagedResource(any(), any<() -> Subscription>()) + } } \ No newline at end of file diff --git a/components/flow/flow-service/src/test/kotlin/net/corda/flow/service/FlowServiceTest.kt b/components/flow/flow-service/src/test/kotlin/net/corda/flow/service/FlowServiceTest.kt index 1a913c77756..cd94b4c9fd5 100644 --- a/components/flow/flow-service/src/test/kotlin/net/corda/flow/service/FlowServiceTest.kt +++ b/components/flow/flow-service/src/test/kotlin/net/corda/flow/service/FlowServiceTest.kt @@ -31,7 +31,8 @@ class FlowServiceTest { Arguments.of(LifecycleCoordinatorName.forComponent()), Arguments.of(LifecycleCoordinatorName.forComponent()), Arguments.of(LifecycleCoordinatorName.forComponent()), - Arguments.of(LifecycleCoordinatorName.forComponent()) + Arguments.of(LifecycleCoordinatorName.forComponent()), + Arguments.of(LifecycleCoordinatorName.forComponent()), ) } } @@ -147,6 +148,7 @@ class FlowServiceTest { addDependency() addDependency() addDependency() + addDependency() FlowService( coordinatorFactory,