Describe the bug
There are at least two inconsistencies about complying BatchReceivePolicy:
A. BatchReceivePolicy should supports maxNumberOfMessages = 0 and maxNumBytes = 0 if timeout is set but ConsumerBase's constructor issue a warning and reset to default BatchReceivePolicy in this case
B. MessageImpl.canAdd does not comply BatchReceivePolicy, allowing more than maxNumberOfMessages if maxSizeOfMessages is not reached
To Reproduce
A. 1. create a consumer providing BatchReceivePolicy.builder().maxNumMessages(0).maxNumBytes(0).timeout(100,TimeUnit.MILLISECONDS).build()
A. 2. see ConsumerBase's constructor log warning:
BatchReceivePolicy maxNumMessages: 0 or maxNumBytes: 0 is less than 0. Reset to DEFAULT_POLICY. batchReceivePolicy: [...]
B. 1. create a consumer providing BatchReceivePolicy.builder().maxNumMessages(1).maxNumBytes(10*1024*1024).timeout(0,null).build()
B. 2. consumer.batchReceive() may returns a Messages<T> with more than 1 message
Expected behavior
A. ConsumerBase should allow BatchReceivePolicy with maxNumberOfMessages and maxNumBytes set to 0 (or -1) if timeout is set
B. consumer.batchReceive() should comply maxNumberOfMessages and maxNumBytes (not or)
Additional context
In addition to those two issues, there may be an inconsistency between MessageImpl.canAdd and ConsumerBase.hasEnoughMessagesForBatchReceive. Not sure about this one but the code for policy compliance should not be spread among several `classes.```
Describe the bug
There are at least two inconsistencies about complying
BatchReceivePolicy:A.
BatchReceivePolicyshould supportsmaxNumberOfMessages = 0andmaxNumBytes = 0iftimeoutis set butConsumerBase's constructor issue a warning and reset to defaultBatchReceivePolicyin this caseB.
MessageImpl.canAdddoes not complyBatchReceivePolicy, allowing more thanmaxNumberOfMessagesifmaxSizeOfMessagesis not reachedTo Reproduce
A. 1. create a
consumerprovidingBatchReceivePolicy.builder().maxNumMessages(0).maxNumBytes(0).timeout(100,TimeUnit.MILLISECONDS).build()A. 2. see
ConsumerBase's constructor log warning:B. 1. create a
consumerprovidingBatchReceivePolicy.builder().maxNumMessages(1).maxNumBytes(10*1024*1024).timeout(0,null).build()B. 2.
consumer.batchReceive()may returns aMessages<T>with more than 1 messageExpected behavior
A.
ConsumerBaseshould allowBatchReceivePolicywithmaxNumberOfMessagesandmaxNumBytesset to0(or-1) iftimeoutis setB.
consumer.batchReceive()should complymaxNumberOfMessagesandmaxNumBytes(not or)Additional context
In addition to those two issues, there may be an inconsistency between
MessageImpl.canAddandConsumerBase.hasEnoughMessagesForBatchReceive. Not sure about this one but the code for policy compliance should not be spread among several `classes.```