This is an automated email from the ASF dual-hosted git repository.
bogong pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.9 by this push:
new dfa8db52972 [fix][flaky-test] Fix failed test
NonPersistentTopicE2ETest.testGCWillDeleteSchema (#16381)
dfa8db52972 is described below
commit dfa8db5297279f6fa617ee31bbfa26e3f1b28a0c
Author: lipenghui <[email protected]>
AuthorDate: Tue Jul 5 10:38:53 2022 +0800
[fix][flaky-test] Fix failed test
NonPersistentTopicE2ETest.testGCWillDeleteSchema (#16381)
(cherry picked from commit aabd5d020543210921f10648caf6720adc41d651)
---
.../broker/service/NonPersistentTopicE2ETest.java | 51 +++++++++++-----------
1 file changed, 26 insertions(+), 25 deletions(-)
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/NonPersistentTopicE2ETest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/NonPersistentTopicE2ETest.java
index 9525944adc7..f7adca08747 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/NonPersistentTopicE2ETest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/NonPersistentTopicE2ETest.java
@@ -84,7 +84,7 @@ public class NonPersistentTopicE2ETest extends BrokerTestBase
{
@Test(groups = "broker")
public void testGCWillDeleteSchema() throws Exception {
// 1. Simple successful GC
- String topicName = "non-persistent://prop/ns-abc/topic-1";
+ final String topicName = "non-persistent://prop/ns-abc/topic-1";
Producer<byte[]> producer =
pulsarClient.newProducer().topic(topicName).create();
producer.close();
@@ -101,56 +101,57 @@ public class NonPersistentTopicE2ETest extends
BrokerTestBase {
assertTrue(topicHasSchema(topicName));
runGC();
- topic = getTopic(topicName);
- assertFalse(topic.isPresent());
+ Awaitility.await().untilAsserted(() -> {
+ assertFalse(getTopic(topicName).isPresent());
+ });
assertFalse(topicHasSchema(topicName));
// 1a. Topic that add/removes subscription can be GC'd
- topicName = "non-persistent://prop/ns-abc/topic-1a";
+ final String topicName2 = "non-persistent://prop/ns-abc/topic-1a";
String subName = "sub1";
- Consumer<byte[]> consumer =
pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).subscribe();
- topic = getTopic(topicName);
+ Consumer<byte[]> consumer =
pulsarClient.newConsumer().topic(topicName2).subscriptionName(subName).subscribe();
+ topic = getTopic(topicName2);
assertTrue(topic.isPresent());
topic.get().addSchema(schemaData).join();
- assertTrue(topicHasSchema(topicName));
+ assertTrue(topicHasSchema(topicName2));
- admin.topics().deleteSubscription(topicName, subName);
+ admin.topics().deleteSubscription(topicName2, subName);
consumer.close();
runGC();
- topic = getTopic(topicName);
- assertFalse(topic.isPresent());
- assertFalse(topicHasSchema(topicName));
+ Awaitility.await().untilAsserted(() -> {
+ assertFalse(getTopic(topicName2).isPresent());
+ });
+ assertFalse(topicHasSchema(topicName2));
// 2. Topic is not GCed with live connection
- topicName = "non-persistent://prop/ns-abc/topic-2";
+ final String topicName3 = "non-persistent://prop/ns-abc/topic-2";
subName = "sub1";
- consumer =
pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).subscribe();
- topic = getTopic(topicName);
+ consumer =
pulsarClient.newConsumer().topic(topicName3).subscriptionName(subName).subscribe();
+ topic = getTopic(topicName3);
assertTrue(topic.isPresent());
topic.get().addSchema(schemaData).join();
- assertTrue(topicHasSchema(topicName));
+ assertTrue(topicHasSchema(topicName3));
runGC();
- topic = getTopic(topicName);
- assertTrue(topic.isPresent());
- assertTrue(topicHasSchema(topicName));
+ assertTrue(getTopic(topicName3).isPresent());
+ assertTrue(topicHasSchema(topicName3));
// 3. Topic with subscription is not GCed even with no connections
consumer.close();
runGC();
- topic = getTopic(topicName);
- assertTrue(topic.isPresent());
- assertTrue(topicHasSchema(topicName));
+ assertTrue(getTopic(topicName3).isPresent());
+ assertTrue(topicHasSchema(topicName3));
// 4. Topic can be GCed after unsubscribe
- admin.topics().deleteSubscription(topicName, subName);
+ admin.topics().deleteSubscription(topicName3, subName);
runGC();
- topic = getTopic(topicName);
- assertFalse(topic.isPresent());
- assertFalse(topicHasSchema(topicName));
+ Awaitility.await().untilAsserted(() -> {
+ assertFalse(getTopic(topicName3).isPresent());
+ });
+ assertFalse(topicHasSchema(topicName3));
}
@Test(groups = "broker")