Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit 89be9cb

Browse files
committed
WIP: Print HostStatuses in DNSTimeout
1 parent 717e9bb commit 89be9cb

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

algoliasearch/src/main/java/com/algolia/search/saas/AbstractClient.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.lang.ref.WeakReference;
4646
import java.net.HttpURLConnection;
4747
import java.net.URL;
48+
import java.text.SimpleDateFormat;
4849
import java.util.ArrayList;
4950
import java.util.Arrays;
5051
import java.util.Date;
@@ -92,14 +93,20 @@ public int hashCode() {
9293
}
9394
}
9495

95-
private static class HostStatus {
96-
boolean isUp = true;
96+
static class HostStatus {
97+
boolean isUp;
9798
long lastTryTimestamp;
9899

99100
HostStatus(boolean isUp) {
100101
this.isUp = isUp;
101102
lastTryTimestamp = new Date().getTime();
102103
}
104+
105+
@Override
106+
public String toString() {
107+
return (isUp ? "up" : "down") + " at " + new SimpleDateFormat("HH:mm:ss.SSS")
108+
.format(new Date(lastTryTimestamp));
109+
}
103110
}
104111

105112
// ----------------------------------------------------------------------

algoliasearch/src/test/java/com/algolia/search/saas/IndexTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.Map;
4646
import java.util.UUID;
4747

48+
import static com.algolia.search.saas.AbstractClient.HostStatus;
4849
import static org.junit.Assert.assertEquals;
4950
import static org.junit.Assert.assertFalse;
5051
import static org.junit.Assert.assertNotEquals;
@@ -530,9 +531,16 @@ public void DNSTimeout() throws AssertionError {
530531
// Expect failed search after timeout
531532
final long startTime = System.nanoTime();
532533
index.searchAsync(new Query(), new AssertCompletionHandler() {
533-
@Override public void doRequestCompleted(JSONObject content, AlgoliaException error) {
534+
@Override
535+
public void doRequestCompleted(JSONObject content, AlgoliaException error) {
534536
if (error != null) {
535537
final long duration = (System.nanoTime() - startTime) / 1000000;
538+
System.out.println(error.getMessage());
539+
// Whitebox.getInternalState(client, "readHosts", hostsArray);
540+
HashMap<String, HostStatus> hostStatuses = (HashMap<String, HostStatus>) Whitebox.getInternalState(client, "hostStatuses");
541+
for (Map.Entry<String, HostStatus> entry : hostStatuses.entrySet()) {
542+
System.out.println(entry.getKey() + ": " + entry.getValue().toString());
543+
}
536544
assertTrue("We should hit 4 times the timeout before failing, but test took only " + duration + " ms.",
537545
duration > timeout * 4);
538546
} else {

0 commit comments

Comments
 (0)