Search in sources :

Example 11 with ProcessScheduler

use of org.apache.nifi.controller.ProcessScheduler in project nifi by apache.

the class TestProcessorLifecycle method validateStartFailsOnInvalidProcessorWithMissingProperty.

/**
 * Validate that processor will not be validated on failing
 * PropertyDescriptor validation.
 */
@Test(expected = IllegalStateException.class)
public void validateStartFailsOnInvalidProcessorWithMissingProperty() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode, true);
    fail();
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Example 12 with ProcessScheduler

use of org.apache.nifi.controller.ProcessScheduler in project nifi by apache.

the class TestProcessorLifecycle method validateStopCallsAreMeaninglessIfProcessorNotStarted.

/**
 * Validates that stop calls are harmless and idempotent if processor is not
 * in STARTING or RUNNING state.
 */
@Test
public void validateStopCallsAreMeaninglessIfProcessorNotStarted() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    // sets the scenario for the processor to run
    int randomDelayLimit = 3000;
    this.randomOnTriggerDelay(testProcessor, randomDelayLimit);
    final ProcessScheduler ps = fc.getProcessScheduler();
    ps.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    assertTrue(testProcessor.operationNames.isEmpty());
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Example 13 with ProcessScheduler

use of org.apache.nifi.controller.ProcessScheduler in project nifi by apache.

the class TestProcessorLifecycle method validateProcessorCanBeStoppedWhenOnTriggerThrowsException.

/**
 * Validates that processor can be stopped if onTrigger() keeps throwing
 * exceptions.
 */
@Test
public void validateProcessorCanBeStoppedWhenOnTriggerThrowsException() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    // sets the scenario for the processor to run
    this.noop(testProcessor);
    testProcessor.generateExceptionOnTrigger = true;
    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode, true);
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), 2000L);
    ps.disableProcessor(testProcNode);
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), 2000L);
    ps.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), 2000L);
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Example 14 with ProcessScheduler

use of org.apache.nifi.controller.ProcessScheduler in project nifi by apache.

the class TestProcessorLifecycle method validateProcessScheduledAfterAdministrativeDelayDueToTheOnScheduledException.

/**
 * Validates that Processor is eventually started once invocation of
 *
 * @OnSchedule stopped throwing exceptions.
 */
@Test
public void validateProcessScheduledAfterAdministrativeDelayDueToTheOnScheduledException() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    // sets the scenario for the processor to run
    this.noop(testProcessor);
    testProcessor.generateExceptionOnScheduled = true;
    testProcessor.keepFailingOnScheduledTimes = 2;
    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode, true);
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), 10000L);
    ps.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), 2000L);
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Example 15 with ProcessScheduler

use of org.apache.nifi.controller.ProcessScheduler in project nifi by apache.

the class TestProcessorLifecycle method validateLifecycleOperationOrderWithConcurrentCallsToStartStop.

/**
 * Concurrency test that is basically hammers on both stop and start
 * operation validating their idempotency.
 */
@Test
@Ignore
public void validateLifecycleOperationOrderWithConcurrentCallsToStartStop() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    // sets the scenario for the processor to run
    this.noop(testProcessor);
    final ProcessScheduler ps = fc.getProcessScheduler();
    ExecutorService executor = Executors.newFixedThreadPool(100);
    int startCallsCount = 10000;
    final CountDownLatch countDownCounter = new CountDownLatch(startCallsCount);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    final Random random = new Random();
    for (int i = 0; i < startCallsCount / 2; i++) {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                LockSupport.parkNanos(random.nextInt(9000000));
                ps.stopProcessor(testProcNode);
                countDownCounter.countDown();
            }
        });
    }
    for (int i = 0; i < startCallsCount / 2; i++) {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                LockSupport.parkNanos(random.nextInt(9000000));
                ps.startProcessor(testProcNode, true);
                countDownCounter.countDown();
            }
        });
    }
    assertTrue(countDownCounter.await(1000000, TimeUnit.MILLISECONDS));
    String previousOperation = null;
    for (String operationName : testProcessor.operationNames) {
        if (previousOperation == null || previousOperation.equals("@OnStopped")) {
            assertEquals("@OnScheduled", operationName);
        } else if (previousOperation.equals("@OnScheduled")) {
            assertEquals("@OnUnscheduled", operationName);
        } else if (previousOperation.equals("@OnUnscheduled")) {
            assertTrue(operationName.equals("@OnStopped") || operationName.equals("@OnScheduled"));
        }
        previousOperation = operationName;
    }
    executor.shutdownNow();
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Random(java.util.Random) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ProcessScheduler (org.apache.nifi.controller.ProcessScheduler)16 ProcessGroup (org.apache.nifi.groups.ProcessGroup)15 ProcessorNode (org.apache.nifi.controller.ProcessorNode)14 Test (org.junit.Test)14 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 AuthorizationRequest (org.apache.nifi.authorization.AuthorizationRequest)1 Authorizer (org.apache.nifi.authorization.Authorizer)1 Connection (org.apache.nifi.connectable.Connection)1 StandardFlowFileQueue (org.apache.nifi.controller.StandardFlowFileQueue)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1 BulletinRepository (org.apache.nifi.reporting.BulletinRepository)1 Ignore (org.junit.Ignore)1