[GitHub] [hadoop] ayushtkn commented on a diff in pull request #5636: YARN-11492. Improve createJerseyClient#setConnectTimeout Code.
ayushtkn commented on code in PR #5636: URL: https://github.com/apache/hadoop/pull/5636#discussion_r1212556425 ## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestRouterWebServiceUtil.java: ## @@ -678,4 +683,83 @@ public void testMergeDiffApplicationStatisticsInfo() { Assert.assertEquals(YarnApplicationState.FINISHED, item3Result.getState()); Assert.assertEquals(item4.getCount(), item3Result.getCount()); } + + @Test + public void testCreateJerseyClient() { +// Case1, default timeout, The default timeout is 30s. +YarnConfiguration configuration = new YarnConfiguration(); +Client client01 = RouterWebServiceUtil.createJerseyClient(configuration); +Map properties = client01.getProperties(); +int readTimeOut = (int) properties.get(ClientConfig.PROPERTY_READ_TIMEOUT); +int connectTimeOut = (int) properties.get(ClientConfig.PROPERTY_CONNECT_TIMEOUT); +Assert.assertEquals(3, readTimeOut); +Assert.assertEquals(3, connectTimeOut); +client01.destroy(); + +// Case2, set a negative timeout, We'll get the default timeout(30s) +YarnConfiguration configuration2 = new YarnConfiguration(); +configuration2.setLong(YarnConfiguration.ROUTER_WEBAPP_CONNECT_TIMEOUT, -1L); +configuration2.setLong(YarnConfiguration.ROUTER_WEBAPP_READ_TIMEOUT, -1L); +Client client02 = RouterWebServiceUtil.createJerseyClient(configuration2); +Map properties02 = client02.getProperties(); +int readTimeOut02 = (int) properties02.get(ClientConfig.PROPERTY_READ_TIMEOUT); +int connectTimeOut02 = (int) properties02.get(ClientConfig.PROPERTY_CONNECT_TIMEOUT); +Assert.assertEquals(3, readTimeOut02); +Assert.assertEquals(3, connectTimeOut02); +client02.destroy(); + +// Case3, Set the maximum value that exceeds the integer +// We'll get the default timeout(30s) +YarnConfiguration configuration3 = new YarnConfiguration(); +long connectTimeOutLong = (long) Integer.MAX_VALUE + 1; +long readTimeOutLong = (long) Integer.MAX_VALUE + 1; Review Comment: I think the correct approach would be first get the long, figure out whether it is -ve or bigger than Integer.MAX and if so put a log and use the default. If it is within limit, then may be we can do a cast -- 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. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org
[GitHub] [hadoop] ayushtkn commented on a diff in pull request #5636: YARN-11492. Improve createJerseyClient#setConnectTimeout Code.
ayushtkn commented on code in PR #5636: URL: https://github.com/apache/hadoop/pull/5636#discussion_r1203933698 ## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestRouterWebServiceUtil.java: ## @@ -678,4 +683,83 @@ public void testMergeDiffApplicationStatisticsInfo() { Assert.assertEquals(YarnApplicationState.FINISHED, item3Result.getState()); Assert.assertEquals(item4.getCount(), item3Result.getCount()); } + + @Test + public void testCreateJerseyClient() { +// Case1, default timeout, The default timeout is 30s. +YarnConfiguration configuration = new YarnConfiguration(); +Client client01 = RouterWebServiceUtil.createJerseyClient(configuration); +Map properties = client01.getProperties(); +int readTimeOut = (int) properties.get(ClientConfig.PROPERTY_READ_TIMEOUT); +int connectTimeOut = (int) properties.get(ClientConfig.PROPERTY_CONNECT_TIMEOUT); +Assert.assertEquals(3, readTimeOut); +Assert.assertEquals(3, connectTimeOut); +client01.destroy(); + +// Case2, set a negative timeout, We'll get the default timeout(30s) +YarnConfiguration configuration2 = new YarnConfiguration(); +configuration2.setLong(YarnConfiguration.ROUTER_WEBAPP_CONNECT_TIMEOUT, -1L); +configuration2.setLong(YarnConfiguration.ROUTER_WEBAPP_READ_TIMEOUT, -1L); +Client client02 = RouterWebServiceUtil.createJerseyClient(configuration2); +Map properties02 = client02.getProperties(); +int readTimeOut02 = (int) properties02.get(ClientConfig.PROPERTY_READ_TIMEOUT); +int connectTimeOut02 = (int) properties02.get(ClientConfig.PROPERTY_CONNECT_TIMEOUT); +Assert.assertEquals(3, readTimeOut02); +Assert.assertEquals(3, connectTimeOut02); +client02.destroy(); + +// Case3, Set the maximum value that exceeds the integer +// We'll get the default timeout(30s) +YarnConfiguration configuration3 = new YarnConfiguration(); +long connectTimeOutLong = (long) Integer.MAX_VALUE + 1; +long readTimeOutLong = (long) Integer.MAX_VALUE + 1; Review Comment: if it is ``` long connectTimeOutLong = (long) Integer.MAX_VALUE * 3L; long readTimeOutLong = (long) Integer.MAX_VALUE * 3L; ``` you won't get the default value I think, because you are relying on the value to go negative when you cast, but post cast it can go +ve as well -- 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. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org