Skip to content

Commit

Permalink
[fix][test] Fix flaky test BrokerServiceAutoSubscriptionCreationTest (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
Technoboy- authored Mar 4, 2024
1 parent ccc2ea6 commit 8c7c978
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 8c7c978

Please sign in to comment.