use of org.apache.nifi.processor.Processor in project nifi by apache.
the class TestStandardRemoteGroupPort method setupMockProcessSession.
private void setupMockProcessSession() {
// Construct a RemoteGroupPort as a processor to use NiFi mock library.
final Processor remoteGroupPort = mock(Processor.class);
final Set<Relationship> relationships = new HashSet<>();
relationships.add(Relationship.ANONYMOUS);
when(remoteGroupPort.getRelationships()).thenReturn(relationships);
when(remoteGroupPort.getIdentifier()).thenReturn("remote-group-port-id");
sessionState = new SharedSessionState(remoteGroupPort, new AtomicLong(0));
processSession = new MockProcessSession(sessionState, remoteGroupPort);
processContext = new MockProcessContext(remoteGroupPort);
}
use of org.apache.nifi.processor.Processor in project nifi by apache.
the class PriorityAttributePrioritizerTest 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 ffNoPriority = session.create();
final MockFlowFile ffPri1 = session.create();
ffPri1.putAttributes(attrsPri1);
final MockFlowFile ffPri2 = session.create();
ffPri2.putAttributes(attrsPri2);
final MockFlowFile ffPrin1 = session.create();
ffPrin1.putAttributes(attrsPrin1);
final MockFlowFile ffPriA = session.create();
ffPriA.putAttributes(attrsPriA);
final MockFlowFile ffPriB = session.create();
ffPriB.putAttributes(attrsPriB);
final MockFlowFile ffPriLP = session.create();
ffPriLP.putAttributes(attrsPriLP);
final MockFlowFile ffPriLN = session.create();
ffPriLN.putAttributes(attrsPriLN);
final PriorityAttributePrioritizer prioritizer = new PriorityAttributePrioritizer();
assertEquals(0, prioritizer.compare(null, null));
assertEquals(-1, prioritizer.compare(ffNoPriority, null));
assertEquals(1, prioritizer.compare(null, ffNoPriority));
assertEquals(0, prioritizer.compare(ffNoPriority, ffNoPriority));
assertEquals(-1, prioritizer.compare(ffPri1, ffNoPriority));
assertEquals(1, prioritizer.compare(ffNoPriority, ffPri1));
assertEquals(0, prioritizer.compare(ffPri1, ffPri1));
assertEquals(-1, prioritizer.compare(ffPri1, ffPri2));
assertEquals(1, prioritizer.compare(ffPri2, ffPri1));
assertEquals(-1, prioritizer.compare(ffPrin1, ffPri1));
assertEquals(1, prioritizer.compare(ffPri1, ffPrin1));
assertEquals(-1, prioritizer.compare(ffPri1, ffPriA));
assertEquals(1, prioritizer.compare(ffPriA, ffPri1));
assertEquals(0, prioritizer.compare(ffPriA, ffPriA));
assertEquals(-1, prioritizer.compare(ffPriA, ffPriB));
assertEquals(1, prioritizer.compare(ffPriB, ffPriA));
assertEquals(1, prioritizer.compare(ffPriLP, ffPri1));
assertEquals(-1, prioritizer.compare(ffPri1, ffPriLP));
assertEquals(-1, prioritizer.compare(ffPriLN, ffPri1));
assertEquals(1, prioritizer.compare(ffPri1, ffPriLN));
}
use of org.apache.nifi.processor.Processor in project nifi by apache.
the class TestMockProcessSession method testReadWithoutCloseThrowsExceptionOnCommit.
@Test
public void testReadWithoutCloseThrowsExceptionOnCommit() throws IOException {
final Processor processor = new PoorlyBehavedProcessor();
final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, new AtomicLong(0L)), processor);
FlowFile flowFile = session.createFlowFile("hello, world".getBytes());
final InputStream in = session.read(flowFile);
final byte[] buffer = new byte[12];
StreamUtils.fillBuffer(in, buffer);
assertEquals("hello, world", new String(buffer));
session.remove(flowFile);
try {
session.commit();
Assert.fail("Was able to commit session without closing InputStream");
} catch (final FlowFileHandlingException ffhe) {
System.out.println(ffhe.toString());
}
}
use of org.apache.nifi.processor.Processor in project nifi by apache.
the class TestMockProcessSession method testTransferUnknownRelationship.
@Test
public void testTransferUnknownRelationship() {
final Processor processor = new PoorlyBehavedProcessor();
final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, new AtomicLong(0L)), processor);
FlowFile ff1 = session.createFlowFile("hello, world".getBytes());
final Relationship fakeRel = new Relationship.Builder().name("FAKE").build();
try {
session.transfer(ff1, fakeRel);
Assert.fail("Should have thrown IllegalArgumentException");
} catch (final IllegalArgumentException ie) {
}
try {
session.transfer(Collections.singleton(ff1), fakeRel);
Assert.fail("Should have thrown IllegalArgumentException");
} catch (final IllegalArgumentException ie) {
}
}
use of org.apache.nifi.processor.Processor in project nifi by apache.
the class InvokeScriptedProcessor method getSupportedPropertyDescriptors.
/**
* Returns a list of property descriptors supported by this processor. The
* list always includes properties such as script engine name, script file
* name, script body name, script arguments, and an external module path. If
* the scripted processor also defines supported properties, those are added
* to the list as well.
*
* @return a List of PropertyDescriptor objects supported by this processor
*/
@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
synchronized (scriptingComponentHelper.isInitialized) {
if (!scriptingComponentHelper.isInitialized.get()) {
scriptingComponentHelper.createResources();
}
}
List<PropertyDescriptor> supportedPropertyDescriptors = new ArrayList<>();
supportedPropertyDescriptors.addAll(scriptingComponentHelper.getDescriptors());
final Processor instance = processor.get();
if (instance != null) {
try {
final List<PropertyDescriptor> instanceDescriptors = instance.getPropertyDescriptors();
if (instanceDescriptors != null) {
supportedPropertyDescriptors.addAll(instanceDescriptors);
}
} catch (final Throwable t) {
final ComponentLog logger = getLogger();
final String message = "Unable to get property descriptors from Processor: " + t;
logger.error(message);
if (logger.isDebugEnabled()) {
logger.error(message, t);
}
}
}
return Collections.unmodifiableList(supportedPropertyDescriptors);
}
Aggregations