Search in sources :

Example 6 with MockProcessGroup

use of org.apache.nifi.controller.service.mock.MockProcessGroup in project nifi by apache.

the class TestStandardControllerServiceProvider method testEnableReferencingComponents.

@Test
public void testEnableReferencingComponents() {
    final ProcessGroup procGroup = new MockProcessGroup(controller);
    final FlowController controller = Mockito.mock(FlowController.class);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);
    final StandardProcessScheduler scheduler = createScheduler();
    final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, null, null, stateManagerProvider, variableRegistry, niFiProperties);
    final ControllerServiceNode serviceNode = provider.createControllerService(ServiceA.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
    final ProcessorNode procNode = createProcessor(scheduler, provider);
    serviceNode.addReference(procNode);
    // procNode.setScheduledState(ScheduledState.STOPPED);
    provider.unscheduleReferencingComponents(serviceNode);
    assertEquals(ScheduledState.STOPPED, procNode.getScheduledState());
    // procNode.setScheduledState(ScheduledState.RUNNING);
    provider.unscheduleReferencingComponents(serviceNode);
    assertEquals(ScheduledState.STOPPED, procNode.getScheduledState());
}
Also used : ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ProcessorNode(org.apache.nifi.controller.ProcessorNode) StandardProcessorNode(org.apache.nifi.controller.StandardProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessGroup(org.apache.nifi.groups.StandardProcessGroup) FlowController(org.apache.nifi.controller.FlowController) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessScheduler(org.apache.nifi.controller.scheduling.StandardProcessScheduler) Test(org.junit.Test)

Example 7 with MockProcessGroup

use of org.apache.nifi.controller.service.mock.MockProcessGroup in project nifi by apache.

the class TestStandardControllerServiceProvider method validateEnableServices.

@Test
public void validateEnableServices() {
    StandardProcessScheduler scheduler = createScheduler();
    FlowController controller = Mockito.mock(FlowController.class);
    StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties);
    ProcessGroup procGroup = new MockProcessGroup(controller);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);
    ControllerServiceNode A = provider.createControllerService(ServiceA.class.getName(), "A", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode B = provider.createControllerService(ServiceA.class.getName(), "B", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode C = provider.createControllerService(ServiceA.class.getName(), "C", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode D = provider.createControllerService(ServiceB.class.getName(), "D", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode E = provider.createControllerService(ServiceA.class.getName(), "E", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode F = provider.createControllerService(ServiceB.class.getName(), "F", systemBundle.getBundleDetails().getCoordinate(), null, false);
    procGroup.addControllerService(A);
    procGroup.addControllerService(B);
    procGroup.addControllerService(C);
    procGroup.addControllerService(D);
    procGroup.addControllerService(E);
    procGroup.addControllerService(F);
    setProperty(A, ServiceA.OTHER_SERVICE.getName(), "B");
    setProperty(B, ServiceA.OTHER_SERVICE.getName(), "D");
    setProperty(C, ServiceA.OTHER_SERVICE.getName(), "B");
    setProperty(C, ServiceA.OTHER_SERVICE_2.getName(), "D");
    setProperty(E, ServiceA.OTHER_SERVICE.getName(), "A");
    setProperty(E, ServiceA.OTHER_SERVICE_2.getName(), "F");
    provider.enableControllerServices(Arrays.asList(A, B, C, D, E, F));
    assertTrue(A.isActive());
    assertTrue(B.isActive());
    assertTrue(C.isActive());
    assertTrue(D.isActive());
    assertTrue(E.isActive());
    assertTrue(F.isActive());
}
Also used : ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ProcessGroup(org.apache.nifi.groups.ProcessGroup) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessGroup(org.apache.nifi.groups.StandardProcessGroup) FlowController(org.apache.nifi.controller.FlowController) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessScheduler(org.apache.nifi.controller.scheduling.StandardProcessScheduler) Test(org.junit.Test)

Example 8 with MockProcessGroup

use of org.apache.nifi.controller.service.mock.MockProcessGroup in project nifi by apache.

the class TestStandardControllerServiceProvider method validateEnableServicesWithDisabledMissingService.

@Test
public void validateEnableServicesWithDisabledMissingService() {
    StandardProcessScheduler scheduler = createScheduler();
    FlowController controller = Mockito.mock(FlowController.class);
    StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties);
    ProcessGroup procGroup = new MockProcessGroup(controller);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);
    ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceA.class.getName(), "2", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode serviceNode5 = provider.createControllerService(ServiceA.class.getName(), "5", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode serviceNode6 = provider.createControllerService(ServiceB.class.getName(), "6", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode serviceNode7 = provider.createControllerService(ServiceC.class.getName(), "7", systemBundle.getBundleDetails().getCoordinate(), null, false);
    procGroup.addControllerService(serviceNode1);
    procGroup.addControllerService(serviceNode2);
    procGroup.addControllerService(serviceNode3);
    procGroup.addControllerService(serviceNode4);
    procGroup.addControllerService(serviceNode5);
    procGroup.addControllerService(serviceNode6);
    procGroup.addControllerService(serviceNode7);
    setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "2");
    setProperty(serviceNode2, ServiceA.OTHER_SERVICE.getName(), "4");
    setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "2");
    setProperty(serviceNode3, ServiceA.OTHER_SERVICE_2.getName(), "4");
    setProperty(serviceNode5, ServiceA.OTHER_SERVICE.getName(), "6");
    setProperty(serviceNode7, ServiceC.REQ_SERVICE_1.getName(), "2");
    setProperty(serviceNode7, ServiceC.REQ_SERVICE_2.getName(), "3");
    provider.enableControllerServices(Arrays.asList(serviceNode1, serviceNode2, serviceNode3, serviceNode4, serviceNode5, serviceNode7));
    assertFalse(serviceNode1.isActive());
    assertFalse(serviceNode2.isActive());
    assertFalse(serviceNode3.isActive());
    assertFalse(serviceNode4.isActive());
    assertFalse(serviceNode5.isActive());
    assertFalse(serviceNode6.isActive());
    provider.enableControllerService(serviceNode6);
    provider.enableControllerServices(Arrays.asList(serviceNode1, serviceNode2, serviceNode3, serviceNode4, serviceNode5));
    assertTrue(serviceNode1.isActive());
    assertTrue(serviceNode2.isActive());
    assertTrue(serviceNode3.isActive());
    assertTrue(serviceNode4.isActive());
    assertTrue(serviceNode5.isActive());
    assertTrue(serviceNode6.isActive());
}
Also used : ServiceC(org.apache.nifi.controller.service.mock.ServiceC) ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ProcessGroup(org.apache.nifi.groups.ProcessGroup) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessGroup(org.apache.nifi.groups.StandardProcessGroup) FlowController(org.apache.nifi.controller.FlowController) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessScheduler(org.apache.nifi.controller.scheduling.StandardProcessScheduler) Test(org.junit.Test)

Example 9 with MockProcessGroup

use of org.apache.nifi.controller.service.mock.MockProcessGroup in project nifi by apache.

the class TestStandardControllerServiceProvider method validateEnableServices2.

/**
 * This test is similar to the above, but different combination of service
 * dependencies
 */
@Test
public void validateEnableServices2() {
    StandardProcessScheduler scheduler = createScheduler();
    FlowController controller = Mockito.mock(FlowController.class);
    StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, scheduler, null, stateManagerProvider, variableRegistry, niFiProperties);
    ProcessGroup procGroup = new MockProcessGroup(controller);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);
    ControllerServiceNode A = provider.createControllerService(ServiceC.class.getName(), "A", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode B = provider.createControllerService(ServiceA.class.getName(), "B", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode C = provider.createControllerService(ServiceB.class.getName(), "C", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode D = provider.createControllerService(ServiceA.class.getName(), "D", systemBundle.getBundleDetails().getCoordinate(), null, false);
    ControllerServiceNode F = provider.createControllerService(ServiceA.class.getName(), "F", systemBundle.getBundleDetails().getCoordinate(), null, false);
    procGroup.addControllerService(A);
    procGroup.addControllerService(B);
    procGroup.addControllerService(C);
    procGroup.addControllerService(D);
    procGroup.addControllerService(F);
    setProperty(A, ServiceC.REQ_SERVICE_1.getName(), "B");
    setProperty(A, ServiceC.REQ_SERVICE_2.getName(), "D");
    setProperty(B, ServiceA.OTHER_SERVICE.getName(), "C");
    setProperty(F, ServiceA.OTHER_SERVICE.getName(), "D");
    setProperty(D, ServiceA.OTHER_SERVICE.getName(), "C");
    provider.enableControllerServices(Arrays.asList(C, F, A, B, D));
    assertTrue(A.isActive());
    assertTrue(B.isActive());
    assertTrue(C.isActive());
    assertTrue(D.isActive());
    assertTrue(F.isActive());
}
Also used : ServiceC(org.apache.nifi.controller.service.mock.ServiceC) ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ProcessGroup(org.apache.nifi.groups.ProcessGroup) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessGroup(org.apache.nifi.groups.StandardProcessGroup) FlowController(org.apache.nifi.controller.FlowController) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessScheduler(org.apache.nifi.controller.scheduling.StandardProcessScheduler) Test(org.junit.Test)

Aggregations

FlowController (org.apache.nifi.controller.FlowController)9 MockProcessGroup (org.apache.nifi.controller.service.mock.MockProcessGroup)9 ProcessGroup (org.apache.nifi.groups.ProcessGroup)8 ServiceA (org.apache.nifi.controller.service.mock.ServiceA)7 ServiceB (org.apache.nifi.controller.service.mock.ServiceB)7 StandardProcessGroup (org.apache.nifi.groups.StandardProcessGroup)7 Test (org.junit.Test)7 StandardProcessScheduler (org.apache.nifi.controller.scheduling.StandardProcessScheduler)6 ProcessorNode (org.apache.nifi.controller.ProcessorNode)2 StandardProcessorNode (org.apache.nifi.controller.StandardProcessorNode)2 ServiceC (org.apache.nifi.controller.service.mock.ServiceC)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LoggableComponent (org.apache.nifi.controller.LoggableComponent)1 ReloadComponent (org.apache.nifi.controller.ReloadComponent)1 TerminationAwareLogger (org.apache.nifi.controller.TerminationAwareLogger)1 ValidationContextFactory (org.apache.nifi.controller.ValidationContextFactory)1