From ad924745933c3e018e0d78282d9d085978b8cd2b Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Fri, 11 Nov 2016 15:03:44 -0500 Subject: [PATCH] NIFI-2851: Added additional unit test to ensure correctness of demarcation when demarcator falls between buffered data This closes #1116. --- .../io/util/TextLineDemarcatorTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TextLineDemarcatorTest.java b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TextLineDemarcatorTest.java index 3b64a17794..ce66cad06a 100644 --- a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TextLineDemarcatorTest.java +++ b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TextLineDemarcatorTest.java @@ -18,11 +18,13 @@ package org.apache.nifi.stream.io.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -236,6 +238,28 @@ public class TextLineDemarcatorTest { assertTrue(offsetInfo.isStartsWithMatch()); } + @Test + public void testOnBufferSplitNoTrailingDelimiter() throws IOException { + final byte[] inputData = "Yes\nNo".getBytes(StandardCharsets.UTF_8); + final ByteArrayInputStream is = new ByteArrayInputStream(inputData); + final TextLineDemarcator demarcator = new TextLineDemarcator(is, 3); + + final OffsetInfo first = demarcator.nextOffsetInfo(); + final OffsetInfo second = demarcator.nextOffsetInfo(); + final OffsetInfo third = demarcator.nextOffsetInfo(); + assertNotNull(first); + assertNotNull(second); + assertNull(third); + + assertEquals(0, first.getStartOffset()); + assertEquals(4, first.getLength()); + assertEquals(1, first.getCrlfLength()); + + assertEquals(4, second.getStartOffset()); + assertEquals(2, second.getLength()); + assertEquals(0, second.getCrlfLength()); + } + private InputStream stringToIs(String data) { return new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); }