Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Tests ] Use Awaitility to instead of Thread sleep #11164

Merged
merged 1 commit into from
Jun 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static org.testng.Assert.assertEquals;

import java.time.Duration;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
Expand Down Expand Up @@ -85,18 +86,9 @@ public void testInitialization() throws InterruptedException, ExecutionException
future.completeExceptionally(t);
}
});

// Make sure subscription has been created
while (true) {
try {
List<String> subscriptions = admin.topics().getSubscriptions(topicName);
if(subscriptions.size() == 1){
break;
}
} catch (Exception ignored){
}
Thread.sleep(200);
}
Awaitility.await()
.ignoreExceptions()
.until(()->admin.topics().getSubscriptions(topicName).size() == 1);

PulsarClientTool pulsarClientToolProducer = new PulsarClientTool(properties);

Expand Down Expand Up @@ -150,16 +142,10 @@ public void testNonDurableSubscribe() throws Exception {
Assert.assertFalse(future.isCompletedExceptionally());
future.get();

while (true) {
try {
List<String> subscriptions = admin.topics().getSubscriptions(topicName);
if (subscriptions.size() == 0) {
break;
}
} catch (Exception ignored) {
}
Thread.sleep(200);
}
Awaitility.await()
.ignoreExceptions()
.atMost(Duration.ofMillis(20000))
.until(()->admin.topics().getSubscriptions(topicName).size() == 0);
}

@Test(timeOut = 60000)
Expand All @@ -186,18 +172,11 @@ public void testDurableSubscribe() throws Exception {
future.completeExceptionally(t);
}
});

// Make sure subscription has been created
while (true) {
try {
List<String> subscriptions = admin.topics().getSubscriptions(topicName);
if (subscriptions.size() == 1) {
break;
}
} catch (Exception ignored) {
}
Thread.sleep(200);
}
Awaitility.await()
.atMost(Duration.ofMillis(60000))
.ignoreExceptions()
.until(() -> admin.topics().getSubscriptions(topicName).size() == 1);

PulsarClientTool pulsarClientToolProducer = new PulsarClientTool(properties);

Expand All @@ -207,7 +186,7 @@ public void testDurableSubscribe() throws Exception {
Assert.assertFalse(future.isCompletedExceptionally());
future.get();
//wait for close
Thread.sleep(2000);
Awaitility.waitAtMost(Duration.ofDays(2000));
mattisonchao marked this conversation as resolved.
Show resolved Hide resolved
List<String> subscriptions = admin.topics().getSubscriptions(topicName);
Assert.assertNotNull(subscriptions);
Assert.assertEquals(subscriptions.size(), 1);
Expand Down Expand Up @@ -239,15 +218,10 @@ public void testEncryption() throws Exception {
});

// Make sure subscription has been created
Awaitility.await().until(() -> {
boolean isCreated = false;
try {
List<String> subscriptions = admin.topics().getSubscriptions(topicName);
isCreated = (subscriptions.size() == 1);
} catch (Exception ignored) {
}
return isCreated;
});
Awaitility.await()
.atMost(Duration.ofMillis(20000))
.ignoreExceptions()
.until(() -> admin.topics().getSubscriptions(topicName).size() == 1);

PulsarClientTool pulsarClientToolProducer = new PulsarClientTool(properties);
String[] args = {"produce", "-m", "Have a nice day", "-n", Integer.toString(numberOfMessages), "-ekn",
Expand Down