Skip to content

Commit

Permalink
[fix][test] Fix flaky test BrokerServiceAutoSubscriptionCreationTest (#…
Browse files Browse the repository at this point in the history
…22190)

(cherry picked from commit 8c7c978)
  • Loading branch information
Technoboy- authored and lhotari committed Mar 28, 2024
1 parent e3531e8 commit c74eec7
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride;
import org.awaitility.Awaitility;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
Expand Down Expand Up @@ -159,15 +160,19 @@ public void testDynamicConfigurationTopicAutoSubscriptionCreation()
throws PulsarAdminException, PulsarClientException {
pulsar.getConfiguration().setAllowAutoTopicCreation(false);
pulsar.getConfiguration().setAllowAutoSubscriptionCreation(true);
admin.brokers().updateDynamicConfiguration("allowAutoSubscriptionCreation", "false");
String allowAutoSubscriptionCreation = "allowAutoSubscriptionCreation";
admin.brokers().updateDynamicConfiguration(allowAutoSubscriptionCreation, "false");
String topicString = "persistent://prop/ns-abc/non-partitioned-topic" + UUID.randomUUID();
String subscriptionName = "non-partitioned-topic-sub";
admin.topics().createNonPartitionedTopic(topicString);
Assert.assertThrows(PulsarClientException.class,
()-> pulsarClient.newConsumer().topic(topicString).subscriptionName(subscriptionName).subscribe());
admin.brokers().updateDynamicConfiguration("allowAutoSubscriptionCreation", "true");
pulsarClient.newConsumer().topic(topicString).subscriptionName(subscriptionName).subscribe();
assertTrue(admin.topics().getSubscriptions(topicString).contains(subscriptionName));
admin.brokers().updateDynamicConfiguration(allowAutoSubscriptionCreation, "true");
Awaitility.await().untilAsserted(() -> {
Assert.assertEquals(admin.brokers().getAllDynamicConfigurations().get(allowAutoSubscriptionCreation), "true");
pulsarClient.newConsumer().topic(topicString).subscriptionName(subscriptionName).subscribe();
assertTrue(admin.topics().getSubscriptions(topicString).contains(subscriptionName));
});
}

}

0 comments on commit c74eec7

Please sign in to comment.