Skip to content

Commit eea9f37

Browse files
committed
[Test] Added test to verify the avoidance of infnite accumulation
1 parent cabd52c commit eea9f37

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.List;
2727

2828
import static org.hamcrest.MatcherAssert.assertThat;
29-
import static org.hamcrest.Matchers.containsString;
29+
import static org.hamcrest.Matchers.*;
3030
import static org.junit.Assert.assertEquals;
3131
import static org.junit.Assert.assertThrows;
3232
import 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("\nbbb\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
}

0 commit comments

Comments
 (0)