FixedDelayRetry.java

1
package fr.sii.ogham.core.retry;
2
3
import java.time.Instant;
4
5
/**
6
 * Retry several times with a fixed delay to wait after the last execution
7
 * failure until the maximum attempts is reached.
8
 * 
9
 * If delay is 500ms and max retries is 5, it means that a retry will be
10
 * attempted every 500ms until 5 attempts are reached (inclusive). For example,
11
 * you want to connect to an external system at t1=0 and the connection timeout
12
 * (100ms) is triggered at t2=100ms. Using this retry will provide the following
13
 * behavior:
14
 * 
15
 * <ul>
16
 * <li>0: connect</li>
17
 * <li>100: timeout</li>
18
 * <li>600: connect</li>
19
 * <li>700: timeout</li>
20
 * <li>1200: connect</li>
21
 * <li>1300: timeout</li>
22
 * <li>1800: connect</li>
23
 * <li>1900: timeout</li>
24
 * <li>2400: connect</li>
25
 * <li>2500: timeout</li>
26
 * <li>3000: connect</li>
27
 * <li>3100: timeout</li>
28
 * <li>fail</li>
29
 * </ul>
30
 * 
31
 * 
32
 * @author Aurélien Baudet
33
 *
34
 */
35
public class FixedDelayRetry implements RetryStrategy {
36
	private final int maxRetries;
37
	private final long delay;
38
	private int retries;
39
40
	/**
41
	 * Initializes with the maximum attempts and the delay to wait after a
42
	 * failure.
43
	 * 
44
	 * @param maxRetries
45
	 *            the maximum attempts
46
	 * @param delay
47
	 *            the delay to wait after failure to do another attempt
48
	 */
49
	public FixedDelayRetry(int maxRetries, long delay) {
50
		super();
51
		this.maxRetries = maxRetries;
52
		this.delay = delay;
53
		retries = maxRetries;
54
	}
55
56
	@Override
57
	public boolean terminated() {
58 12 1. terminated : replaced boolean return with true for fr/sii/ogham/core/retry/FixedDelayRetry::terminated → NO_COVERAGE
2. terminated : changed conditional boundary → NO_COVERAGE
3. terminated : negated conditional → NO_COVERAGE
4. terminated : replaced boolean return with true for fr/sii/ogham/core/retry/FixedDelayRetry::terminated → TIMED_OUT
5. terminated : changed conditional boundary → TIMED_OUT
6. terminated : negated conditional → TIMED_OUT
7. terminated : replaced boolean return with true for fr/sii/ogham/core/retry/FixedDelayRetry::terminated → KILLED
8. terminated : replaced boolean return with true for fr/sii/ogham/core/retry/FixedDelayRetry::terminated → KILLED
9. terminated : changed conditional boundary → KILLED
10. terminated : changed conditional boundary → KILLED
11. terminated : negated conditional → KILLED
12. terminated : negated conditional → KILLED
		return retries <= 0;
59
	}
60
61
	@Override
62
	public Instant nextDate(Instant executionStartTime, Instant executionFailureTime) {
63 3 1. nextDate : Replaced integer subtraction with addition → NO_COVERAGE
2. nextDate : Replaced integer subtraction with addition → TIMED_OUT
3. nextDate : Replaced integer subtraction with addition → KILLED
		retries--;
64 4 1. nextDate : replaced return value with null for fr/sii/ogham/core/retry/FixedDelayRetry::nextDate → NO_COVERAGE
2. nextDate : replaced return value with null for fr/sii/ogham/core/retry/FixedDelayRetry::nextDate → TIMED_OUT
3. nextDate : replaced return value with null for fr/sii/ogham/core/retry/FixedDelayRetry::nextDate → KILLED
4. nextDate : replaced return value with null for fr/sii/ogham/core/retry/FixedDelayRetry::nextDate → KILLED
		return executionFailureTime.plusMillis(delay);
65
	}
66
67
	public int getRemainingRetries() {
68 2 1. getRemainingRetries : replaced int return with 0 for fr/sii/ogham/core/retry/FixedDelayRetry::getRemainingRetries → NO_COVERAGE
2. getRemainingRetries : replaced int return with 0 for fr/sii/ogham/core/retry/FixedDelayRetry::getRemainingRetries → KILLED
		return retries;
69
	}
70
71
	public int getMaxRetries() {
72 1 1. getMaxRetries : replaced int return with 0 for fr/sii/ogham/core/retry/FixedDelayRetry::getMaxRetries → NO_COVERAGE
		return maxRetries;
73
	}
74
75
	public long getDelay() {
76 1 1. getDelay : replaced long return with 0 for fr/sii/ogham/core/retry/FixedDelayRetry::getDelay → NO_COVERAGE
		return delay;
77
	}
78
}

Mutations

58

1.1
Location : terminated
Killed by : oghamcore.ut.core.retry.FixedDelayRetryExecutorTest.reachMaximumAttempts(oghamcore.ut.core.retry.FixedDelayRetryExecutorTest)
replaced boolean return with true for fr/sii/ogham/core/retry/FixedDelayRetry::terminated → KILLED

2.2
Location : terminated
Killed by : oghamall.it.retry.AutoRetryTest.resendSms(oghamall.it.retry.AutoRetryTest)
replaced boolean return with true for fr/sii/ogham/core/retry/FixedDelayRetry::terminated → KILLED

3.3
Location : terminated
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/retry/FixedDelayRetry::terminated → NO_COVERAGE

4.4
Location : terminated
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/retry/FixedDelayRetry::terminated → TIMED_OUT

5.5
Location : terminated
Killed by : oghamall.it.retry.AutoRetryTest.resendSms(oghamall.it.retry.AutoRetryTest)
changed conditional boundary → KILLED

6.6
Location : terminated
Killed by : oghamcore.ut.core.retry.FixedDelayRetryExecutorTest.reachMaximumAttempts(oghamcore.ut.core.retry.FixedDelayRetryExecutorTest)
changed conditional boundary → KILLED

7.7
Location : terminated
Killed by : none
changed conditional boundary → TIMED_OUT

8.8
Location : terminated
Killed by : none
changed conditional boundary → NO_COVERAGE

9.9
Location : terminated
Killed by : none
negated conditional → NO_COVERAGE

10.10
Location : terminated
Killed by : none
negated conditional → TIMED_OUT

11.11
Location : terminated
Killed by : oghamall.it.retry.AutoRetryTest.resendSms(oghamall.it.retry.AutoRetryTest)
negated conditional → KILLED

12.12
Location : terminated
Killed by : oghamcore.ut.core.retry.FixedDelayRetryExecutorTest.reachMaximumAttempts(oghamcore.ut.core.retry.FixedDelayRetryExecutorTest)
negated conditional → KILLED

63

1.1
Location : nextDate
Killed by : oghamcore.ut.core.retry.FixedDelayRetryExecutorTest.reachMaximumAttempts(oghamcore.ut.core.retry.FixedDelayRetryExecutorTest)
Replaced integer subtraction with addition → KILLED

2.2
Location : nextDate
Killed by : none
Replaced integer subtraction with addition → TIMED_OUT

3.3
Location : nextDate
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

64

1.1
Location : nextDate
Killed by : none
replaced return value with null for fr/sii/ogham/core/retry/FixedDelayRetry::nextDate → NO_COVERAGE

2.2
Location : nextDate
Killed by : oghamall.it.retry.AutoRetryTest.resendSms(oghamall.it.retry.AutoRetryTest)
replaced return value with null for fr/sii/ogham/core/retry/FixedDelayRetry::nextDate → KILLED

3.3
Location : nextDate
Killed by : oghamcore.ut.core.retry.FixedDelayRetryExecutorTest.reachMaximumAttempts(oghamcore.ut.core.retry.FixedDelayRetryExecutorTest)
replaced return value with null for fr/sii/ogham/core/retry/FixedDelayRetry::nextDate → KILLED

4.4
Location : nextDate
Killed by : none
replaced return value with null for fr/sii/ogham/core/retry/FixedDelayRetry::nextDate → TIMED_OUT

68

1.1
Location : getRemainingRetries
Killed by : none
replaced int return with 0 for fr/sii/ogham/core/retry/FixedDelayRetry::getRemainingRetries → NO_COVERAGE

2.2
Location : getRemainingRetries
Killed by : oghamcore.ut.core.retry.FixedDelayRetryExecutorTest.reachMaximumAttempts(oghamcore.ut.core.retry.FixedDelayRetryExecutorTest)
replaced int return with 0 for fr/sii/ogham/core/retry/FixedDelayRetry::getRemainingRetries → KILLED

72

1.1
Location : getMaxRetries
Killed by : none
replaced int return with 0 for fr/sii/ogham/core/retry/FixedDelayRetry::getMaxRetries → NO_COVERAGE

76

1.1
Location : getDelay
Killed by : none
replaced long return with 0 for fr/sii/ogham/core/retry/FixedDelayRetry::getDelay → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM