narendly commented on a change in pull request #1013:
URL: https://github.com/apache/helix/pull/1013#discussion_r426055460
##########
File path: helix-common/src/main/java/org/apache/helix/SystemPropertyKeys.java
##########
@@ -78,4 +78,7 @@
// System Property Metadata Store Directory Server endpoint key
public static final String MSDS_SERVER_ENDPOINT_KEY =
MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY;
+
+ // System property for request timeout
+ public static final String HTTP_REQUEST_TIMEOUT = "http.request.timeout";
Review comment:
Is this strictly for Helix REST? In that case, should we try to put this
in a PropertyKey constant file in the helix-rest module?
##########
File path:
helix-rest/src/main/java/org/apache/helix/rest/client/CustomRestClientFactory.java
##########
@@ -32,10 +36,13 @@
*/
public class CustomRestClientFactory {
private static final Logger LOG =
LoggerFactory.getLogger(CustomRestClientFactory.class);
+ private static final int DEFAULT_HTTP_REQUEST_TIMEOUT = 60 * 1000;
Review comment:
For timeout values, we usually use `long` type.
`60 * 1000L;`
##########
File path:
helix-rest/src/test/java/org/apache/helix/rest/client/TestCustomRestClient.java
##########
@@ -145,6 +150,19 @@ public void testPostRequestFormat() throws IOException {
Assert.assertEquals(json.get("data").asText(), "{}");
}
+ @Test(expectedExceptions = ConnectTimeoutException.class)
+ public void testPostRequestSmallTimeout() throws IOException {
+ // Set 1 ms to cause timeout for requests
+ System.setProperty(SystemPropertyKeys.HTTP_REQUEST_TIMEOUT, "1");
+ // a popular echo server that echos all the inputs
+ final String echoServer = "http://httpbin.org/post";
+ CustomRestClient _customRestClient = MockCustomRestClientFactory.get();
+ _customRestClient.getInstanceStoppableCheck(echoServer,
Collections.emptyMap());
+
+ // Reset the HTTP_REQUEST_TIMEOUT property back to its original value
+ System.setProperty(SystemPropertyKeys.HTTP_REQUEST_TIMEOUT, "60000");
Review comment:
:"back to its original value" -> where is the original value set?
##########
File path:
helix-rest/src/test/java/org/apache/helix/rest/client/TestCustomRestClient.java
##########
@@ -161,4 +179,35 @@ protected JsonNode getJsonObject(HttpResponse
httpResponse) throws IOException {
return new ObjectMapper().readTree(_jsonResponse);
}
}
+
+ /**
+ * This MockCustomRestClientFactory is necessary to have for testing because
once an INSTANCE is
+ * initialized in CustomRestClientFactory while running "mvn test" , it will
no re-initialize the
Review comment:
Please fix typos.
##########
File path:
helix-rest/src/test/java/org/apache/helix/rest/client/TestCustomRestClient.java
##########
@@ -161,4 +179,35 @@ protected JsonNode getJsonObject(HttpResponse
httpResponse) throws IOException {
return new ObjectMapper().readTree(_jsonResponse);
}
}
+
+ /**
+ * This MockCustomRestClientFactory is necessary to have for testing because
once an INSTANCE is
+ * initialized in CustomRestClientFactory while running "mvn test" , it will
no re-initialize the
+ * INSTANCE with new HelixProperty. Hence this class makes sure that new
CustomRestClient will be
+ * created with the timeout set to the new value.
+ */
+ private static class MockCustomRestClientFactory extends
CustomRestClientFactory {
+ private static final int DEFAULT_HTTP_REQUEST_TIMEOUT = 60 * 1000;
Review comment:
Use long
##########
File path:
helix-rest/src/main/java/org/apache/helix/rest/client/CustomRestClientFactory.java
##########
@@ -44,14 +51,17 @@ public static CustomRestClient get() {
if (INSTANCE == null) {
try {
HttpClient httpClient;
+ RequestConfig config =
RequestConfig.custom().setConnectTimeout(_httpRequestTimeout)
+ .setConnectionRequestTimeout(_httpRequestTimeout)
+ .setSocketTimeout(_httpRequestTimeout).build();
Review comment:
Do we want to set the socket and connect timeout as well? Those two seem
unrelated to the problem you're solving. I am not saying we shouldn't
necessarily, but we should understand the implications of setting such configs.
Also it would be good to add a line of comment describing what you're doing
here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]