-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add timeout config to RetryTest and CircuitBreakerTimeoutTest #543
Merged
Emily-Jiang
merged 2 commits into
eclipse:master
from
Azquelt:retry-delay-timeout-config
May 18, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
******************************************************************************* | ||
* Copyright (c) 2018 Contributors to the Eclipse Foundation | ||
* Copyright (c) 2018-2020 Contributors to the Eclipse Foundation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2018, 2020 |
||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
|
@@ -23,6 +23,7 @@ | |
|
||
import javax.enterprise.context.RequestScoped; | ||
|
||
import org.eclipse.microprofile.fault.tolerance.tck.util.TCKConfig; | ||
import org.eclipse.microprofile.faulttolerance.CircuitBreaker; | ||
import org.eclipse.microprofile.faulttolerance.Timeout; | ||
import org.eclipse.microprofile.faulttolerance.exceptions.BulkheadException; | ||
|
@@ -38,10 +39,10 @@ public class CircuitBreakerClientWithTimeout { | |
* @return should always throw TimeoutException, unless CircuitBreaker prevents execution | ||
*/ | ||
@CircuitBreaker(successThreshold = 2, requestVolumeThreshold = 2, failureRatio = 0.75, delay = 50000) | ||
@Timeout(500) | ||
@Timeout(500) // Adjusted by config | ||
public String serviceWithTimeout() { | ||
try { | ||
Thread.sleep(1000); | ||
Thread.sleep(TCKConfig.getConfig().getTimeoutInMillis(1000)); | ||
fail("Thread not interrupted by timeout"); | ||
} | ||
catch (InterruptedException e) { | ||
|
@@ -60,10 +61,10 @@ public String serviceWithTimeout() { | |
* @return should always throw TimeoutException | ||
*/ | ||
@CircuitBreaker(successThreshold = 2, requestVolumeThreshold = 2, failureRatio = 0.75, delay = 50000, failOn = BulkheadException.class) | ||
@Timeout(500) | ||
@Timeout(500) // Adjusted by config | ||
public String serviceWithTimeoutWithoutFailOn() { | ||
try { | ||
Thread.sleep(1000); | ||
Thread.sleep(TCKConfig.getConfig().getTimeoutInMillis(1000)); | ||
fail("Thread not interrupted by timeout"); | ||
} | ||
catch (InterruptedException e) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
******************************************************************************* | ||
* Copyright (c) 2016-2017 Contributors to the Eclipse Foundation | ||
* Copyright (c) 2016-2020 Contributors to the Eclipse Foundation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2016, 2020 |
||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
|
@@ -19,13 +19,18 @@ | |
*******************************************************************************/ | ||
package org.eclipse.microprofile.fault.tolerance.tck.retry.clientserver; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.everyItem; | ||
import static org.hamcrest.Matchers.lessThan; | ||
|
||
import java.sql.Connection; | ||
import java.time.Duration; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
|
||
import org.eclipse.microprofile.fault.tolerance.tck.util.TCKConfig; | ||
import org.eclipse.microprofile.faulttolerance.Retry; | ||
/** | ||
* A client to demonstrate the delay configurations | ||
|
@@ -38,12 +43,12 @@ public class RetryClientWithDelay { | |
private long timestampForConnectionService = 0; | ||
private Set<Duration> delayTimes = new HashSet<>(); | ||
|
||
// Expect delay between 0-800ms. Set limit to 900ms to allow a small buffer | ||
private static final Duration MAX_DELAY = Duration.ofMillis(900); | ||
// Expect delay between 0-800ms. Set limit to 1000ms to allow a small buffer | ||
private static final Duration MAX_DELAY = TCKConfig.getConfig().getTimeoutInDuration(1000); | ||
|
||
//There should be 0-800ms (jitter is -400ms - 400ms) delays between each invocation | ||
//there should be at least 4 retries | ||
@Retry(delay = 400, maxDuration= 3200, jitter= 400, maxRetries = 10) | ||
@Retry(delay = 400, maxDuration = 3200, jitter = 400, maxRetries = 10) // Adjusted by config | ||
public Connection serviceA() { | ||
return connectionService(); | ||
} | ||
|
@@ -61,14 +66,8 @@ private Connection connectionService() { | |
throw new RuntimeException("Connection failed"); | ||
} | ||
|
||
public boolean isDelayInRange() { | ||
boolean isDelayInRange = true; | ||
for (Duration delayTime : delayTimes) { | ||
if (delayTime.compareTo(MAX_DELAY) > 0) { | ||
return false; | ||
} | ||
} | ||
return isDelayInRange; | ||
public void assertDelayInRange() { | ||
assertThat("Delay longer than expected", delayTimes, everyItem(lessThan(MAX_DELAY))); | ||
} | ||
|
||
public int getRetryCountForConnectionService() { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It should be 2018, 2020
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.
If this is wrong, then it's wrong almost everywhere.
If it needs fixed, we should probably do a mass change over the whole repo.
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.
Raised #545 for this.