Skip to content

Commit df4237a

Browse files
authored
fix units for the connect timeout (#4228)
1 parent c90ddce commit df4237a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/util/HostUtil.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public static int urlToPort(String urlStr) throws URISyntaxException {
5959
return uri.getPort();
6060
}
6161

62-
private static boolean isWebAppReachable(String webappURI, int timeOutMillis, @Nullable String token) {
62+
private static boolean isWebAppReachable(String webappURI, int timeOutSeconds, @Nullable String token) {
6363
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
64-
clientBuilder.connectTimeout(timeOutMillis, TimeUnit.MILLISECONDS);
65-
clientBuilder.readTimeout(timeOutMillis, TimeUnit.MILLISECONDS);
64+
clientBuilder.connectTimeout(timeOutSeconds, TimeUnit.SECONDS);
65+
clientBuilder.readTimeout(timeOutSeconds, TimeUnit.SECONDS);
6666

6767
// Here, IndexerUtil#getWebAppHeaders() is not used because at the point this method is called,
6868
// the RuntimeEnvironment configuration used by getWebAppHeaders() is not set yet.
@@ -71,6 +71,8 @@ private static boolean isWebAppReachable(String webappURI, int timeOutMillis, @N
7171
headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + token);
7272
}
7373

74+
LOGGER.log(Level.FINE, "checking reachability of {0} with connect/read timeout of {1} seconds",
75+
new Object[]{webappURI, timeOutSeconds});
7476
try (Client client = clientBuilder.build()) {
7577
Response response = client
7678
.target(webappURI)
@@ -97,11 +99,11 @@ private static boolean isWebAppReachable(String webappURI, int timeOutMillis, @N
9799
/**
98100
*
99101
* @param webappURI URI of the web app
100-
* @param timeOutMillis connect/read timeout in milliseconds
102+
* @param timeOutSeconds connect/read timeout in seconds
101103
* @param token authentication token, can be {@code null}
102104
* @return whether web app is reachable within given timeout on given URI
103105
*/
104-
public static boolean isReachable(String webappURI, int timeOutMillis, @Nullable String token) {
106+
public static boolean isReachable(String webappURI, int timeOutSeconds, @Nullable String token) {
105107
boolean connectWorks = false;
106108

107109
try {
@@ -111,7 +113,7 @@ public static boolean isReachable(String webappURI, int timeOutMillis, @Nullable
111113
return false;
112114
}
113115

114-
return isWebAppReachable(webappURI, timeOutMillis, token);
116+
return isWebAppReachable(webappURI, timeOutSeconds, token);
115117
} catch (URISyntaxException e) {
116118
LOGGER.log(Level.SEVERE, String.format("URI not valid: %s", webappURI), e);
117119
}

opengrok-indexer/src/test/java/org/opengrok/indexer/util/HostUtilTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@
3333
public class HostUtilTest {
3434
@Test
3535
void testInvalidURI() {
36-
assertFalse(HostUtil.isReachable("htt://localhost:8080/source/", 1000, null));
36+
assertFalse(HostUtil.isReachable("htt://localhost:8080/source/", 10, null));
3737
}
3838

3939
@Test
4040
void testInvalidHost() {
41-
assertFalse(HostUtil.isReachable("http://localhosta:8080/source/", 1000, null));
41+
assertFalse(HostUtil.isReachable("http://localhosta:8080/source/", 10, null));
4242
}
4343

4444
@Test
4545
void testInvalidPort() {
46-
assertFalse(HostUtil.isReachable("http://localhost:zzzz/source/", 1000, null));
46+
assertFalse(HostUtil.isReachable("http://localhost:zzzz/source/", 10, null));
4747
}
4848

4949
@Test
5050
void testNotReachableWebApp() {
51-
assertFalse(HostUtil.isReachable("http://localhost:4444/source/", 1000, null));
51+
assertFalse(HostUtil.isReachable("http://localhost:4444/source/", 10, null));
5252
}
5353
}

0 commit comments

Comments
 (0)