This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/master by this push:
new 9918cd0 NO-JIRA Adding option to RetryRule to retry on success
9918cd0 is described below
commit 9918cd02fb8d159208ea7cab7c803a1f8734e140
Author: Clebert Suconic <[email protected]>
AuthorDate: Thu Apr 30 11:43:11 2020 -0400
NO-JIRA Adding option to RetryRule to retry on success
This means retry a test until it failed, if the option is chosen.
---
.../apache/activemq/artemis/utils/RetryRule.java | 36 +++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git
a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/RetryRule.java
b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/RetryRule.java
index 50c1073..7e40c62 100644
---
a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/RetryRule.java
+++
b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/RetryRule.java
@@ -33,7 +33,8 @@ public class RetryRule implements MethodRule {
private static Logger logger = Logger.getLogger(RetryRule.class);
- int defaultNumberOfRetries;
+ final int defaultNumberOfRetries;
+ final boolean retrySuccess;
public RetryRule() {
this(0);
@@ -41,6 +42,17 @@ public class RetryRule implements MethodRule {
public RetryRule(int defaultNumberOfRetries) {
this.defaultNumberOfRetries = defaultNumberOfRetries;
+ this.retrySuccess = false;
+ }
+
+ /**
+ *
+ * @param defaultNumberOfRetries
+ * @param retrySuccess if true, it will keep retrying until it failed or
the number of retries have reached an end, opposite rule.
+ */
+ public RetryRule(int defaultNumberOfRetries, boolean retrySuccess) {
+ this.defaultNumberOfRetries = defaultNumberOfRetries;
+ this.retrySuccess = retrySuccess;
}
private int getNumberOfRetries(final FrameworkMethod method) {
@@ -58,6 +70,28 @@ public class RetryRule implements MethodRule {
@Override
public Statement apply(final Statement base, final FrameworkMethod method,
Object target) {
+ if (retrySuccess) {
+ return retrySuccess(base, method, target);
+ } else {
+ return retryIfFailed(base, method, target);
+ }
+ }
+
+ protected Statement retrySuccess(Statement base, FrameworkMethod method,
Object target) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ int retries = getNumberOfRetries(method) + 1;
+ for (int i = 0; i < retries; i++) {
+ logger.warn("LOOP " + i);
+ base.evaluate();
+ }
+ }
+ };
+ }
+
+
+ protected Statement retryIfFailed(Statement base, FrameworkMethod method,
Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {