showuon commented on code in PR #15616: URL: https://github.com/apache/kafka/pull/15616#discussion_r1574049613
########## core/src/test/scala/unit/kafka/server/AlterReplicaLogDirsRequestTest.scala: ########## @@ -116,6 +123,57 @@ class AlterReplicaLogDirsRequestTest extends BaseRequestTest { assertEquals(Errors.KAFKA_STORAGE_ERROR, findErrorForPartition(alterReplicaDirResponse3, new TopicPartition(topic, 2))) } + @Test + def testAlterReplicaLogDirsRequestWithRetention(): Unit = { + val partitionNum = 1 + + // Alter replica dir before topic creation + val logDir1 = new File(servers.head.config.logDirs(1)).getAbsolutePath + val partitionDirs1 = (0 until partitionNum).map(partition => new TopicPartition(topic, partition) -> logDir1).toMap + val alterReplicaLogDirsResponse1 = sendAlterReplicaLogDirsRequest(partitionDirs1) + + // The response should show error UNKNOWN_TOPIC_OR_PARTITION for all partitions + val tp = new TopicPartition(topic, 0) + assertEquals(Errors.UNKNOWN_TOPIC_OR_PARTITION, findErrorForPartition(alterReplicaLogDirsResponse1, tp)) + assertTrue(servers.head.logManager.getLog(tp).isEmpty) + + val topicProperties = new Properties() + topicProperties.put(TopicConfig.RETENTION_BYTES_CONFIG, "1024") + topicProperties.put(TopicConfig.FILE_DELETE_DELAY_MS_CONFIG, "10000") + topicProperties.put(TopicConfig.SEGMENT_BYTES_CONFIG, "1024") + + createTopic(topic, partitionNum, 1, topicProperties) + assertEquals(logDir1, servers.head.logManager.getLog(tp).get.dir.getParent) + + // send enough records to trigger log rolling + (0 until 20).foreach { _ => + TestUtils.generateAndProduceMessages(servers, topic, 10, 1) + } + TestUtils.waitUntilTrue(() => servers.head.logManager.getLog(new TopicPartition(topic, 0)).get.numberOfSegments > 1, + "timed out waiting for log segment to roll") + + // Wait for log segment retention. Override initialTaskDelayMs as 5 seconds. + // The first retention task is executed after 5 seconds, so waiting for 10 seconds should be enough. + TestUtils.waitUntilTrue(() => { + new File(logDir1, tp.toString).listFiles().count(_.getName.endsWith(LogFileUtils.DELETED_FILE_SUFFIX)) > 0 + }, "timed out waiting for log segment to retention", 10000) Review Comment: nit: I think we can leave the timeout as default value. That is, removing the 3rd parameter directly. ########## core/src/test/scala/unit/kafka/server/AlterReplicaLogDirsRequestTest.scala: ########## @@ -37,6 +40,10 @@ class AlterReplicaLogDirsRequestTest extends BaseRequestTest { val topic = "topic" + override def brokerPropertyOverrides(properties: Properties): Unit = { + properties.put(ServerLogConfigs.LOG_INITIAL_TASK_DELAY_MS_CONFIG, "5000") Review Comment: Why do we need to wait 5 secs for it? I would say we can set to 0 to speed up the test. WDYT? -- 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. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org