use of org.apache.nifi.processor.Processor in project nifi by apache.
the class TestHttpFlowFileServerProtocol method setupMockProcessSession.
private void setupMockProcessSession() {
// Construct a RootGroupPort as a processor to use NiFi mock library.
final Processor rootGroupPort = mock(Processor.class);
final Set<Relationship> relationships = new HashSet<>();
relationships.add(Relationship.ANONYMOUS);
when(rootGroupPort.getRelationships()).thenReturn(relationships);
when(rootGroupPort.getIdentifier()).thenReturn("root-group-port-id");
sessionState = new SharedSessionState(rootGroupPort, new AtomicLong(0));
processSession = new MockProcessSession(sessionState, rootGroupPort);
processContext = new MockProcessContext(rootGroupPort);
}
use of org.apache.nifi.processor.Processor in project nifi by apache.
the class NewestFirstPrioritizerTest method testPrioritizer.
@Test
public void testPrioritizer() throws InstantiationException, IllegalAccessException {
final Processor processor = new SimpleProcessor();
final AtomicLong idGenerator = new AtomicLong(0L);
final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, idGenerator), Mockito.mock(Processor.class));
final MockFlowFile flowFile1 = session.create();
try {
// guarantee the FlowFile entryDate for flowFile2 is different than flowFile1
Thread.sleep(2);
} catch (final InterruptedException e) {
}
final MockFlowFile flowFile2 = session.create();
final NewestFlowFileFirstPrioritizer prioritizer = new NewestFlowFileFirstPrioritizer();
Assert.assertEquals(0, prioritizer.compare(null, null));
Assert.assertEquals(-1, prioritizer.compare(flowFile1, null));
Assert.assertEquals(1, prioritizer.compare(null, flowFile1));
Assert.assertEquals(0, prioritizer.compare(flowFile1, flowFile1));
Assert.assertEquals(0, prioritizer.compare(flowFile2, flowFile2));
Assert.assertEquals(1, prioritizer.compare(flowFile1, flowFile2));
Assert.assertEquals(-1, prioritizer.compare(flowFile2, flowFile1));
}
use of org.apache.nifi.processor.Processor in project nifi by apache.
the class OldestFirstPrioritizerTest method testPrioritizer.
@Test
public void testPrioritizer() throws InstantiationException, IllegalAccessException {
final Processor processor = new SimpleProcessor();
final AtomicLong idGenerator = new AtomicLong(0L);
final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, idGenerator), Mockito.mock(Processor.class));
final MockFlowFile flowFile1 = session.create();
try {
// guarantee the FlowFile entryDate for flowFile2 is different than flowFile1
Thread.sleep(2);
} catch (final InterruptedException e) {
}
final MockFlowFile flowFile2 = session.create();
final OldestFlowFileFirstPrioritizer prioritizer = new OldestFlowFileFirstPrioritizer();
Assert.assertEquals(0, prioritizer.compare(null, null));
Assert.assertEquals(-1, prioritizer.compare(flowFile1, null));
Assert.assertEquals(1, prioritizer.compare(null, flowFile1));
Assert.assertEquals(0, prioritizer.compare(flowFile1, flowFile1));
Assert.assertEquals(0, prioritizer.compare(flowFile2, flowFile2));
Assert.assertEquals(-1, prioritizer.compare(flowFile1, flowFile2));
Assert.assertEquals(1, prioritizer.compare(flowFile2, flowFile1));
}
use of org.apache.nifi.processor.Processor 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.processor.Processor in project nifi by apache.
the class TestConnectableTask method testIsWorkToDo.
@Test
public void testIsWorkToDo() {
final ProcessorNode procNode = Mockito.mock(ProcessorNode.class);
Mockito.when(procNode.hasIncomingConnection()).thenReturn(false);
final Processor processor = Mockito.mock(Processor.class);
Mockito.when(procNode.getIdentifier()).thenReturn("123");
Mockito.when(procNode.getRunnableComponent()).thenReturn(processor);
final FlowController flowController = Mockito.mock(FlowController.class);
Mockito.when(flowController.getStateManagerProvider()).thenReturn(Mockito.mock(StateManagerProvider.class));
final RepositoryContext repoContext = Mockito.mock(RepositoryContext.class);
Mockito.when(repoContext.getFlowFileEventRepository()).thenReturn(Mockito.mock(FlowFileEventRepository.class));
final RepositoryContextFactory contextFactory = Mockito.mock(RepositoryContextFactory.class);
Mockito.when(contextFactory.newProcessContext(Mockito.any(Connectable.class), Mockito.any(AtomicLong.class))).thenReturn(repoContext);
final LifecycleState scheduleState = new LifecycleState();
final StringEncryptor encryptor = Mockito.mock(StringEncryptor.class);
ConnectableTask task = new ConnectableTask(Mockito.mock(SchedulingAgent.class), procNode, flowController, contextFactory, scheduleState, encryptor);
// There is work to do because there are no incoming connections.
assertFalse(task.invoke().isYield());
// Test with only a single connection that is self-looping and empty
final Connection selfLoopingConnection = Mockito.mock(Connection.class);
when(selfLoopingConnection.getSource()).thenReturn(procNode);
when(selfLoopingConnection.getDestination()).thenReturn(procNode);
when(procNode.hasIncomingConnection()).thenReturn(true);
when(procNode.getIncomingConnections()).thenReturn(Collections.singletonList(selfLoopingConnection));
assertFalse(task.invoke().isYield());
// Test with only a single connection that is self-looping and empty
final FlowFileQueue flowFileQueue = Mockito.mock(FlowFileQueue.class);
when(flowFileQueue.isActiveQueueEmpty()).thenReturn(true);
final FlowFileQueue nonEmptyQueue = Mockito.mock(FlowFileQueue.class);
when(nonEmptyQueue.isActiveQueueEmpty()).thenReturn(false);
when(selfLoopingConnection.getFlowFileQueue()).thenReturn(nonEmptyQueue);
assertFalse(task.invoke().isYield());
// Test with only a non-looping Connection that has no FlowFiles
final Connection emptyConnection = Mockito.mock(Connection.class);
when(emptyConnection.getSource()).thenReturn(Mockito.mock(ProcessorNode.class));
when(emptyConnection.getDestination()).thenReturn(procNode);
when(emptyConnection.getFlowFileQueue()).thenReturn(flowFileQueue);
when(procNode.getIncomingConnections()).thenReturn(Collections.singletonList(emptyConnection));
// Create a new ConnectableTask because we want to have a different value for the 'hasNonLoopConnection' value, which is calculated in the task's constructor.
task = new ConnectableTask(Mockito.mock(SchedulingAgent.class), procNode, flowController, contextFactory, scheduleState, encryptor);
assertTrue(task.invoke().isYield());
// test when the queue has data
final Connection nonEmptyConnection = Mockito.mock(Connection.class);
when(nonEmptyConnection.getSource()).thenReturn(Mockito.mock(ProcessorNode.class));
when(nonEmptyConnection.getDestination()).thenReturn(procNode);
when(nonEmptyConnection.getFlowFileQueue()).thenReturn(nonEmptyQueue);
when(procNode.getIncomingConnections()).thenReturn(Collections.singletonList(nonEmptyConnection));
assertFalse(task.invoke().isYield());
}
Aggregations