NIFI-3188: Added unit test to test corner cases

This closes #1321.

Signed-off-by: Koji Kawamura <ijokarumawak@apache.org>
This commit is contained in:
Mark Payne 2016-12-12 15:23:40 -05:00 committed by Koji Kawamura
parent 266bd80bde
commit e59cf86656
1 changed files with 34 additions and 0 deletions

View File

@ -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);