You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/07/01 14:56:34 UTC
[GitHub] [pulsar] gaoran10 commented on a change in pull request #11183: Fix the dead lock when using hasMessageAvailableAsync and readNextAsync
gaoran10 commented on a change in pull request #11183:
URL: https://github.com/apache/pulsar/pull/11183#discussion_r662364584
##########
File path: pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ReaderTest.java
##########
@@ -510,4 +514,44 @@ public void testSameSubName() throws Exception {
}
+ @Test(timeOut = 30000)
+ public void testAvoidUsingIoThreadToGetValueOfMessage() throws Exception {
+ final String topic = "persistent://my-property/my-ns/testAvoidUsingIoThreadToGetValueOfMessage";
+
+ @Cleanup
+ Producer<Schemas.PersonOne> producer = pulsarClient.newProducer(Schema.AVRO(Schemas.PersonOne.class))
+ .topic(topic)
+ .create();
+
+ producer.send(new Schemas.PersonOne(1));
+
+ @Cleanup
+ Reader<Schemas.PersonOne> reader = pulsarClient.newReader(Schema.AVRO(Schemas.PersonOne.class))
+ .topic(topic)
+ .startMessageId(MessageId.earliest)
+ .create();
+
+ CountDownLatch latch = new CountDownLatch(1);
+ List<Schemas.PersonOne> received = new ArrayList<>(1);
+ // Make sure the message is added to the incoming queue
+ Awaitility.await().untilAsserted(() ->
+ assertTrue(((ReaderImpl<?>) reader).getConsumer().incomingMessages.size() > 0));
+ reader.hasMessageAvailableAsync().whenComplete((has, e) -> {
+ if (e == null && has) {
+ CompletableFuture<Message<Schemas.PersonOne>> future = reader.readNextAsync();
+ // Make sure the future completed
+ Awaitility.await().pollInterval(1, TimeUnit.MILLISECONDS).untilAsserted(future::isDone);
Review comment:
Why need to wait for the future?
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org