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:19:39 UTC

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

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



##########
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:
       The code indentation format is wrong.

##########
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:
       The code indentation format is wrong.

##########
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:
       The code indentation format is wrong.




-- 
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