Copilot commented on code in PR #2743:
URL: https://github.com/apache/tika/pull/2743#discussion_r3039836124
##########
tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/PassbackFilterTest.java:
##########
@@ -81,6 +81,7 @@ public void testPassbackFilter(@TempDir Path tmpDir) throws
Exception {
.emitData()
.getMetadataList()
.get(0);
+ pipesClient.close();
assertEquals("TESTOVERLAPPINGTEXT.PDF",
metadata.get(TikaCoreProperties.RESOURCE_NAME_KEY));
Review Comment:
Calling `pipesClient.close()` here only closes the client on the success
path; if `process(...)` throws or an earlier assertion fails, the client (and
its temp dir) will remain open. Prefer try-with-resources for `PipesClient` in
this test, or ensure close happens in a `finally`/`@AfterEach`.
##########
tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/UnpackModeTest.java:
##########
@@ -310,24 +311,24 @@ public void
testUnpackModeBytesEmittedToOutputDir(@TempDir Path tmp) throws Exce
Path outputDir = tmp.resolve("output");
Files.createDirectories(outputDir);
- PipesClient pipesClient = init(tmp, testDocWithEmbedded);
-
- ParseContext parseContext = new ParseContext();
- parseContext.set(ParseMode.class, ParseMode.UNPACK);
-
- PipesResult pipesResult = pipesClient.process(
- new FetchEmitTuple(testDocWithEmbedded, new
FetchKey(fetcherName, testDocWithEmbedded),
- new EmitKey(emitterName, testDocWithEmbedded), new
Metadata(), parseContext,
- FetchEmitTuple.ON_PARSE_EXCEPTION.EMIT));
-
- assertTrue(pipesResult.isSuccess(), "UNPACK should succeed");
-
- // Check that output files were created for the embedded documents
- // The exact naming depends on the EmittingUnpackHandler configuration
- // At minimum, we verify the metadata JSON was written
- assertTrue(Files.exists(outputDir.resolve(testDocWithEmbedded +
".json")) ||
- Files.list(outputDir).count() > 0,
- "Output directory should contain emitted files");
+ try (PipesClient pipesClient = init(tmp, testDocWithEmbedded)) {
+ ParseContext parseContext = new ParseContext();
+ parseContext.set(ParseMode.class, ParseMode.UNPACK);
+
+ PipesResult pipesResult = pipesClient.process(
+ new FetchEmitTuple(testDocWithEmbedded, new
FetchKey(fetcherName, testDocWithEmbedded),
+ new EmitKey(emitterName, testDocWithEmbedded), new
Metadata(), parseContext,
+ FetchEmitTuple.ON_PARSE_EXCEPTION.EMIT));
+
+ assertTrue(pipesResult.isSuccess(), "UNPACK should succeed");
+
+ // Check that output files were created for the embedded documents
+ // The exact naming depends on the EmittingUnpackHandler
configuration
+ // At minimum, we verify the metadata JSON was written
+ assertTrue(Files.exists(outputDir.resolve(testDocWithEmbedded +
".json")) ||
+ Files.list(outputDir).count() > 0,
+ "Output directory should contain emitted files");
Review Comment:
`Files.list(outputDir)` returns a Stream that must be closed; using it
inline in the assertion leaks a directory stream on some platforms. Wrap the
`Files.list` call in a try-with-resources (or replace with a non-stream
alternative) before counting/checking entries.
--
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]