MINOR: Delete temporary directories after using them in RaftManagerTest Updated (#20550)

Follow-up to [#11193](https://github.com/apache/kafka/pull/11193). This
change adds cleanup of the temporary log and metadata directories
created by RaftManagerTest so they are removed after each test run.
Without this cleanup, the directories remain until the entire test suite
completes, leaving extra files in the system temporary directory.

Testing:
- Ran `./gradlew core:test --tests kafka.raft.RaftManagerTest` and
confirmed all tests pass.

Reviewers: TengYao Chi <kitingiao@gmail.com>, Chia-Ping Tsai
 <chia7712@gmail.com>
This commit is contained in:
Ryan Dielhenn 2025-09-18 19:22:05 -07:00 committed by GitHub
parent 5ed4a48829
commit b72db2b2c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 49 additions and 34 deletions

View File

@ -30,6 +30,7 @@ import org.apache.kafka.common.Uuid
import org.apache.kafka.common.metrics.Metrics
import org.apache.kafka.common.network.ListenerName
import org.apache.kafka.common.utils.Time
import org.apache.kafka.common.utils.Utils
import org.apache.kafka.network.SocketServerConfigs
import org.apache.kafka.raft.{Endpoints, MetadataLogConfig, QuorumConfig}
import org.apache.kafka.server.ProcessRole
@ -126,6 +127,7 @@ class RaftManagerTest {
val logDir = TestUtils.tempDir()
val nodeId = 1
try {
val raftManager = createRaftManager(
new TopicPartition("__raft_id_test", 0),
createConfig(
@ -137,6 +139,9 @@ class RaftManagerTest {
)
assertEquals(nodeId, raftManager.client.nodeId.getAsInt)
raftManager.shutdown()
} finally {
Utils.delete(logDir)
}
}
@ParameterizedTest
@ -155,6 +160,7 @@ class RaftManagerTest {
}
val nodeId = 1
try {
val raftManager = createRaftManager(
new TopicPartition("__raft_id_test", 0),
createConfig(
@ -171,6 +177,10 @@ class RaftManagerTest {
raftManager.shutdown()
assertFalse(fileLocked(lockPath))
} finally {
logDir.foreach(p => Utils.delete(p.toFile))
metadataDir.foreach(p => Utils.delete(p.toFile))
}
}
@Test
@ -179,6 +189,7 @@ class RaftManagerTest {
val metadataDir = Some(TestUtils.tempDir().toPath)
val nodeId = 1
try {
val raftManager = createRaftManager(
new TopicPartition("__raft_id_test", 0),
createConfig(
@ -195,6 +206,10 @@ class RaftManagerTest {
raftManager.shutdown()
assertFalse(fileLocked(lockPath))
} finally {
logDir.foreach(p => Utils.delete(p.toFile))
metadataDir.foreach(p => Utils.delete(p.toFile))
}
}
def createMetadataLog(config: KafkaConfig): Unit = {