mirror of https://github.com/apache/nifi.git
NIFI-5974 fix: Fragment Attributes are populated in case no split has occured.
Unit test is implemented: testNoSplitterInString NIFI-5974: Fixed Checkstyle violations Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes #3275
This commit is contained in:
parent
2eac0e96c7
commit
8e777203a0
|
@ -257,15 +257,14 @@ public class SplitContent extends AbstractProcessor {
|
||||||
});
|
});
|
||||||
|
|
||||||
long lastOffsetPlusSize = -1L;
|
long lastOffsetPlusSize = -1L;
|
||||||
|
final ArrayList<FlowFile> splitList = new ArrayList<>();
|
||||||
|
|
||||||
if (splits.isEmpty()) {
|
if (splits.isEmpty()) {
|
||||||
FlowFile clone = session.clone(flowFile);
|
FlowFile clone = session.clone(flowFile);
|
||||||
session.transfer(flowFile, REL_ORIGINAL);
|
// finishFragmentAttributes performs .clear() so List must be mutable
|
||||||
session.transfer(clone, REL_SPLITS);
|
splitList.add(clone);
|
||||||
logger.info("Found no match for {}; transferring original 'original' and transferring clone {} to 'splits'", new Object[]{flowFile, clone});
|
logger.info("Found no match for {}; transferring original 'original' and transferring clone {} to 'splits'", new Object[]{flowFile, clone});
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
final ArrayList<FlowFile> splitList = new ArrayList<>();
|
|
||||||
for (final Tuple<Long, Long> tuple : splits) {
|
for (final Tuple<Long, Long> tuple : splits) {
|
||||||
long offset = tuple.getKey();
|
long offset = tuple.getKey();
|
||||||
long size = tuple.getValue();
|
long size = tuple.getValue();
|
||||||
|
@ -288,6 +287,7 @@ public class SplitContent extends AbstractProcessor {
|
||||||
FlowFile finalSplit = session.clone(flowFile, finalSplitOffset, flowFile.getSize() - finalSplitOffset);
|
FlowFile finalSplit = session.clone(flowFile, finalSplitOffset, flowFile.getSize() - finalSplitOffset);
|
||||||
splitList.add(finalSplit);
|
splitList.add(finalSplit);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final String fragmentId = finishFragmentAttributes(session, flowFile, splitList);
|
final String fragmentId = finishFragmentAttributes(session, flowFile, splitList);
|
||||||
session.transfer(splitList, REL_SPLITS);
|
session.transfer(splitList, REL_SPLITS);
|
||||||
|
|
|
@ -27,6 +27,8 @@ import org.junit.Test;
|
||||||
|
|
||||||
import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_COUNT;
|
import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_COUNT;
|
||||||
import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_ID;
|
import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_ID;
|
||||||
|
import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_INDEX;
|
||||||
|
import static org.apache.nifi.processors.standard.SplitContent.SEGMENT_ORIGINAL_FILENAME;
|
||||||
|
|
||||||
public class TestSplitContent {
|
public class TestSplitContent {
|
||||||
|
|
||||||
|
@ -371,4 +373,31 @@ public class TestSplitContent {
|
||||||
final List<MockFlowFile> packed = mergeRunner.getFlowFilesForRelationship(MergeContent.REL_MERGED);
|
final List<MockFlowFile> packed = mergeRunner.getFlowFilesForRelationship(MergeContent.REL_MERGED);
|
||||||
packed.get(0).assertContentEquals(new byte[]{1, 2, 3, 4, 5, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 5, 4, 3, 2, 1});
|
packed.get(0).assertContentEquals(new byte[]{1, 2, 3, 4, 5, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 5, 4, 3, 2, 1});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoSplitterInString() {
|
||||||
|
|
||||||
|
String content = "UVAT";
|
||||||
|
|
||||||
|
final TestRunner runner = TestRunners.newTestRunner(new SplitContent());
|
||||||
|
runner.setProperty(SplitContent.FORMAT, SplitContent.UTF8_FORMAT.getValue());
|
||||||
|
runner.setProperty(SplitContent.BYTE_SEQUENCE, ",");
|
||||||
|
runner.setProperty(SplitContent.KEEP_SEQUENCE, "false");
|
||||||
|
runner.setProperty(SplitContent.BYTE_SEQUENCE_LOCATION, SplitContent.TRAILING_POSITION.getValue());
|
||||||
|
|
||||||
|
runner.enqueue(content.getBytes());
|
||||||
|
runner.run();
|
||||||
|
|
||||||
|
runner.assertTransferCount(SplitContent.REL_SPLITS, 1);
|
||||||
|
MockFlowFile splitResult = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS).get(0);
|
||||||
|
splitResult.assertAttributeExists(FRAGMENT_ID);
|
||||||
|
splitResult.assertAttributeExists(SEGMENT_ORIGINAL_FILENAME);
|
||||||
|
splitResult.assertAttributeEquals(FRAGMENT_COUNT, "1");
|
||||||
|
splitResult.assertAttributeEquals(FRAGMENT_INDEX, "1");
|
||||||
|
runner.assertTransferCount(SplitContent.REL_ORIGINAL, 1);
|
||||||
|
|
||||||
|
runner.assertQueueEmpty();
|
||||||
|
final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitContent.REL_SPLITS);
|
||||||
|
splits.get(0).assertContentEquals(content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue