This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1137 from finos/1087-add-retry-limit-to-reductive…
…-walker 1087, 1092 add retry limit to reductive walker
- Loading branch information
Showing
10 changed files
with
290 additions
and
19 deletions.
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
25 changes: 25 additions & 0 deletions
25
generator/src/main/java/com/scottlogic/deg/generator/walker/ReductiveWalkerRetryChecker.java
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.scottlogic.deg.generator.walker; | ||
|
||
public class ReductiveWalkerRetryChecker { | ||
private int numRetriesSoFar = 0; | ||
private int retryLimit; | ||
|
||
public ReductiveWalkerRetryChecker(int retryLimit) { | ||
this.retryLimit = retryLimit; | ||
} | ||
|
||
void retrySuccessful() { | ||
numRetriesSoFar = 0; | ||
} | ||
|
||
void retryUnsuccessful() { | ||
numRetriesSoFar++; | ||
if (numRetriesSoFar > retryLimit) { | ||
throw new RetryLimitReachedException(); | ||
} | ||
} | ||
|
||
void reset() { | ||
numRetriesSoFar = 0; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
generator/src/main/java/com/scottlogic/deg/generator/walker/RetryLimitReachedException.java
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.scottlogic.deg.generator.walker; | ||
|
||
public class RetryLimitReachedException extends RuntimeException { | ||
// This exception must be a RuntimeException to be able to break out of a stream evaluation. | ||
public RetryLimitReachedException() { | ||
super(); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...r/src/test/java/com/scottlogic/deg/generator/walker/ReductiveWalkerRetryCheckerTests.java
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.scottlogic.deg.generator.walker; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ReductiveWalkerRetryCheckerTests { | ||
@Test | ||
public void retryChecker_withRepeatedFailure_throwsException() { | ||
//Arrange | ||
ReductiveWalkerRetryChecker retryChecker = new ReductiveWalkerRetryChecker(2); | ||
|
||
//Act | ||
retryChecker.retryUnsuccessful(); | ||
retryChecker.retryUnsuccessful(); | ||
|
||
//Assert | ||
assertThrows(RetryLimitReachedException.class, retryChecker::retryUnsuccessful); | ||
} | ||
|
||
@Test | ||
public void retryChecker_withRepeatedFailureAfterSuccess_doesNotThrowException() { | ||
//Arrange | ||
ReductiveWalkerRetryChecker retryChecker = new ReductiveWalkerRetryChecker(2); | ||
|
||
//Act | ||
retryChecker.retryUnsuccessful(); | ||
retryChecker.retrySuccessful(); | ||
retryChecker.retryUnsuccessful(); | ||
|
||
//Assert | ||
assertDoesNotThrow(retryChecker::retryUnsuccessful); | ||
} | ||
|
||
@Test | ||
public void reset_resetsLimit() { | ||
//Arrange | ||
ReductiveWalkerRetryChecker retryChecker = new ReductiveWalkerRetryChecker(2); | ||
|
||
//Act | ||
retryChecker.retryUnsuccessful(); | ||
retryChecker.retryUnsuccessful(); | ||
retryChecker.reset(); | ||
retryChecker.retryUnsuccessful(); | ||
retryChecker.retryUnsuccessful(); | ||
|
||
//Assert | ||
assertThrows(RetryLimitReachedException.class, retryChecker::retryUnsuccessful); | ||
} | ||
|
||
@Test | ||
public void reset_resetsGuaranteeOfSuccess() { | ||
//Arrange | ||
ReductiveWalkerRetryChecker retryChecker = new ReductiveWalkerRetryChecker(2); | ||
|
||
//Act | ||
retryChecker.retrySuccessful(); | ||
retryChecker.reset(); | ||
retryChecker.retryUnsuccessful(); | ||
retryChecker.retryUnsuccessful(); | ||
|
||
//Assert | ||
assertThrows(RetryLimitReachedException.class, retryChecker::retryUnsuccessful); | ||
} | ||
} |
Oops, something went wrong.