From e59cf8665660507e3e53edbc480b76be48595a62 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Mon, 12 Dec 2016 15:23:40 -0500 Subject: [PATCH] NIFI-3188: Added unit test to test corner cases This closes #1321. Signed-off-by: Koji Kawamura --- .../stream/io/util/StreamDemarcatorTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/StreamDemarcatorTest.java b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/StreamDemarcatorTest.java index 66d266848a..cfac6de40f 100644 --- a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/StreamDemarcatorTest.java +++ b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/StreamDemarcatorTest.java @@ -256,6 +256,40 @@ public class StreamDemarcatorTest { assertArrayEquals(second, new byte[] {'N', 'o'}); } + @Test + public void testOnBufferCorners() throws IOException { + byte[] inputData = "YesDEMARCATORNo".getBytes(StandardCharsets.UTF_8); + final int[] initialLengths = new int[] {1, 2, 12, 13, 14, 15, 16, 25}; + + for (final int initialBufferLength : initialLengths) { + ByteArrayInputStream is = new ByteArrayInputStream(inputData); + StreamDemarcator scanner = new StreamDemarcator(is, "DEMARCATOR".getBytes(), 1000, initialBufferLength); + + final byte[] first = scanner.nextToken(); + final byte[] second = scanner.nextToken(); + assertNotNull(first); + assertNotNull(second); + + assertArrayEquals(new byte[] {'Y', 'e', 's'}, first); + assertArrayEquals(new byte[] {'N', 'o'}, second); + } + + inputData = "NoDEMARCATORYes".getBytes(StandardCharsets.UTF_8); + for (final int initialBufferLength : initialLengths) { + ByteArrayInputStream is = new ByteArrayInputStream(inputData); + StreamDemarcator scanner = new StreamDemarcator(is, "DEMARCATOR".getBytes(), 1000, initialBufferLength); + + final byte[] first = scanner.nextToken(); + final byte[] second = scanner.nextToken(); + assertNotNull(first); + assertNotNull(second); + + assertArrayEquals(new byte[] {'N', 'o'}, first); + assertArrayEquals(new byte[] {'Y', 'e', 's'}, second); + } + } + + @Test public void testOnBufferSplit() throws IOException { final byte[] inputData = "123\n456\n789".getBytes(StandardCharsets.UTF_8);