Fix TestSnapshotCloudManager test bug: file handle leak

I believe this was the root cause of some recent windows jenkins suite level failures in cleaning up temp files

(cherry picked from commit 416de65d31)
This commit is contained in:
Chris Hostetter 2019-09-11 11:47:50 -07:00
parent 32d6f3953c
commit 3120409699
1 changed files with 6 additions and 4 deletions

View File

@ -117,10 +117,12 @@ public class TestSnapshotCloudManager extends SolrCloudTestCase {
for (String key : SnapshotCloudManager.REQUIRED_KEYS) {
File src = new File(tmpDir, key + ".json");
assertTrue(src.toString() + " doesn't exist", src.exists());
String data = IOUtils.toString(new FileInputStream(src), Charset.forName("UTF-8"));
assertFalse("empty data in " + src, data.trim().isEmpty());
for (String redactedName : redacted) {
assertFalse("redacted name " + redactedName + " found in " + src, data.contains(redactedName));
try (FileInputStream is = new FileInputStream(src)) {
String data = IOUtils.toString(is, Charset.forName("UTF-8"));
assertFalse("empty data in " + src, data.trim().isEmpty());
for (String redactedName : redacted) {
assertFalse("redacted name " + redactedName + " found in " + src, data.contains(redactedName));
}
}
}
}