RobertIndie commented on code in PR #15144:
URL: https://github.com/apache/pulsar/pull/15144#discussion_r849292346
##########
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ZeroQueueSizeTest.java:
##########
@@ -305,17 +306,23 @@ public void testFailedZeroQueueSizeBatchMessage() throws
PulsarClientException {
producer.send(message.getBytes());
}
- try {
- consumer.receiveAsync().handle((ok, e) -> {
- if (e == null) {
- // as zero receiverQueueSize doesn't support batch
message, must receive exception at callback.
- Assert.fail();
- }
- return null;
- });
- } finally {
- consumer.close();
- }
+ AtomicReference<Throwable> exceptionRef = new AtomicReference<>();
+
+ consumer.receiveAsync().handle((ok, e) -> {
+ // as zero receiverQueueSize doesn't support batch message, must
receive exception at callback.
+ exceptionRef.set(e);
+ return null;
+ });
+ Awaitility.await().untilAsserted(() ->
assertNotNull(exceptionRef.get()));
+ Awaitility.await().untilAsserted(() ->
assertEquals(exceptionRef.get().getClass(),
+ PulsarClientException.InvalidMessageException.class));
+ Awaitility.await().untilAsserted(() ->
assertEquals(exceptionRef.get().getMessage(),
+ String.format("Unsupported Batch message with 0 size receiver
queue for [%s]-[%s] ",
+ consumer.getSubscription(),
consumer.getConsumerName())));
+ // zeroConsumerImpl will close when received batch message.
+ Assert.assertFalse(consumer.isConnected());
Review Comment:
Maybe we should use await untilAsserted here. Because calling the callback
and closing the consumer is not synchronous
##########
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ZeroQueueSizeTest.java:
##########
@@ -305,17 +306,23 @@ public void testFailedZeroQueueSizeBatchMessage() throws
PulsarClientException {
producer.send(message.getBytes());
}
- try {
- consumer.receiveAsync().handle((ok, e) -> {
- if (e == null) {
- // as zero receiverQueueSize doesn't support batch
message, must receive exception at callback.
- Assert.fail();
- }
- return null;
- });
- } finally {
- consumer.close();
- }
+ AtomicReference<Throwable> exceptionRef = new AtomicReference<>();
+
+ consumer.receiveAsync().handle((ok, e) -> {
+ // as zero receiverQueueSize doesn't support batch message, must
receive exception at callback.
+ exceptionRef.set(e);
+ return null;
+ });
+ Awaitility.await().untilAsserted(() ->
assertNotNull(exceptionRef.get()));
+ Awaitility.await().untilAsserted(() ->
assertEquals(exceptionRef.get().getClass(),
+ PulsarClientException.InvalidMessageException.class));
+ Awaitility.await().untilAsserted(() ->
assertEquals(exceptionRef.get().getMessage(),
Review Comment:
I think we don't need to await unitlAsserted here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]