Skip to content

Commit 7cd2f11

Browse files
committed
Add test for verifying retries.
1 parent 96d9f7b commit 7cd2f11

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.typesense.api;
2+
3+
import junit.framework.TestCase;
4+
import org.typesense.resources.Node;
5+
6+
import java.net.UnknownHostException;
7+
import java.time.Duration;
8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
11+
public class RetryTest extends TestCase {
12+
13+
private Client client;
14+
15+
public void setUp() throws Exception {
16+
super.setUp();
17+
ArrayList<Node> nodes = new ArrayList<>();
18+
nodes.add(new Node("http","unknownhost123","8108"));
19+
Configuration configuration = new Configuration(nodes, Duration.ofSeconds(1),"xyz");
20+
configuration.numRetries = 2;
21+
configuration.retryInterval = Duration.ofSeconds(2);
22+
this.client = new Client(configuration);
23+
}
24+
25+
public void testRetry() throws Exception {
26+
long start = System.currentTimeMillis();
27+
try {
28+
client.health.retrieve();
29+
} catch (Exception e) {
30+
long timeTaken = System.currentTimeMillis() - start;
31+
assertTrue(e.getCause() instanceof UnknownHostException);
32+
assertTrue(timeTaken > 4000);
33+
return ;
34+
}
35+
36+
throw new Exception("Retry did not throw exception.");
37+
}
38+
}

0 commit comments

Comments
 (0)