File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
logstash-core/src/test/java/org/logstash/common Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 2626import java .util .List ;
2727
2828import static org .hamcrest .MatcherAssert .assertThat ;
29- import static org .hamcrest .Matchers .containsString ;
29+ import static org .hamcrest .Matchers .* ;
3030import static org .junit .Assert .assertEquals ;
3131import static org .junit .Assert .assertThrows ;
3232import static org .logstash .common .BufferedTokenizerTest .toList ;
@@ -128,4 +128,26 @@ public void givenFragmentThatHasTheSecondTokenOverrunsSizeLimitThenAnErrorIsThro
128128 // third token resumes
129129 assertEquals ("ccc" , tokensIterator .next ());
130130 }
131+
132+ @ Test
133+ public void givenSequenceOfFragmentsWithoutSeparatorThenDoesntGenerateOutOfMemory () {
134+ final String neverEndingData = generate (8 , "a" );
135+ for (int i = 0 ; i < 10 ; i ++) {
136+ sut .extract (neverEndingData );
137+ }
138+
139+ assertThat ("Accumulator include only a part of an exploding payload" , sut .flush ().length (), is (lessThan (10 )));
140+
141+ Iterable <String > tokensIterable = sut .extract ("\n bbb\n " );
142+ Iterator <String > tokensIterator = tokensIterable .iterator ();
143+ // send a token delimiter and check an error is raised
144+ Exception exception = assertThrows (IllegalStateException .class , () -> {
145+ tokensIterator .next ();
146+ });
147+ assertThat (exception .getMessage (), containsString ("input buffer full" ));
148+ }
149+
150+ private static String generate (int length , String fillChar ) {
151+ return fillChar .repeat (length );
152+ }
131153}
You can’t perform that action at this time.
0 commit comments