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

Fix MethodRetry annotation handling for unlimited maximum attempts #831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/main/java/com/uber/cadence/common/RetryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ public static RetryOptions merge(MethodRetry r, RetryOptions o) {
} else {
builder.setBackoffCoefficient(DEFAULT_BACKOFF_COEFFICIENT);
}
int maximumAttempts = merge(r.maximumAttempts(), o.getMaximumAttempts(), int.class);
if (maximumAttempts != 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no sure if I follow that. How is zero different from null in the processing? Could you provide the code link?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shijiesheng I think the point is setMaximumAttempts method throws exception if the value is 0.
The value 0 is default and a valid value if "expiration" is set.
Unfortunately I cannot build the project locally because of thrift 0.9.3 not available on linux currently but test like that should show it:

public class RetryOptionsTest {
  @Test
  public void testUnlimitedRetryWithExpiration() throws NoSuchMethodException {
    RetryOptions topLevelOption =
        new RetryOptions.Builder().setExpiration(Duration.ofSeconds(5)).build();
    MethodRetry methodRetry =
        UnlimitedRetry.class.getMethod("retry").getAnnotation(MethodRetry.class);
    RetryOptions retryOptions = RetryOptions.merge(methodRetry, topLevelOption);
    Assert.assertEquals(
        "Top level options must take precedence", 5, retryOptions.getExpiration().getSeconds());
  }

  private interface UnlimitedRetry {
    @ActivityMethod
    @MethodRetry(expirationSeconds = 100)
    void retry();
  }
}

builder.setMaximumAttempts(maximumAttempts);
}
return builder
.setMaximumAttempts(merge(r.maximumAttempts(), o.getMaximumAttempts(), int.class))
.setDoNotRetry(merge(r.doNotRetry(), o.getDoNotRetry()))
.validateBuildWithDefaults();
}
Expand Down