Skip to content

Commit 9b3b5c3

Browse files
committed
fix closing issue
1 parent a51bcde commit 9b3b5c3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

storage/src/test/java/org/apache/kafka/storage/internals/log/UnifiedLogTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.kafka.common.Uuid;
2020
import org.apache.kafka.common.compress.Compression;
21+
import org.apache.kafka.common.errors.KafkaStorageException;
2122
import org.apache.kafka.common.record.ControlRecordType;
2223
import org.apache.kafka.common.record.EndTransactionMarker;
2324
import org.apache.kafka.common.record.MemoryRecords;
@@ -65,7 +66,13 @@ public class UnifiedLogTest {
6566
public void tearDown() throws IOException {
6667
brokerTopicStats.close();
6768
for (UnifiedLog log : logsToClose) {
68-
log.close();
69+
try {
70+
// some test like testLogDeletionAfterClose and testLogDeletionAfterClose
71+
// they are closed from test so KafkaStorageException is expected.
72+
log.close();
73+
} catch (KafkaStorageException ignore) {
74+
// ignore
75+
}
6976
}
7077
Utils.delete(tmpDir);
7178
}
@@ -460,6 +467,7 @@ public void testDeleteOldSegments() throws IOException {
460467
log.assignEpochStartOffset(0, 40);
461468
log.assignEpochStartOffset(1, 90);
462469

470+
// segments are not eligible for deletion if no high watermark has been set
463471
int numSegments = log.numberOfSegments();
464472
log.deleteOldSegments();
465473
assertEquals(numSegments, log.numberOfSegments());
@@ -579,7 +587,7 @@ public void testFirstUnstableOffsetWithTransactionalData() throws IOException {
579587
assertEquals(Optional.of(firstAppendInfo.firstOffset()), log.firstUnstableOffset());
580588

581589
// now transaction is committed
582-
LogAppendInfo commitAppendInfo = appendEndTxnMarkerAsLeader(log, pid, epoch, ControlRecordType.COMMIT, mockTime.milliseconds());
590+
LogAppendInfo commitAppendInfo = LogTestUtils.appendEndTxnMarkerAsLeader(log, pid, epoch, ControlRecordType.COMMIT, mockTime.milliseconds(), 0, 0);
583591

584592
// first unstable offset is not updated until the high watermark is advanced
585593
assertEquals(Optional.of(firstAppendInfo.firstOffset()), log.firstUnstableOffset());

0 commit comments

Comments
 (0)