github-advanced-security[bot] commented on code in PR #15953:
URL: https://github.com/apache/druid/pull/15953#discussion_r1503679270
##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQExportTest.java:
##########
@@ -95,36 +101,54 @@
.verifyResults();
Assert.assertEquals(
- expectedFooFileContents().size(),
+ expectedFooFileContents(false).size() + 1, // + 1 for the manifest file
Objects.requireNonNull(new
File(exportDir.getAbsolutePath()).listFiles()).length
);
}
- private List<Object[]> expectedFooFileContents()
+ private List<String> expectedFooFileContents(boolean withHeader)
{
- return new ArrayList<>(ImmutableList.of(
- new Object[]{"1", null},
- new Object[]{"1", 10.1},
- new Object[]{"1", 2},
- new Object[]{"1", 1},
- new Object[]{"1", "def"},
- new Object[]{"1", "abc"}
- ));
+ ArrayList<String> expectedResults = new ArrayList<>();
+ if (withHeader) {
+ expectedResults.add("cnt,dim1");
+ }
+ expectedResults.addAll(ImmutableList.of(
+ "1,",
+ "1,10.1",
+ "1,2",
+ "1,1",
+ "1,def",
+ "1,abc"
+ )
+ );
+ return expectedResults;
}
- private String convertResultsToString(List<Object[]> expectedRows) throws
IOException
+ private List<String> readResultsFromFile(File resultFile) throws IOException
{
- ByteArrayOutputStream expectedResult = new ByteArrayOutputStream();
- ResultFormat.Writer formatter =
ResultFormat.CSV.createFormatter(expectedResult, objectMapper);
- formatter.writeResponseStart();
- for (Object[] row : expectedRows) {
- formatter.writeRowStart();
- for (Object object : row) {
- formatter.writeRowField("", object);
+ List<String> results = new ArrayList<>();
+ try (BufferedReader br = new BufferedReader(new
InputStreamReader(Files.newInputStream(resultFile.toPath()),
StringUtils.UTF8_STRING))) {
+ String line;
+ while (!(line = br.readLine()).isEmpty()) {
+ results.add(line);
}
- formatter.writeRowEnd();
+ return results;
+ }
+ }
+
+ private void verifyManifestFile(File manifestFile, List<File> resultFiles)
throws IOException
+ {
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
+ Files.newInputStream(manifestFile.toPath()),
+ StringUtils.UTF8_STRING
+ ));
Review Comment:
## Potential input resource leak
This InputStreamReader is not always closed on method exit.
[Show more
details](https://github.com/apache/druid/security/code-scanning/6777)
--
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]