validate bufferLimit is positive in HeapBufferedAsyncResponseConsumer

This commit is contained in:
javanna 2016-07-21 13:59:28 +02:00 committed by Luca Cavanna
parent 59ccc88c73
commit 175c327e17
2 changed files with 13 additions and 0 deletions

View File

@ -61,6 +61,9 @@ public class HeapBufferedAsyncResponseConsumer extends AbstractAsyncResponseCons
* Creates a new instance of this consumer with the provided buffer limit
*/
public HeapBufferedAsyncResponseConsumer(int bufferLimit) {
if (bufferLimit <= 0) {
throw new IllegalArgumentException("bufferLimit must be greater than 0");
}
this.bufferLimit = bufferLimit;
}

View File

@ -79,6 +79,16 @@ public class HeapBufferedAsyncResponseConsumerTests extends RestClientTestCase {
}
public void testConfiguredBufferLimit() throws Exception {
try {
new HeapBufferedAsyncResponseConsumer(randomIntBetween(Integer.MIN_VALUE, 0));
} catch(IllegalArgumentException e) {
assertEquals("bufferLimit must be greater than 0", e.getMessage());
}
try {
new HeapBufferedAsyncResponseConsumer(0);
} catch(IllegalArgumentException e) {
assertEquals("bufferLimit must be greater than 0", e.getMessage());
}
int bufferLimit = randomIntBetween(1, MAX_TEST_BUFFER_SIZE - 100);
HeapBufferedAsyncResponseConsumer consumer = new HeapBufferedAsyncResponseConsumer(bufferLimit);
bufferLimitTest(consumer, bufferLimit);