Skip to content

Commit

Permalink
Fix flaky test ConsumedLedgersTrimTest.testConsumedLedgersTrimNoSubsc…
Browse files Browse the repository at this point in the history
…riptions (apache#9420)

Fixes apache#9409
### Motivation
After restarting, it takes time to load the topic, and this admin api will throw an exception when the topic cannot be queried.
This problem can easily be triggered when this unit test is called in a loop. Therefore, I added a judgment to determine whether the topic is loaded. After that, I called it 100 times in a loop and no exception was seen.
  • Loading branch information
315157973 authored Feb 5, 2021
1 parent 31ee454 commit ca8a23f
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import lombok.Cleanup;
Expand All @@ -31,6 +33,7 @@
import org.apache.pulsar.client.api.Message;
import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.client.api.Producer;
import org.awaitility.Awaitility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
Expand Down Expand Up @@ -142,6 +145,8 @@ public void testConsumedLedgersTrimNoSubscriptions() throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
Awaitility.await().ignoreExceptions().untilAsserted(()
-> assertNotNull(pulsar.getBrokerService().getTopicIfExists(topicName).get(3, TimeUnit.SECONDS).get()));
pulsar.getAdminClient().topics().getStats(topicName);
MessageId messageIdAfterRestart = pulsar.getAdminClient().topics().getLastMessageId(topicName);
LOG.info("lastmessageid " + messageIdAfterRestart);
Expand Down

0 comments on commit ca8a23f

Please sign in to comment.