validate bufferLimit is positive in HeapBufferedAsyncResponseConsumer
This commit is contained in:
parent
59ccc88c73
commit
175c327e17
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue