Skip to content

Commit bec089c

Browse files
authored
MINOR: Close leaked RemoteLogManager instances in RemoteLogManagerTest (#23604)
Three tests in `RemoteLogManagerTest` leaked a `RemoteLogManager`, so its scheduler threads and metrics outlived the test and could interfere with the tests that follow Reviewers: Chia-Ping Tsai [chia7712@gmail.com](mailto:chia7712@gmail.com), liuliu <liuliugit@gmail.com>, Ken Huang <s7133700@gmail.com>
1 parent adf8c4c commit bec089c

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

‎storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteLogManagerTest.java‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,7 @@ void testFetchOffsetByTimestampWithTieredStorageDoesNotFetchIndexWhenExistsLocal
18001800
});
18011801

18021802
when(mockLog.logEndOffset()).thenReturn(300L);
1803+
remoteLogManager.close();
18031804
remoteLogManager = new RemoteLogManager(config, brokerId, logDir, clusterId, time,
18041805
partition -> Optional.of(mockLog),
18051806
(topicPartition, offset) -> currentLogStartOffset.set(offset),
@@ -2617,6 +2618,7 @@ public synchronized Iterator<RemoteLogSegmentMetadata> listRemoteLogSegments(Top
26172618
}
26182619
};
26192620

2621+
remoteLogManager.close();
26202622
remoteLogManager = new RemoteLogManager(config, brokerId, logDir, clusterId, time,
26212623
tp -> Optional.of(mockLog),
26222624
(topicPartition, offset) -> currentLogStartOffset.set(offset),
@@ -4185,7 +4187,7 @@ public void testRemoteReadFetchDataInfo() throws RemoteStorageException, IOExcep
41854187
when(remoteStorageManager.fetchLogSegment(any(RemoteLogSegmentMetadata.class), anyInt()))
41864188
.thenReturn(fileInputStream);
41874189

4188-
RemoteLogManager remoteLogManager = new RemoteLogManager(config, brokerId, logDir, clusterId, time,
4190+
try (RemoteLogManager remoteLogManager = new RemoteLogManager(config, brokerId, logDir, clusterId, time,
41894191
tp -> Optional.of(mockLog),
41904192
(topicPartition, offset) -> currentLogStartOffset.set(offset),
41914193
brokerTopicStats, metrics, endPoint) {
@@ -4201,20 +4203,21 @@ public RemoteLogMetadataManager createRemoteLogMetadataManager() {
42014203
int lookupPositionForOffset(RemoteLogSegmentMetadata remoteLogSegmentMetadata, long offset) {
42024204
return 0;
42034205
}
4204-
};
4205-
remoteLogManager.onLeadershipChange(
4206-
Set.of(mockPartition(leaderTopicIdPartition)), Set.of(), topicIds);
4207-
4208-
long fetchOffset = 10;
4209-
FetchRequest.PartitionData partitionData = new FetchRequest.PartitionData(
4210-
Uuid.randomUuid(), fetchOffset, 0, 100, Optional.empty());
4211-
RemoteStorageFetchInfo remoteStorageFetchInfo = new RemoteStorageFetchInfo(
4212-
1048576, true, leaderTopicIdPartition,
4213-
partitionData, FetchIsolation.HIGH_WATERMARK);
4214-
FetchDataInfo fetchDataInfo = remoteLogManager.read(remoteStorageFetchInfo);
4215-
// firstBatch baseOffset may not be equal to the fetchOffset
4216-
assertEquals(9, fetchDataInfo.fetchOffsetMetadata.messageOffset);
4217-
assertEquals(273, fetchDataInfo.fetchOffsetMetadata.relativePositionInSegment);
4206+
}) {
4207+
remoteLogManager.onLeadershipChange(
4208+
Set.of(mockPartition(leaderTopicIdPartition)), Set.of(), topicIds);
4209+
4210+
long fetchOffset = 10;
4211+
FetchRequest.PartitionData partitionData = new FetchRequest.PartitionData(
4212+
Uuid.randomUuid(), fetchOffset, 0, 100, Optional.empty());
4213+
RemoteStorageFetchInfo remoteStorageFetchInfo = new RemoteStorageFetchInfo(
4214+
1048576, true, leaderTopicIdPartition,
4215+
partitionData, FetchIsolation.HIGH_WATERMARK);
4216+
FetchDataInfo fetchDataInfo = remoteLogManager.read(remoteStorageFetchInfo);
4217+
// firstBatch baseOffset may not be equal to the fetchOffset
4218+
assertEquals(9, fetchDataInfo.fetchOffsetMetadata.messageOffset);
4219+
assertEquals(273, fetchDataInfo.fetchOffsetMetadata.relativePositionInSegment);
4220+
}
42184221
}
42194222

42204223
@Test

0 commit comments

Comments
 (0)