Skip to content

Commit

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

(cherry picked from commit 8c7c978)
(cherry picked from commit c74eec7)
  • Loading branch information
Technoboy- authored and srinath-ctds committed Apr 23, 2024
1 parent 8035e66 commit ec47aa7
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 ec47aa7

Please sign in to comment.