kowshik commented on a change in pull request #10592: URL: https://github.com/apache/kafka/pull/10592#discussion_r619682506
########## File path: core/src/test/scala/unit/kafka/log/LogSegmentsTest.scala ########## @@ -35,6 +39,17 @@ class LogSegmentsTest { LogTestUtils.createSegment(offset, logDir, indexIntervalBytes, time) } + @BeforeEach + def setup(): Unit = { + logDir = TestUtils.tempDir() + } + + @AfterEach + def teardown(): Unit = { + segmentsBuffer.foreach(_.close()) Review comment: The segments are already closed from inside `LogSegments#close()` and therefore can be skipped in the `tearDown()`. https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/log/LogSegments.scala#L78 ########## File path: core/src/test/scala/unit/kafka/log/LogSegmentsTest.scala ########## @@ -129,12 +149,13 @@ class LogSegmentsTest { assertEquals(Seq(seg3), segments.values(3, 4).toSeq) assertEquals(Seq(), segments.values(4, 4).toSeq) assertEquals(Seq(seg4), segments.values(4, 5).toSeq) - Review comment: Lets add a `segments.close()` call here. ########## File path: core/src/test/scala/unit/kafka/log/LogSegmentsTest.scala ########## @@ -129,12 +149,13 @@ class LogSegmentsTest { assertEquals(Seq(seg3), segments.values(3, 4).toSeq) assertEquals(Seq(), segments.values(4, 4).toSeq) assertEquals(Seq(seg4), segments.values(4, 5).toSeq) - } @Test def testClosestMatchOperations(): Unit = { val segments = new LogSegments(topicPartition) Review comment: Lets add a `segments.close()` call at the end of this function. ########## File path: core/src/test/scala/unit/kafka/log/LogSegmentsTest.scala ########## @@ -18,15 +18,19 @@ package kafka.log import java.io.File +import kafka.utils.TestUtils import org.apache.kafka.common.TopicPartition -import org.apache.kafka.common.utils.Time +import org.apache.kafka.common.utils.{Time, Utils} import org.junit.jupiter.api.Assertions._ -import org.junit.jupiter.api.Test +import org.junit.jupiter.api.{AfterEach, BeforeEach, Test} + +import scala.collection.mutable class LogSegmentsTest { val topicPartition = new TopicPartition("topic", 0) var logDir: File = _ + val segmentsBuffer: mutable.ArrayBuffer[LogSegments] = mutable.ArrayBuffer[LogSegments]() Review comment: This buffer can be removed, as I described below by calling `LogSegments#close()` inside each test. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org