-
Notifications
You must be signed in to change notification settings - Fork 0
/
RetryTemplateTest.java
66 lines (51 loc) · 1.7 KB
/
RetryTemplateTest.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package xyz.downgoon.mydk.util;
import junit.framework.Assert;
import org.junit.Test;
public class RetryTemplateTest {
@Test
public void testEcho() {
UnreliableService us = new UnreliableService(1);
RetryTemplate retryTemplate = new RetryTemplate(us,"US", 1,2,4);
Exception exception = null;
try {
retryTemplate.retry("echo", "hello hill");
} catch (Exception e) {
exception = e;
}
Assert.assertNull(exception);
}
@Test
public void testSilence() {
UnreliableService us = new UnreliableService(1);
RetryTemplate retryTemplate = new RetryTemplate(us,"US", 1,2,4);
Exception exception = null;
try {
retryTemplate.retry("silence", "hello hill");
} catch (Exception e) {
exception = e;
}
Assert.assertNull(exception);
}
static class UnreliableService {
private int unreliableCount = 1;
public UnreliableService(int unreliableCount) {
super();
this.unreliableCount = unreliableCount;
}
private int echoCount = 0;
public String echo(String arg) {
echoCount ++;
if (echoCount <= unreliableCount) {
throw new IllegalStateException("unreliabe call "+echoCount);
}
return arg;
}
private int silenceCount = 0;
public void silence(String arg) {
silenceCount ++;
if (silenceCount <= unreliableCount) {
throw new IllegalStateException("unreliabe call "+silenceCount);
}
}
}
}