lhotari commented on a change in pull request #9420:
URL: https://github.com/apache/pulsar/pull/9420#discussion_r568367550
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +143,14 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
Review comment:
use `.untilAsserted` instead of `.until`.
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +143,14 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
Review comment:
`.atMost` can be omitted since the default is 10 seconds anyways.
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +143,14 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
+ try {
+ pulsar.getBrokerService().getTopicIfExists(topicName).get(3,
TimeUnit.SECONDS).get();
+ return true;
+ } catch (Exception ignored) {
+ }
Review comment:
When a code block should pass, using `untilAsserted` will lead to
cleaner code and there won't be a need to return a boolean or catch exceptions.
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +143,14 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
+ try {
+ pulsar.getBrokerService().getTopicIfExists(topicName).get(3,
TimeUnit.SECONDS).get();
+ return true;
+ } catch (Exception ignored) {
+ }
Review comment:
When a code block should pass, using `untilAsserted` will lead to
cleaner code since there won't be a need to return a boolean or catch
exceptions.
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +143,14 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
+ try {
+ pulsar.getBrokerService().getTopicIfExists(topicName).get(3,
TimeUnit.SECONDS).get();
+ return true;
+ } catch (Exception ignored) {
+ }
Review comment:
Yes you are right @315157973 , untilAsserted will only catch
AssertionErrors . I'm sorry about the incorrect advice.
Your original approach seemed to be the best approach after all since it
would also handle the case of an exception being caught.
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +143,14 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
+ try {
+ pulsar.getBrokerService().getTopicIfExists(topicName).get(3,
TimeUnit.SECONDS).get();
+ return true;
+ } catch (Exception ignored) {
+ }
Review comment:
hmm. there's also `.catchUncaughtExceptions()`.
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +143,14 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
+ try {
+ pulsar.getBrokerService().getTopicIfExists(topicName).get(3,
TimeUnit.SECONDS).get();
+ return true;
+ } catch (Exception ignored) {
+ }
Review comment:
`catchUncaughtExceptions` defaults to true in Awaitility, so after all,
untilAsserted should be fine without catching the exception. @315157973 Have
you actually checked that RuntimeException terminates untilAsserted?
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +145,12 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().untilAsserted(() -> {
+ try {
+
assertNotNull(pulsar.getBrokerService().getTopicIfExists(topicName).get(3,
TimeUnit.SECONDS).get());
+ } catch (Exception ignored) {
Review comment:
I think this should be removed since Awaitility catches
RuntimeExceptions by default.
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +145,12 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().untilAsserted(() -> {
+ try {
+
assertNotNull(pulsar.getBrokerService().getTopicIfExists(topicName).get(3,
TimeUnit.SECONDS).get());
+ } catch (Exception ignored) {
Review comment:
Actually it does terminate the test, I just checked, so I'll take this
back. The original approach was fine, my advice was bad. I'm sorry about that.
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +145,12 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().untilAsserted(() -> {
+ try {
+
assertNotNull(pulsar.getBrokerService().getTopicIfExists(topicName).get(3,
TimeUnit.SECONDS).get());
+ } catch (Exception ignored) {
Review comment:
`Awaitility.await().ignoreExceptions().untilAsserted` works. So one more
round...
##########
File path:
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ConsumedLedgersTrimTest.java
##########
@@ -142,6 +145,12 @@ public void testConsumedLedgersTrimNoSubscriptions()
throws Exception {
// the lastMessageId is still on the previous ledger
restartBroker();
// force load topic
+ Awaitility.await().untilAsserted(() -> {
+ try {
+
assertNotNull(pulsar.getBrokerService().getTopicIfExists(topicName).get(3,
TimeUnit.SECONDS).get());
+ } catch (Exception ignored) {
Review comment:
@315157973 feel free to go with the original. this is my bad. Next time
I'll know that it's `Awaitility.await().ignoreExceptions().untilAsserted` which
should be used. :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]