Search in sources :

Example 41 with FlowFile

use of org.apache.nifi.flowfile.FlowFile in project nifi by apache.

the class TestStandardProcessSession method testContentModifiedEmittedAndNotAttributesModified.

@Test
public void testContentModifiedEmittedAndNotAttributesModified() throws IOException {
    final FlowFileRecord flowFile = new StandardFlowFileRecord.Builder().id(1L).addAttribute("uuid", "000000000000-0000-0000-0000-00000000").build();
    this.flowFileQueue.put(flowFile);
    FlowFile existingFlowFile = session.get();
    existingFlowFile = session.write(existingFlowFile, new OutputStreamCallback() {

        @Override
        public void process(OutputStream out) throws IOException {
        }
    });
    existingFlowFile = session.putAttribute(existingFlowFile, "attr", "a");
    session.transfer(existingFlowFile, new Relationship.Builder().name("A").build());
    session.commit();
    final List<ProvenanceEventRecord> events = provenanceRepo.getEvents(0L, 10000);
    assertFalse(events.isEmpty());
    assertEquals(1, events.size());
    final ProvenanceEventRecord event = events.get(0);
    assertEquals(ProvenanceEventType.CONTENT_MODIFIED, event.getEventType());
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) FilterOutputStream(java.io.FilterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Relationship(org.apache.nifi.processor.Relationship) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) OutputStreamCallback(org.apache.nifi.processor.io.OutputStreamCallback) Test(org.junit.Test)

Example 42 with FlowFile

use of org.apache.nifi.flowfile.FlowFile in project nifi by apache.

the class TestStandardProcessSession method testReadFromInputStreamWhileWriting.

@Test
public void testReadFromInputStreamWhileWriting() throws IOException {
    final FlowFileRecord flowFileRecord = new StandardFlowFileRecord.Builder().addAttribute("uuid", "12345678-1234-1234-1234-123456789012").entryDate(System.currentTimeMillis()).size(12L).build();
    flowFileQueue.put(flowFileRecord);
    final FlowFile flowFile = session.get();
    OutputStream out = session.write(flowFile);
    try {
        session.read(flowFile);
        Assert.fail("Was able to obtain an InputStream for a FlowFile while also holding an OutputStream for it");
    } catch (final IllegalStateException e) {
    // expected
    } finally {
        out.close();
    }
    // Should now be okay
    try (final InputStream in = session.read(flowFile)) {
    }
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FilterOutputStream(java.io.FilterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test)

Example 43 with FlowFile

use of org.apache.nifi.flowfile.FlowFile in project nifi by apache.

the class TestStandardProcessSession method testContentModifiedNotEmittedForCreate.

@Test
public void testContentModifiedNotEmittedForCreate() throws IOException {
    FlowFile newFlowFile = session.create();
    newFlowFile = session.write(newFlowFile, new OutputStreamCallback() {

        @Override
        public void process(OutputStream out) throws IOException {
        }
    });
    session.transfer(newFlowFile, new Relationship.Builder().name("A").build());
    session.commit();
    final List<ProvenanceEventRecord> events = provenanceRepo.getEvents(0L, 10000);
    assertFalse(events.isEmpty());
    assertEquals(1, events.size());
    final ProvenanceEventRecord event = events.get(0);
    assertEquals(ProvenanceEventType.CREATE, event.getEventType());
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) FilterOutputStream(java.io.FilterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Relationship(org.apache.nifi.processor.Relationship) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) OutputStreamCallback(org.apache.nifi.processor.io.OutputStreamCallback) Test(org.junit.Test)

Example 44 with FlowFile

use of org.apache.nifi.flowfile.FlowFile in project nifi by apache.

the class TestStandardProcessSession method testRoundRobinAcrossConnectionsOnSessionGetWithCount.

@Test
@SuppressWarnings("unchecked")
public void testRoundRobinAcrossConnectionsOnSessionGetWithCount() {
    final AtomicReference<FlowFileQueue> queue1Reference = new AtomicReference<>();
    final AtomicReference<FlowFileQueue> queue2Reference = new AtomicReference<>();
    final List<Connection> connList = new ArrayList<>();
    final Connection conn1 = createConnection(queue1Reference);
    final Connection conn2 = createConnection(queue2Reference);
    connList.add(conn1);
    connList.add(conn2);
    final FlowFileQueue queue2 = queue2Reference.get();
    final FlowFileRecord flowFileRecord = new StandardFlowFileRecord.Builder().id(1000L).addAttribute("uuid", "12345678-1234-1234-1234-123456789012").entryDate(System.currentTimeMillis()).build();
    queue2.put(flowFileRecord);
    when(connectable.getIncomingConnections()).thenReturn(connList);
    List<FlowFile> result = session.get(2);
    assertEquals(1, result.size());
    verify(conn1, times(1)).poll(any(FlowFileFilter.class), any(Set.class));
    verify(conn2, times(1)).poll(any(FlowFileFilter.class), any(Set.class));
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) Set(java.util.Set) HashSet(java.util.HashSet) Connection(org.apache.nifi.connectable.Connection) ArrayList(java.util.ArrayList) FlowFileFilter(org.apache.nifi.processor.FlowFileFilter) AtomicReference(java.util.concurrent.atomic.AtomicReference) StandardFlowFileQueue(org.apache.nifi.controller.StandardFlowFileQueue) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) Test(org.junit.Test)

Example 45 with FlowFile

use of org.apache.nifi.flowfile.FlowFile in project nifi by apache.

the class TestStandardProcessSession method testCreateEmitted.

@Test
public void testCreateEmitted() throws IOException {
    final FlowFile newFlowFile = session.create();
    session.transfer(newFlowFile, new Relationship.Builder().name("A").build());
    session.commit();
    final List<ProvenanceEventRecord> events = provenanceRepo.getEvents(0L, 10000);
    assertFalse(events.isEmpty());
    assertEquals(1, events.size());
    final ProvenanceEventRecord event = events.get(0);
    assertEquals(ProvenanceEventType.CREATE, event.getEventType());
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) MockFlowFile(org.apache.nifi.util.MockFlowFile) Relationship(org.apache.nifi.processor.Relationship) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) Test(org.junit.Test)

Aggregations

FlowFile (org.apache.nifi.flowfile.FlowFile)500 IOException (java.io.IOException)236 ProcessException (org.apache.nifi.processor.exception.ProcessException)193 HashMap (java.util.HashMap)160 InputStream (java.io.InputStream)145 OutputStream (java.io.OutputStream)131 ComponentLog (org.apache.nifi.logging.ComponentLog)119 Test (org.junit.Test)116 ArrayList (java.util.ArrayList)113 Map (java.util.Map)105 MockFlowFile (org.apache.nifi.util.MockFlowFile)103 ProcessSession (org.apache.nifi.processor.ProcessSession)99 OutputStreamCallback (org.apache.nifi.processor.io.OutputStreamCallback)83 Relationship (org.apache.nifi.processor.Relationship)78 InputStreamCallback (org.apache.nifi.processor.io.InputStreamCallback)78 HashSet (java.util.HashSet)75 List (java.util.List)67 StopWatch (org.apache.nifi.util.StopWatch)59 Set (java.util.Set)56 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)55