-
Notifications
You must be signed in to change notification settings - Fork 14
/
RetryStatsTest.java
48 lines (41 loc) · 1.32 KB
/
RetryStatsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package net.jodah.sarge.internal;
import org.testng.annotations.Test;
import java.time.Duration;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
/**
* @author Jonathan Halterman
*/
@Test
public class RetryStatsTest {
public void shouldAllowRetryWhenAttemptsNotExceeded() throws Exception {
RetryStats stats = new RetryStats(new RetryDirective(3, Duration.ofMillis(50)));
assertTrue(stats.canRetry());
stats.canRetry();
stats.canRetry();
Thread.sleep(75);
assertTrue(stats.canRetry());
}
public void shouldAllowRetryWhenAttemptsExceededOutsideOfWindow() throws Exception {
RetryStats stats = new RetryStats(new RetryDirective(3, Duration.ofMillis(50)));
stats.canRetry();
stats.canRetry();
assertTrue(stats.canRetry());
Thread.sleep(75);
stats.canRetry();
stats.canRetry();
assertTrue(stats.canRetry());
}
public void shouldNotAllowRetryWhenAttemptsExceededWithinWindow() throws Exception {
RetryStats stats = new RetryStats(new RetryDirective(3, Duration.ofMillis(50)));
stats.canRetry();
assertTrue(stats.canRetry());
stats.canRetry();
stats.canRetry();
stats.canRetry();
assertFalse(stats.canRetry());
// Positive test after window reset
Thread.sleep(75);
assertTrue(stats.canRetry());
}
}