You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ij...@apache.org on 2016/12/14 01:58:02 UTC
nifi git commit: NIFI-3188: Added unit test to test corner cases
Repository: nifi
Updated Branches:
refs/heads/master 266bd80bd -> e59cf8665
NIFI-3188: Added unit test to test corner cases
This closes #1321.
Signed-off-by: Koji Kawamura <ij...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/e59cf866
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/e59cf866
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/e59cf866
Branch: refs/heads/master
Commit: e59cf8665660507e3e53edbc480b76be48595a62
Parents: 266bd80
Author: Mark Payne <ma...@hotmail.com>
Authored: Mon Dec 12 15:23:40 2016 -0500
Committer: Koji Kawamura <ij...@apache.org>
Committed: Wed Dec 14 10:57:11 2016 +0900
----------------------------------------------------------------------
.../stream/io/util/StreamDemarcatorTest.java | 34 ++++++++++++++++++++
1 file changed, 34 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/e59cf866/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/StreamDemarcatorTest.java
----------------------------------------------------------------------
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 66d2668..cfac6de 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
@@ -257,6 +257,40 @@ public class StreamDemarcatorTest {
}
@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);
ByteArrayInputStream is = new ByteArrayInputStream(inputData);