-
Notifications
You must be signed in to change notification settings - Fork 27
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
added diagnostics support for @Retry
annotation member values
#191
Conversation
9563b3b
to
e7b7ade
Compare
1d225c0
to
5f854a4
Compare
.../eclipse/lsp4mp/jdt/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java
Outdated
Show resolved
Hide resolved
.../eclipse/lsp4mp/jdt/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java
Outdated
Show resolved
Hide resolved
It works, but there's a small problem I noticed. It only makes sense to compare the delay and maxDuration directly when their time units (delayUnit & durationUnit) match. If they don't, you may need to do some additional math (or api call) to be sure. For example If delay = 5, maxDuration = 3, delayUnit = ChronoUnit.SECONDS, durationUnit = ChronoUnit.MILLENNIA, validation would currently fail, but we should be fine. |
According to the docstring for jitter(https://github.com/eclipse/microprofile-fault-tolerance/blob/800363fe002701bb2e31ba413f21e5a36af56b41/api/src/main/java/org/eclipse/microprofile/faulttolerance/Retry.java#L120), I believe that the jitter can randomly add to/subtract from the delay. That means if the delay + jitter exceeds maxDuration, then it should be invalid. However, there doesn't seem to be a test case for this on the mp fault-tolerance side. Should this case be considered in validation @rgrunber? |
I think at this point I'd be inclined to just validate if the time units are the same. Seems overkill to check jitter as well. |
5f854a4
to
b1e8fda
Compare
@angelozerr , looks like RangeExpression.parse(String) can't deal with the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we just need to wait on a fix for lsp4mp to handle negative values in the range.
.../eclipse/lsp4mp/jdt/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java
Outdated
Show resolved
Hide resolved
.../eclipse/lsp4mp/jdt/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java
Outdated
Show resolved
Hide resolved
4601071
to
786d5b7
Compare
Can you try adding : diff --git a/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/core/java/validators/annotations/RangeExpression.java b/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/core/java/validators/annotations/RangeExpression.java
index 9b70b92..82cd29a 100644
--- a/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/core/java/validators/annotations/RangeExpression.java
+++ b/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/internal/core/java/validators/annotations/RangeExpression.java
@@ -152,7 +152,7 @@ public class RangeExpression {
valueAsString.append(c);
break;
default:
- if (Character.isDigit(c)) {
+ if (Character.isDigit(c) || '-' == c) {^M
valueAsString.append(c);
} else {
unexpectedToken(c, i, expression); and see if that solves the issue ? Note : Proper approach is to give it its own case where |
This is a solution, but I also added the |
bb0389a
to
0aebc46
Compare
0aebc46
to
21c245e
Compare
...rg/eclipse/lsp4mp/jdt/internal/core/java/validators/annotations/AnnotationValidatorTest.java
Show resolved
Hide resolved
...rg/eclipse/lsp4mp/jdt/internal/core/java/validators/annotations/AnnotationValidatorTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Alexander Chen <alchen@redhat.com>
21c245e
to
c90fe89
Compare
LGTM |
Great job @AlexXuChen ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try the following :
@Retry(
delay = 8,
maxDuration = 2,
delayUnit = java.time.temporal.ChronoUnit.HOURS,
durationUnit = ChronoUnit.HOURS
)
Basically, you need to deal with fully qualified names.
A fully qualified name is made of 2 components : The qualifier (eg. java.time.temporal.ChronoUnit, or just ChronoUnit) and the name (eg. HOURS).
Duration jitterValue = jitterDelayUnitExpr != null | ||
? Duration.of(jitterNum, ChronoUnit.valueOf(jitterDelayUnit)) | ||
: Duration.of(jitterNum, ChronoUnit.MILLIS); | ||
Duration maxDelayValue = delayValue.plus(jitterValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, jitter it is. It isn't just added to the delay, but also subtracted. It adds some random delay to the minium value. Have a look at https://github.com/eclipse/microprofile-fault-tolerance/blob/800363fe002701bb2e31ba413f21e5a36af56b41/api/src/main/java/org/eclipse/microprofile/faulttolerance/Retry.java#L113 .
The reason I hesitated is because if you take a delay of 3, with a jitter of 2, and maxDuration of 4, you'll have delays between [1,5] . Some of the delays will fall below 4, but others above. Should we all this an error ? Maybe a warning ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the error message reports "The delay
member value must be less than the maxDuration
member value.", but to illustrate this, I can mention "the sum of delay
and jitter
...".
According to https://github.com/eclipse/microprofile-fault-tolerance/blob/800363fe002701bb2e31ba413f21e5a36af56b41/api/src/main/java/org/eclipse/microprofile/faulttolerance/Retry.java#L113, the negative effective delays have a lower bound of 0, which means the maximum effective delay should be the only one we need to validate.
You can also declare : |
Added diagnostics support for
@Retry
annotation member values, for non-negative values anddelay
exceedingmaxDuration
References #77
Signed-off-by: Alexander Chen alchen@redhat.com