You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/01/05 09:51:16 UTC

[GitHub] [dolphinscheduler] springmonster commented on a change in pull request #7798: [Improvement] Optimize HttpUtils and HttpUtilsTest 1. Checking input parameters of getResponseContentString 2. Add unit test

springmonster commented on a change in pull request #7798:
URL: https://github.com/apache/dolphinscheduler/pull/7798#discussion_r778682856



##########
File path: dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/HttpUtils.java
##########
@@ -154,10 +154,10 @@ public static String getResponseContentString(HttpGet httpget, CloseableHttpClie
                     logger.warn("http entity is null");
                 }
             } else {
-                logger.error("http get:{} response status code is not 200!", response.getStatusLine().getStatusCode());
+                logger.error("http get: {} response status code is not 200!", response.getStatusLine().getStatusCode());
             }
-        } catch (IOException ioe) {
-            logger.error(ioe.getMessage(), ioe);
+        } catch (NullPointerException | IOException exception) {
+            logger.error(exception.getMessage(), exception);

Review comment:
       Hi @zhuangchong ,updated,please check again.
   Thanks for your suggestion.

##########
File path: dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java
##########
@@ -39,40 +39,41 @@
 
     @Test
     public void testGetTest() {
-	// success
-	String result = HttpUtils.get("https://github.com/manifest.json");
-	Assert.assertNotNull(result);
-	ObjectNode jsonObject = JSONUtils.parseObject(result);
-	Assert.assertEquals("GitHub", jsonObject.path("name").asText());
-	result = HttpUtils.get("https://123.333.111.33/ccc");
-	Assert.assertNull(result);
+		// success
+		String result = HttpUtils.get("https://github.com/manifest.json");
+		Assert.assertNotNull(result);
+		ObjectNode jsonObject = JSONUtils.parseObject(result);
+		Assert.assertEquals("GitHub", jsonObject.path("name").asText());
+		result = HttpUtils.get("https://123.333.111.33/ccc");
+		Assert.assertNull(result);
     }
 
     @Test
     public void testGetByKerberos() {
-	try {
-	    String applicationUrl = hadoopUtils.getApplicationUrl("application_1542010131334_0029");
-	    String responseContent;
-	    responseContent = HttpUtils.get(applicationUrl);
-	    Assert.assertNull(responseContent);
-
-	} catch (Exception e) {
-	    logger.error(e.getMessage(), e);
-	}
-
+		try {
+			String applicationUrl = hadoopUtils.getApplicationUrl("application_1542010131334_0029");
+			String responseContent;
+			responseContent = HttpUtils.get(applicationUrl);
+			Assert.assertNull(responseContent);
+		} catch (Exception e) {
+			logger.error(e.getMessage(), e);
+		}
     }
 
     @Test
     public void testGetResponseContentString() {
-	CloseableHttpClient httpclient = HttpClients.createDefault();
-	HttpGet httpget = new HttpGet("https://github.com/manifest.json");
-	/** set timeout、request time、socket timeout */
-	RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(Constants.HTTP_CONNECT_TIMEOUT)
-		.setConnectionRequestTimeout(Constants.HTTP_CONNECTION_REQUEST_TIMEOUT)
-		.setSocketTimeout(Constants.SOCKET_TIMEOUT).setRedirectsEnabled(true).build();
-	httpget.setConfig(requestConfig);
-	String responseContent = HttpUtils.getResponseContentString(httpget, httpclient);
-	Assert.assertNotNull(responseContent);
+		CloseableHttpClient httpclient = HttpClients.createDefault();
+		HttpGet httpget = new HttpGet("https://github.com/manifest.json");
+		/** set timeout、request time、socket timeout */
+		RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(Constants.HTTP_CONNECT_TIMEOUT)
+			.setConnectionRequestTimeout(Constants.HTTP_CONNECTION_REQUEST_TIMEOUT)
+			.setSocketTimeout(Constants.SOCKET_TIMEOUT).setRedirectsEnabled(true).build();
+		httpget.setConfig(requestConfig);
+		String responseContent = HttpUtils.getResponseContentString(httpget, httpclient);
+		Assert.assertNotNull(responseContent);
+	
+		responseContent = HttpUtils.getResponseContentString(null, null);
+		Assert.assertNull(responseContent);

Review comment:
       Hi @zhuangchong ,updated,please check again.
   Thanks for your suggestion.

##########
File path: dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java
##########
@@ -39,40 +39,41 @@
 
     @Test
     public void testGetTest() {
-	// success
-	String result = HttpUtils.get("https://github.com/manifest.json");
-	Assert.assertNotNull(result);
-	ObjectNode jsonObject = JSONUtils.parseObject(result);
-	Assert.assertEquals("GitHub", jsonObject.path("name").asText());
-	result = HttpUtils.get("https://123.333.111.33/ccc");
-	Assert.assertNull(result);
+		// success
+		String result = HttpUtils.get("https://github.com/manifest.json");
+		Assert.assertNotNull(result);
+		ObjectNode jsonObject = JSONUtils.parseObject(result);
+		Assert.assertEquals("GitHub", jsonObject.path("name").asText());
+		result = HttpUtils.get("https://123.333.111.33/ccc");
+		Assert.assertNull(result);
     }
 
     @Test
     public void testGetByKerberos() {
-	try {
-	    String applicationUrl = hadoopUtils.getApplicationUrl("application_1542010131334_0029");
-	    String responseContent;
-	    responseContent = HttpUtils.get(applicationUrl);
-	    Assert.assertNull(responseContent);
-
-	} catch (Exception e) {
-	    logger.error(e.getMessage(), e);
-	}
-
+		try {
+			String applicationUrl = hadoopUtils.getApplicationUrl("application_1542010131334_0029");
+			String responseContent;
+			responseContent = HttpUtils.get(applicationUrl);
+			Assert.assertNull(responseContent);
+		} catch (Exception e) {
+			logger.error(e.getMessage(), e);
+		}

Review comment:
       Hi @zhuangchong ,updated,please check again.
   Thanks for your suggestion.

##########
File path: dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java
##########
@@ -39,40 +39,41 @@
 
     @Test
     public void testGetTest() {
-	// success
-	String result = HttpUtils.get("https://github.com/manifest.json");
-	Assert.assertNotNull(result);
-	ObjectNode jsonObject = JSONUtils.parseObject(result);
-	Assert.assertEquals("GitHub", jsonObject.path("name").asText());
-	result = HttpUtils.get("https://123.333.111.33/ccc");
-	Assert.assertNull(result);
+		// success
+		String result = HttpUtils.get("https://github.com/manifest.json");
+		Assert.assertNotNull(result);
+		ObjectNode jsonObject = JSONUtils.parseObject(result);
+		Assert.assertEquals("GitHub", jsonObject.path("name").asText());
+		result = HttpUtils.get("https://123.333.111.33/ccc");
+		Assert.assertNull(result);

Review comment:
       Hi @zhuangchong ,updated,please check again.
   Thanks for your suggestion.




-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org