Skip to content

Commit

Permalink
[HUDI-3900] Closing resources in TestHoodieLogRecord (#6995)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsivabalan authored Oct 19, 2022
1 parent 52ed71a commit cd67964
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public void testEmptyLog() throws IOException {
assertEquals(0, writer.getCurrentSize(), "Just created this log, size should be 0");
assertTrue(writer.getLogFile().getFileName().startsWith("."), "Check all log files should start with a .");
assertEquals(1, writer.getLogFile().getLogVersion(), "Version should be 1 for new log created");
writer.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -698,7 +699,7 @@ public void testBasicAppendAndScanMultipleFiles(ExternalSpillableMap.DiskMapType

assertEquals(scannedRecords.size(), allRecords.stream().mapToLong(Collection::size).sum(),
"Scanner records count should be the same as appended records");

scanner.close();
}

@Test
Expand Down Expand Up @@ -933,6 +934,7 @@ public void testAvroLogRecordReaderBasic(ExternalSpillableMap.DiskMapType diskMa
copyOfRecords1.stream().map(s -> ((GenericRecord) s).get(HoodieRecord.RECORD_KEY_METADATA_FIELD).toString())
.collect(Collectors.toSet());
assertEquals(originalKeys, readKeys, "CompositeAvroLogReader should return 200 records from 2 versions");
scanner.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -1017,6 +1019,7 @@ public void testAvroLogRecordReaderWithRollbackTombstone(ExternalSpillableMap.Di
copyOfRecords1.stream().map(s -> ((GenericRecord) s).get(HoodieRecord.RECORD_KEY_METADATA_FIELD).toString())
.collect(Collectors.toSet());
assertEquals(originalKeys, readKeys, "CompositeAvroLogReader should return 200 records from 2 versions");
scanner.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -1106,6 +1109,7 @@ public void testAvroLogRecordReaderWithFailedPartialBlock(ExternalSpillableMap.D
copyOfRecords1.stream().map(s -> ((GenericRecord) s).get(HoodieRecord.RECORD_KEY_METADATA_FIELD).toString())
.collect(Collectors.toSet());
assertEquals(originalKeys, readKeys, "CompositeAvroLogReader should return 200 records from 2 versions");
scanner.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -1209,6 +1213,7 @@ public void testAvroLogRecordReaderWithDeleteAndRollback(ExternalSpillableMap.Di
FileCreateUtils.deleteDeltaCommit(basePath, "101", fs);

readKeys.clear();
scanner.close();
scanner = HoodieMergedLogRecordScanner.newBuilder()
.withFileSystem(fs)
.withBasePath(basePath)
Expand Down Expand Up @@ -1243,6 +1248,8 @@ public void testAvroLogRecordReaderWithDeleteAndRollback(ExternalSpillableMap.Di
Collections.sort(firstBlockRecords);
Collections.sort(readKeys);
assertEquals(firstBlockRecords, readKeys, "CompositeAvroLogReader should return 150 records from 2 versions");
writer.close();
scanner.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -1360,6 +1367,8 @@ public void testAvroLogRecordReaderWithDisorderDelete(ExternalSpillableMap.DiskM
Collections.sort(originalKeys);
Collections.sort(readKeys);
assertEquals(originalKeys, readKeys, "HoodieMergedLogRecordScanner should return 180 records from 4 versions");
writer.close();
scanner.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -1447,6 +1456,8 @@ public void testAvroLogRecordReaderWithFailedRollbacks(ExternalSpillableMap.Disk
scanner.forEach(s -> readKeys.add(s.getKey().getRecordKey()));
assertEquals(0, readKeys.size(), "Stream collect should return all 0 records");
FileCreateUtils.deleteDeltaCommit(basePath, "100", fs);
writer.close();
scanner.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -1513,6 +1524,8 @@ public void testAvroLogRecordReaderWithInsertDeleteAndRollback(ExternalSpillable
.build();
assertEquals(0, scanner.getTotalLogRecords(), "We would read 0 records");
FileCreateUtils.deleteDeltaCommit(basePath, "100", fs);
writer.close();
scanner.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -1568,6 +1581,8 @@ public void testAvroLogRecordReaderWithInvalidRollback(ExternalSpillableMap.Disk
final List<String> readKeys = new ArrayList<>(100);
scanner.forEach(s -> readKeys.add(s.getKey().getRecordKey()));
assertEquals(100, readKeys.size(), "Stream collect should return all 150 records");
writer.close();
scanner.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -1637,6 +1652,8 @@ public void testAvroLogRecordReaderWithInsertsDeleteAndRollback(ExternalSpillabl
.withUseScanV2(useScanv2)
.build();
assertEquals(0, scanner.getTotalLogRecords(), "We would read 0 records");
writer.close();
scanner.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -1746,6 +1763,7 @@ public void testAvroLogRecordReaderWithMixedInsertsCorruptsAndRollback(ExternalS
.build();
assertEquals(0, scanner.getTotalLogRecords(), "We would read 0 records");
FileCreateUtils.deleteDeltaCommit(basePath, "100", fs);
scanner.close();
}

@ParameterizedTest
Expand Down Expand Up @@ -1936,6 +1954,7 @@ public void testAvroLogRecordReaderWithMixedInsertsCorruptsRollbackAndMergedLogB
assertEquals(expectedBlockInstants, validBlockInstants);
Collections.sort(readKeys);
assertEquals(expectedRecords, readKeys, "Record keys read should be exactly same.");
scanner.close();
}

/*
Expand Down Expand Up @@ -2013,7 +2032,7 @@ private void testAvroLogRecordReaderMergingMultipleLogFiles(int numRecordsInLog1

assertEquals(Math.max(numRecordsInLog1, numRecordsInLog2), scanner.getNumMergedRecordsInLog(),
"We would read 100 records");

scanner.close();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit cd67964

Please sign in to comment.