Skip to content

Commit c960d38

Browse files
THausherrCopilot
andauthored
TIKA-4704: close client so that temp directory gets deleted (#2743)
* TIKA-4704: close client so that temp directory gets deleted * Refactor PipesClient initialization in tests Refactor FrictionlessUnpackTest to use try-with-resources for PipesClient initialization, reducing code duplication and improving resource management. * Refactor try-with-resources syntax in tests * Refactor try-with-resources syntax in tests * Refactor testWriteLimiter methods for clarity * Clean up comments in MetadataWriteLimiterTest Removed redundant comments in the test case for write limiter override. * Refactor JSON config string in testWriteLimiterOverride Updated the JSON configuration string for ParseContext to improve readability. * Clean up comments in MetadataWriteLimiterTest Removed commented code regarding ParseContext override for X-TIKA:parse_time_millis. * Update comment to reflect number of embedded documents * Update tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/MetadataWriteLimiterTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Close pipesClient in PassbackFilterTest Close pipesClient after emitting data in test. * Refactor PipesClient usage in tests to try-with-resources * Update tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/EmbeddedLimitsTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactor UnpackModeTest for improved readability * Refactor PipesClientTest to use try-with-resources * Refactor UnpackModeTest for clarity and structure * Update tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/UnpackModeTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 89a301f commit c960d38

6 files changed

Lines changed: 825 additions & 824 deletions

File tree

tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/EmbeddedLimitsTest.java

Lines changed: 139 additions & 140 deletions
Large diffs are not rendered by default.

tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/FrictionlessUnpackTest.java

Lines changed: 220 additions & 220 deletions
Large diffs are not rendered by default.

tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/MetadataWriteLimiterTest.java

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ private PipesClient initWithWriteLimiter(Path tmp, String testFileName) throws E
5959
*/
6060
@Test
6161
public void testWriteLimiterFromConfig(@TempDir Path tmp) throws Exception {
62-
PipesClient pipesClient = initWithWriteLimiter(tmp, TEST_DOC);
63-
64-
PipesResult pipesResult = pipesClient.process(
65-
new FetchEmitTuple(TEST_DOC, new FetchKey(FETCHER_NAME, TEST_DOC),
66-
new EmitKey(), new Metadata(), new ParseContext(), FetchEmitTuple.ON_PARSE_EXCEPTION.SKIP));
67-
68-
assertNotNull(pipesResult.emitData().getMetadataList());
69-
assertEquals(1, pipesResult.emitData().getMetadataList().size());
70-
71-
Metadata metadata = pipesResult.emitData().getMetadataList().get(0);
62+
Metadata metadata;
63+
try (PipesClient pipesClient = initWithWriteLimiter(tmp, TEST_DOC)) {
64+
PipesResult pipesResult = pipesClient.process(
65+
new FetchEmitTuple(TEST_DOC, new FetchKey(FETCHER_NAME, TEST_DOC),
66+
new EmitKey(), new Metadata(), new ParseContext(), FetchEmitTuple.ON_PARSE_EXCEPTION.SKIP));
67+
assertNotNull(pipesResult.emitData().getMetadataList());
68+
assertEquals(1, pipesResult.emitData().getMetadataList().size());
69+
metadata = pipesResult.emitData().getMetadataList().get(0);
70+
}
7271

7372
// These fields should be present (in includeFields or "must add" fields)
7473
assertNotNull(metadata.get("Content-Type"), "Content-Type should be present");
@@ -88,31 +87,29 @@ public void testWriteLimiterFromConfig(@TempDir Path tmp) throws Exception {
8887
*/
8988
@Test
9089
public void testWriteLimiterOverrideViaParseContext(@TempDir Path tmp) throws Exception {
91-
PipesClient pipesClient = initWithWriteLimiter(tmp, TEST_DOC);
92-
93-
// Create a ParseContext with an override that allows X-TIKA:parse_time_millis
94-
// The default config's includeFields (dc:creator, Content-Type, X-TIKA:content)
95-
// does NOT include X-TIKA:parse_time_millis, but this override does.
96-
ParseContext parseContext = new ParseContext();
97-
String overrideJson = """
98-
{
99-
"includeFields": ["Content-Type", "X-TIKA:parse_time_millis"],
100-
"maxKeySize": 100,
101-
"maxFieldSize": 1000,
102-
"maxTotalBytes": 10000,
103-
"maxValuesPerField": 5
104-
}
105-
""";
106-
parseContext.setJsonConfig("standard-metadata-limiter-factory", () -> overrideJson);
107-
108-
PipesResult pipesResult = pipesClient.process(
109-
new FetchEmitTuple(TEST_DOC, new FetchKey(FETCHER_NAME, TEST_DOC),
110-
new EmitKey(), new Metadata(), parseContext, FetchEmitTuple.ON_PARSE_EXCEPTION.SKIP));
111-
112-
assertNotNull(pipesResult.emitData().getMetadataList());
113-
assertEquals(1, pipesResult.emitData().getMetadataList().size());
114-
115-
Metadata metadata = pipesResult.emitData().getMetadataList().get(0);
90+
Metadata metadata;
91+
try (PipesClient pipesClient = initWithWriteLimiter(tmp, TEST_DOC)) {
92+
// Create a ParseContext with an override that allows X-TIKA:parse_time_millis
93+
// The default config's includeFields (dc:creator, Content-Type, X-TIKA:content)
94+
// does NOT include X-TIKA:parse_time_millis, but this override does.
95+
ParseContext parseContext = new ParseContext();
96+
String overrideJson = """
97+
{
98+
"includeFields": ["Content-Type", "X-TIKA:parse_time_millis"],
99+
"maxKeySize": 100,
100+
"maxFieldSize": 1000,
101+
"maxTotalBytes": 10000,
102+
"maxValuesPerField": 5
103+
}
104+
""";
105+
parseContext.setJsonConfig("standard-metadata-limiter-factory", () -> overrideJson);
106+
PipesResult pipesResult = pipesClient.process(
107+
new FetchEmitTuple(TEST_DOC, new FetchKey(FETCHER_NAME, TEST_DOC),
108+
new EmitKey(), new Metadata(), parseContext, FetchEmitTuple.ON_PARSE_EXCEPTION.SKIP));
109+
assertNotNull(pipesResult.emitData().getMetadataList());
110+
assertEquals(1, pipesResult.emitData().getMetadataList().size());
111+
metadata = pipesResult.emitData().getMetadataList().get(0);
112+
}
116113

117114
// These fields should be present (in the override includeFields or ALWAYS_SET/ADD_FIELDS)
118115
assertNotNull(metadata.get("Content-Type"), "Content-Type should be present");

tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/PassbackFilterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void testPassbackFilter(@TempDir Path tmpDir) throws Exception {
8181
.emitData()
8282
.getMetadataList()
8383
.get(0);
84+
pipesClient.close();
8485
assertEquals("TESTOVERLAPPINGTEXT.PDF", metadata.get(TikaCoreProperties.RESOURCE_NAME_KEY));
8586
assertNull(metadata.get(Metadata.CONTENT_TYPE));
8687
assertNull(metadata.get(Metadata.CONTENT_LENGTH));

0 commit comments

Comments
 (0)