Skip to content

Commit 7801b53

Browse files
committed
[Test] added test to verify buffer full error is notified not only on the first token
1 parent 72c2d61 commit 7801b53

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

logstash-core/src/test/java/org/logstash/common/BufferedTokenizerWithSizeLimitTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.junit.Before;
2323
import org.junit.Test;
2424

25+
import java.util.Iterator;
2526
import java.util.List;
2627

2728
import static org.hamcrest.MatcherAssert.assertThat;
@@ -109,4 +110,22 @@ public void giveMultipleSegmentsThatGeneratesMultipleBufferFullErrorsThenIsAbleT
109110
List<String> tokens = toList(sut.extract("ccc\nddd\n"));
110111
assertEquals(List.of("ccccc", "ddd"), tokens);
111112
}
113+
114+
@Test
115+
public void givenFragmentThatHasTheSecondTokenOverrunsSizeLimitThenAnErrorIsThrown() {
116+
Iterable<String> tokensIterable = sut.extract("aaaa\nbbbbbbbbbbb\nccc\n");
117+
Iterator<String> tokensIterator = tokensIterable.iterator();
118+
119+
// first token length = 4, it's ok
120+
assertEquals("aaaa", tokensIterator.next());
121+
122+
// second token is an overrun, length = 11
123+
Exception exception = assertThrows(IllegalStateException.class, () -> {
124+
tokensIterator.next();
125+
});
126+
assertThat(exception.getMessage(), containsString("input buffer full"));
127+
128+
// third token resumes
129+
assertEquals("ccc", tokensIterator.next());
130+
}
112131
}

0 commit comments

Comments
 (0)