use of org.apache.nifi.controller.ProcessorNode 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();
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class TestProcessorLifecycle method validateIdempotencyOfProcessorStartOperation.
/**
* Will validate the idempotent nature of processor start operation which
* can be called multiple times without any side-effects.
*/
@Test
public void validateIdempotencyOfProcessorStartOperation() 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();
ps.startProcessor(testProcNode, true);
ps.startProcessor(testProcNode, true);
ps.startProcessor(testProcNode, true);
Thread.sleep(500);
assertCondition(() -> testProcessor.operationNames.size() == 1);
assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class StandardFlowSerializerTest method testSerializationEscapingAndFiltering.
@Test
public void testSerializationEscapingAndFiltering() throws Exception {
final ProcessorNode dummy = controller.createProcessor(DummyScheduledProcessor.class.getName(), UUID.randomUUID().toString(), systemBundle.getBundleDetails().getCoordinate());
dummy.setComments(RAW_COMMENTS);
controller.getRootGroup().addProcessor(dummy);
// serialize the controller
final ByteArrayOutputStream os = new ByteArrayOutputStream();
serializer.serialize(controller, os, ScheduledStateLookup.IDENTITY_LOOKUP);
// verify the results contain the serialized string
final String serializedFlow = os.toString(StandardCharsets.UTF_8.name());
assertTrue(serializedFlow.contains(SERIALIZED_COMMENTS));
assertFalse(serializedFlow.contains(RAW_COMMENTS));
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class TestStandardControllerServiceProvider method createProcessor.
private ProcessorNode createProcessor(final StandardProcessScheduler scheduler, final ControllerServiceProvider serviceProvider) {
final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class);
final LoggableComponent<Processor> dummyProcessor = new LoggableComponent<>(new DummyProcessor(), systemBundle.getBundleDetails().getCoordinate(), null);
final ProcessorNode procNode = new StandardProcessorNode(dummyProcessor, UUID.randomUUID().toString(), new StandardValidationContextFactory(serviceProvider, null), scheduler, serviceProvider, niFiProperties, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent);
final ProcessGroup group = new StandardProcessGroup(UUID.randomUUID().toString(), serviceProvider, scheduler, null, null, Mockito.mock(FlowController.class), new MutableVariableRegistry(variableRegistry));
group.addProcessor(procNode);
procNode.setProcessGroup(group);
return procNode;
}
use of org.apache.nifi.controller.ProcessorNode 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());
}
Aggregations