jolshan commented on code in PR #16973: URL: https://github.com/apache/kafka/pull/16973#discussion_r1731885489
########## core/src/test/scala/unit/kafka/tools/StorageToolTest.scala: ########## @@ -433,5 +433,91 @@ Found problem: contains("Formatting dynamic metadata voter directory %s".format(availableDirs.head)), "Failed to find content in output: " + stream.toString()) } -} + private def runVersionMappingCommand( + stream: ByteArrayOutputStream, + properties: Properties, + releaseVersion: String + ): Int = { + val tempDir = TestUtils.tempDir() + try { + // Write the properties to a temporary file + val configPathString = new File(tempDir.getAbsolutePath, "version-mapping.props").toString + PropertiesUtils.writePropertiesFile(properties, configPathString, true) + + // Prepare the arguments list + val arguments = ListBuffer[String]("version-mapping") + + // Add the release version argument + if (releaseVersion != null) { + arguments += "--release-version" + arguments += releaseVersion + } + + arguments += "--config" + arguments += configPathString + + // Execute the StorageTool with the arguments + StorageTool.execute(arguments.toArray, new PrintStream(stream)) + + } finally { + Utils.delete(tempDir) + } + } + + @Test + def testVersionMappingWithValidReleaseVersion(): Unit = { + val properties = new Properties() + properties.putAll(defaultStaticQuorumProperties) + + val stream = new ByteArrayOutputStream() + // Test with a valid release version + assertEquals(0, runVersionMappingCommand(stream, properties, "3.3-IV3")) + + val output = stream.toString() + assertTrue(output.contains("metadata.version=7 (3.3-IV3)"), + s"Output did not contain expected Metadata Version: $output") + assertTrue(output.contains("kraft.version=0"), + s"Output did not contain expected feature mapping: $output") + assertTrue(output.contains("test.feature.version=0"), + s"Output did not contain expected feature mapping: $output") + assertTrue(output.contains("transaction.version=0"), + s"Output did not contain expected feature mapping: $output") + } + + @Test + def testVersionMappingWithNoReleaseVersion(): Unit = { + val properties = new Properties() + properties.putAll(defaultStaticQuorumProperties) + + val stream = new ByteArrayOutputStream() + assertEquals(0, runVersionMappingCommand(stream, properties, null)) + + val output = stream.toString + assertTrue(output.contains("metadata.version=21 (3.9-IV0)"), + s"Output did not contain expected feature mapping: $output") + assertTrue(output.contains("kraft.version=1"), + s"Output did not contain expected feature mapping: $output") + assertTrue(output.contains("test.feature.version=1"), + s"Output did not contain expected feature mapping: $output") + assertTrue(output.contains("transaction.version=0"), + s"Output did not contain expected feature mapping: $output") + } + + @Test + def testVersionMappingWithInvalidReleaseVersion(): Unit = { Review Comment: Can we have a test case for a completely malformed argument? like "abc" or something that isn't even a valid MV? -- 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