github-advanced-security[bot] commented on code in PR #19495:
URL: https://github.com/apache/druid/pull/19495#discussion_r3278256207
##########
indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskRunnerUtilsTest.java:
##########
@@ -52,4 +66,84 @@
);
Assert.assertEquals("https://1.2.3.4:8290/druid/worker/v1/task/foo%20bar%26/log",
url.toString());
}
+
+ @Test
+ public void testStreamTaskReportsFromTaskLocationOk() throws Exception
+ {
+ final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
+ final String report = "my report";
+ EasyMock.expect(httpClient.go(EasyMock.anyObject(Request.class),
EasyMock.anyObject(InputStreamFullResponseHandler.class)))
+ .andReturn(Futures.immediateFuture(response(HttpResponseStatus.OK,
report)));
+ EasyMock.replay(httpClient);
+
+ final Optional<InputStream> stream =
TaskRunnerUtils.streamTaskReportsFromTaskLocation(
+ httpClient,
+ new URL("http://example.com/liveReports")
+ );
+
+ Assert.assertTrue(stream.isPresent());
+ Assert.assertEquals(report,
StringUtils.fromUtf8(ByteStreams.toByteArray(stream.get())));
+ EasyMock.verify(httpClient);
+ }
+
+ @Test
+ public void testStreamTaskReportsFromTaskLocationNotFound() throws Exception
+ {
+
assertStreamTaskReportsFromTaskLocationUnavailable(HttpResponseStatus.NOT_FOUND);
+ }
+
+ @Test
+ public void testStreamTaskReportsFromTaskLocationServiceUnavailable() throws
Exception
+ {
+
assertStreamTaskReportsFromTaskLocationUnavailable(HttpResponseStatus.SERVICE_UNAVAILABLE);
+ }
+
+ @Test
+ public void testStreamTaskReportsFromTaskLocationUnexpectedStatus() throws
Exception
+ {
+ final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
+ EasyMock.expect(httpClient.go(EasyMock.anyObject(Request.class),
EasyMock.anyObject(InputStreamFullResponseHandler.class)))
+
.andReturn(Futures.immediateFuture(response(HttpResponseStatus.INTERNAL_SERVER_ERROR,
"error")));
+ EasyMock.replay(httpClient);
+
+ final IOException e = Assert.assertThrows(
+ IOException.class,
+ () -> TaskRunnerUtils.streamTaskReportsFromTaskLocation(
+ httpClient,
+ new URL("http://example.com/liveReports")
Review Comment:
## CodeQL / Deprecated method or constructor invocation
Invoking [URL.URL](1) should be avoided because it has been deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/11246)
##########
indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskRunnerUtilsTest.java:
##########
@@ -52,4 +66,84 @@
);
Assert.assertEquals("https://1.2.3.4:8290/druid/worker/v1/task/foo%20bar%26/log",
url.toString());
}
+
+ @Test
+ public void testStreamTaskReportsFromTaskLocationOk() throws Exception
+ {
+ final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
+ final String report = "my report";
+ EasyMock.expect(httpClient.go(EasyMock.anyObject(Request.class),
EasyMock.anyObject(InputStreamFullResponseHandler.class)))
+ .andReturn(Futures.immediateFuture(response(HttpResponseStatus.OK,
report)));
+ EasyMock.replay(httpClient);
+
+ final Optional<InputStream> stream =
TaskRunnerUtils.streamTaskReportsFromTaskLocation(
+ httpClient,
+ new URL("http://example.com/liveReports")
Review Comment:
## CodeQL / Deprecated method or constructor invocation
Invoking [URL.URL](1) should be avoided because it has been deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/11245)
##########
indexing-service/src/test/java/org/apache/druid/indexing/overlord/TaskRunnerUtilsTest.java:
##########
@@ -52,4 +66,84 @@
);
Assert.assertEquals("https://1.2.3.4:8290/druid/worker/v1/task/foo%20bar%26/log",
url.toString());
}
+
+ @Test
+ public void testStreamTaskReportsFromTaskLocationOk() throws Exception
+ {
+ final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
+ final String report = "my report";
+ EasyMock.expect(httpClient.go(EasyMock.anyObject(Request.class),
EasyMock.anyObject(InputStreamFullResponseHandler.class)))
+ .andReturn(Futures.immediateFuture(response(HttpResponseStatus.OK,
report)));
+ EasyMock.replay(httpClient);
+
+ final Optional<InputStream> stream =
TaskRunnerUtils.streamTaskReportsFromTaskLocation(
+ httpClient,
+ new URL("http://example.com/liveReports")
+ );
+
+ Assert.assertTrue(stream.isPresent());
+ Assert.assertEquals(report,
StringUtils.fromUtf8(ByteStreams.toByteArray(stream.get())));
+ EasyMock.verify(httpClient);
+ }
+
+ @Test
+ public void testStreamTaskReportsFromTaskLocationNotFound() throws Exception
+ {
+
assertStreamTaskReportsFromTaskLocationUnavailable(HttpResponseStatus.NOT_FOUND);
+ }
+
+ @Test
+ public void testStreamTaskReportsFromTaskLocationServiceUnavailable() throws
Exception
+ {
+
assertStreamTaskReportsFromTaskLocationUnavailable(HttpResponseStatus.SERVICE_UNAVAILABLE);
+ }
+
+ @Test
+ public void testStreamTaskReportsFromTaskLocationUnexpectedStatus() throws
Exception
+ {
+ final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
+ EasyMock.expect(httpClient.go(EasyMock.anyObject(Request.class),
EasyMock.anyObject(InputStreamFullResponseHandler.class)))
+
.andReturn(Futures.immediateFuture(response(HttpResponseStatus.INTERNAL_SERVER_ERROR,
"error")));
+ EasyMock.replay(httpClient);
+
+ final IOException e = Assert.assertThrows(
+ IOException.class,
+ () -> TaskRunnerUtils.streamTaskReportsFromTaskLocation(
+ httpClient,
+ new URL("http://example.com/liveReports")
+ )
+ );
+
+ Assert.assertTrue(e.getMessage().contains("500 Internal Server Error"));
+ EasyMock.verify(httpClient);
+ }
+
+ private static void assertStreamTaskReportsFromTaskLocationUnavailable(
+ final HttpResponseStatus status
+ ) throws Exception
+ {
+ final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
+ EasyMock.expect(httpClient.go(EasyMock.anyObject(Request.class),
EasyMock.anyObject(InputStreamFullResponseHandler.class)))
+ .andReturn(Futures.immediateFuture(response(status, "error")));
+ EasyMock.replay(httpClient);
+
+ Assert.assertEquals(
+ Optional.absent(),
+ TaskRunnerUtils.streamTaskReportsFromTaskLocation(httpClient, new
URL("http://example.com/liveReports"))
Review Comment:
## CodeQL / Deprecated method or constructor invocation
Invoking [URL.URL](1) should be avoided because it has been deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/11247)
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]