Fix flaky test testEnableAndDisableTopicDelayedDelivery
When admin.topics().getDelayedDeliveryPolicy(topicName) is executed, topicPolicies may not be initialized yet
This problem occurs when only a single unit test is executed.
When the entire unit test is executed, it rarely appears, because other unit tests initialize the TopicPolicies under this Namespace
@@ -44,6 +44,7 @@ import org.apache.pulsar.client.api.ProducerConsumerBase;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.api.Schema;
import org.apache.pulsar.client.api.SubscriptionType;
+import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies;
import org.awaitility.Awaitility;
import org.testng.Assert;
@@ -331,9 +332,12 @@ public class DelayedDeliveryTest extends ProducerConsumerBase {
@Test(timeOut = 20000)
public void testEnableAndDisableTopicDelayedDelivery() throws Exception {
- String topicName = "persistent://public/default/topic-" + UUID.randomUUID().toString();
+ String topicName = "persistent://public/default/topic-" + UUID.randomUUID();
admin.topics().createPartitionedTopic(topicName, 3);
+ pulsarClient.newProducer().topic(topicName).create().close();
+ Awaitility.await().untilAsserted(() -> pulsar.getTopicPoliciesService()
+ .cacheIsInitialized(TopicName.get(topicName)));
assertNull(admin.topics().getDelayedDeliveryPolicy(topicName));
DelayedDeliveryPolicies delayedDeliveryPolicies = DelayedDeliveryPolicies.builder()
.tickTime(2000)
@@ -367,6 +371,9 @@ public class DelayedDeliveryTest extends ProducerConsumerBase {
final String topicName = "persistent://public/default/test" + UUID.randomUUID().toString();
admin.topics().createPartitionedTopic(topicName, 3);
+ pulsarClient.newProducer().topic(topicName).create().close();
+ Awaitility.await().untilAsserted(() -> pulsar.getTopicPoliciesService()
+ .cacheIsInitialized(TopicName.get(topicName)));
assertNull(admin.topics().getDelayedDeliveryPolicy(topicName));
//1 Set topic policy
DelayedDeliveryPolicies delayedDeliveryPolicies = DelayedDeliveryPolicies.builder()
