Skip to content

Commit c2d6f85

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

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
@@ -23,6 +23,7 @@
2323
import org.junit.Before;
2424
import org.junit.Test;
2525

26+
import java.util.Iterator;
2627
import java.util.List;
2728

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

0 commit comments

Comments
 (0)