Repository: incubator-nifi Updated Branches: refs/heads/NIFI-250 be00d0caf -> a227fe46b
NIFI-250: Fixed bug that occurred in refactoring Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/a227fe46 Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/a227fe46 Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/a227fe46 Branch: refs/heads/NIFI-250 Commit: a227fe46b542fdcd6dd6fe57f11d678da237bc98 Parents: be00d0c Author: Mark Payne <[email protected]> Authored: Thu Feb 19 15:56:38 2015 -0500 Committer: Mark Payne <[email protected]> Committed: Thu Feb 19 15:56:38 2015 -0500 ---------------------------------------------------------------------- .../StandardControllerServiceProvider.java | 8 ++- .../TestStandardControllerServiceProvider.java | 51 +++++++++++++++----- 2 files changed, 44 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/a227fe46/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java index 74f11fb..79132b1 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java @@ -405,13 +405,17 @@ public class StandardControllerServiceProvider implements ControllerServiceProvi } private void enableReferencingServices(final ControllerServiceNode serviceNode, final List<ControllerServiceNode> recursiveReferences) { - serviceNode.verifyCanEnable(new HashSet<>(recursiveReferences)); + if ( serviceNode.getState() != ControllerServiceState.ENABLED && serviceNode.getState() != ControllerServiceState.ENABLING ) { + serviceNode.verifyCanEnable(new HashSet<>(recursiveReferences)); + } + final Set<ControllerServiceNode> ifEnabled = new HashSet<>(); final List<ControllerServiceNode> toEnable = findRecursiveReferences(serviceNode, ControllerServiceNode.class); for ( final ControllerServiceNode nodeToEnable : toEnable ) { final ControllerServiceState state = nodeToEnable.getState(); if ( state != ControllerServiceState.ENABLED && state != ControllerServiceState.ENABLING ) { - nodeToEnable.verifyCanEnable(); + nodeToEnable.verifyCanEnable(ifEnabled); + ifEnabled.add(nodeToEnable); } } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/a227fe46/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceProvider.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceProvider.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceProvider.java index 66abf30..46dd885 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceProvider.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceProvider.java @@ -40,9 +40,34 @@ import org.mockito.stubbing.Answer; public class TestStandardControllerServiceProvider { + private ProcessScheduler createScheduler() { + final ProcessScheduler scheduler = Mockito.mock(ProcessScheduler.class); + Mockito.doAnswer(new Answer<Object>() { + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable { + final ControllerServiceNode node = (ControllerServiceNode) invocation.getArguments()[0]; + node.verifyCanEnable(); + node.setState(ControllerServiceState.ENABLED); + return null; + } + }).when(scheduler).enableControllerService(Mockito.any(ControllerServiceNode.class)); + + Mockito.doAnswer(new Answer<Object>() { + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable { + final ControllerServiceNode node = (ControllerServiceNode) invocation.getArguments()[0]; + node.verifyCanDisable(); + node.setState(ControllerServiceState.DISABLED); + return null; + } + }).when(scheduler).disableControllerService(Mockito.any(ControllerServiceNode.class)); + + return scheduler; + } + @Test public void testDisableControllerService() { - final ProcessScheduler scheduler = Mockito.mock(ProcessScheduler.class); + final ProcessScheduler scheduler = createScheduler(); final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(scheduler); final ControllerServiceNode serviceNode = provider.createControllerService(ServiceB.class.getName(), "B", false); @@ -52,7 +77,7 @@ public class TestStandardControllerServiceProvider { @Test public void testEnableDisableWithReference() { - final ProcessScheduler scheduler = Mockito.mock(ProcessScheduler.class); + final ProcessScheduler scheduler = createScheduler(); final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(scheduler); final ControllerServiceNode serviceNodeB = provider.createControllerService(ServiceB.class.getName(), "B", false); @@ -82,7 +107,7 @@ public class TestStandardControllerServiceProvider { @Test public void testEnableReferencingServicesGraph() { - final ProcessScheduler scheduler = Mockito.mock(ProcessScheduler.class); + final ProcessScheduler scheduler = createScheduler(); final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(scheduler); // build a graph of controller services with dependencies as such: @@ -111,15 +136,15 @@ public class TestStandardControllerServiceProvider { provider.enableControllerService(serviceNode4); provider.enableReferencingServices(serviceNode4); - assertEquals(ControllerServiceState.DISABLED, serviceNode3.getState()); - assertEquals(ControllerServiceState.DISABLED, serviceNode2.getState()); - assertEquals(ControllerServiceState.DISABLED, serviceNode1.getState()); + assertEquals(ControllerServiceState.ENABLED, serviceNode3.getState()); + assertEquals(ControllerServiceState.ENABLED, serviceNode2.getState()); + assertEquals(ControllerServiceState.ENABLED, serviceNode1.getState()); } @Test public void testStartStopReferencingComponents() { - final ProcessScheduler scheduler = Mockito.mock(ProcessScheduler.class); + final ProcessScheduler scheduler = createScheduler(); final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(scheduler); // build a graph of reporting tasks and controller services with dependencies as such: @@ -184,9 +209,9 @@ public class TestStandardControllerServiceProvider { provider.enableReferencingServices(serviceNode4); provider.scheduleReferencingComponents(serviceNode4); - assertEquals(ControllerServiceState.DISABLED, serviceNode3.getState()); - assertEquals(ControllerServiceState.DISABLED, serviceNode2.getState()); - assertEquals(ControllerServiceState.DISABLED, serviceNode1.getState()); + assertEquals(ControllerServiceState.ENABLED, serviceNode3.getState()); + assertEquals(ControllerServiceState.ENABLED, serviceNode2.getState()); + assertEquals(ControllerServiceState.ENABLED, serviceNode1.getState()); assertTrue(procNodeA.isRunning()); assertTrue(procNodeB.isRunning()); @@ -194,9 +219,9 @@ public class TestStandardControllerServiceProvider { provider.unscheduleReferencingComponents(serviceNode4); assertFalse(procNodeA.isRunning()); assertFalse(procNodeB.isRunning()); - assertEquals(ControllerServiceState.DISABLED, serviceNode3.getState()); - assertEquals(ControllerServiceState.DISABLED, serviceNode2.getState()); - assertEquals(ControllerServiceState.DISABLED, serviceNode1.getState()); + assertEquals(ControllerServiceState.ENABLED, serviceNode3.getState()); + assertEquals(ControllerServiceState.ENABLED, serviceNode2.getState()); + assertEquals(ControllerServiceState.ENABLED, serviceNode1.getState()); provider.disableReferencingServices(serviceNode4); assertEquals(ControllerServiceState.DISABLED, serviceNode3.getState());
