You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jp...@apache.org on 2016/12/19 20:48:54 UTC
[6/6] nifi git commit: NIFI-3188: Added unit test to test corner cases
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/986e7160
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/986e7160
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/986e7160
Branch: refs/heads/support/nifi-1.1.x
Commit: 986e716091ade2dec29de579f8be4aa4df0efc4c
Parents: 9153fca
Author: Mark Payne <ma...@hotmail.com>
Authored: Mon Dec 12 15:23:40 2016 -0500
Committer: jpercivall <JP...@apache.org>
Committed: Mon Dec 19 15:25:35 2016 -0500
----------------------------------------------------------------------
.../stream/io/util/StreamDemarcatorTest.java | 34 ++++++++++++++++++++
1 file changed, 34 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/986e7160/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);