Check that the queueSize is a positive integer

This commit is contained in:
Marius Bogoevici
2015-05-31 08:48:27 -04:00
committed by Artem Bilan
parent 1b28a7b863
commit d0c0adc5bb
2 changed files with 11 additions and 2 deletions

View File

@@ -245,11 +245,11 @@ public class KafkaMessageListenerContainer implements SmartLifecycle {
/**
* The maximum number of messages that are buffered by each concurrent {@link MessageListener} runner.
* Increasing the value may increase throughput, but also increases the memory consumption.
* Must be a power of 2.
* Must be a positive number and a power of 2.
* @param queueSize the queue size
*/
public void setQueueSize(int queueSize) {
Assert.isTrue(Integer.bitCount(queueSize) == 1, "'queueSize' must be a power of 2");
Assert.isTrue(queueSize > 0 && Integer.bitCount(queueSize) == 1, "'queueSize' must be a positive number and a power of 2");
this.queueSize = queueSize;
}

View File

@@ -89,6 +89,15 @@ public class KafkaMessageDrivenChannelAdapterTests extends AbstractMessageListen
catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("power of 2"));
}
try {
kafkaMessageListenerContainer.setQueueSize(Integer.MIN_VALUE);
fail("expected exception");
}
catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("positive number"));
}
kafkaMessageListenerContainer.setQueueSize(1024);
int expectedMessageCount = 100;