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();
}
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());
}
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);
}
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);
}
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();
}
Aggregations