mirror of https://github.com/apache/nifi.git
NIFI-2851: Added additional unit test to ensure correctness of demarcation when demarcator falls between buffered data
This closes #1116.
This commit is contained in:
parent
41f519e84c
commit
ad92474593
|
@ -18,11 +18,13 @@ package org.apache.nifi.stream.io.util;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
@ -236,6 +238,28 @@ public class TextLineDemarcatorTest {
|
||||||
assertTrue(offsetInfo.isStartsWithMatch());
|
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) {
|
private InputStream stringToIs(String data) {
|
||||||
return new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
|
return new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue