KAFKA-16679 merge unit test down to the class of integration test (#15884)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Cheng-Kai, Zhang 2024-05-11 10:38:23 -05:00 committed by GitHub
parent 47841e0bb9
commit 643db430a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 50 deletions

View File

@ -53,13 +53,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@Tag("integration") @Tag("integration")
public class DeleteRecordsCommandTest { public class DeleteRecordsCommandTest {
private final ClusterInstance cluster;
public DeleteRecordsCommandTest(ClusterInstance cluster) {
this.cluster = cluster;
}
@ClusterTest @ClusterTest
public void testCommand() throws Exception { public void testCommand(ClusterInstance cluster) throws Exception {
Properties adminProps = new Properties(); Properties adminProps = new Properties();
adminProps.put(AdminClientConfig.RETRIES_CONFIG, 1); adminProps.put(AdminClientConfig.RETRIES_CONFIG, 1);
@ -112,12 +107,11 @@ public class DeleteRecordsCommandTest {
}); });
assertTrue(output.contains(expOut)); assertTrue(output.contains(expOut));
} }
}
/** /**
* Unit test of {@link DeleteRecordsCommand} tool. * Unit test of {@link DeleteRecordsCommand} tool.
*/ */
class DeleteRecordsCommandUnitTest {
@Test @Test
public void testOffsetFileNotExists() { public void testOffsetFileNotExists() {
assertThrows(IOException.class, () -> DeleteRecordsCommand.execute(new String[]{ assertThrows(IOException.class, () -> DeleteRecordsCommand.execute(new String[]{

View File

@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import kafka.test.ClusterInstance; import kafka.test.ClusterInstance;
import kafka.test.annotation.ClusterTest; import kafka.test.annotation.ClusterTest;
import kafka.test.annotation.ClusterTestDefaults;
import kafka.test.annotation.Type; import kafka.test.annotation.Type;
import kafka.test.junit.ClusterTestExtensions; import kafka.test.junit.ClusterTestExtensions;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
@ -44,17 +43,10 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(value = ClusterTestExtensions.class) @ExtendWith(value = ClusterTestExtensions.class)
@ClusterTestDefaults(clusterType = Type.KRAFT)
@Tag("integration") @Tag("integration")
public class FeatureCommandTest { public class FeatureCommandTest {
private final ClusterInstance cluster;
public FeatureCommandTest(ClusterInstance cluster) {
this.cluster = cluster;
}
@ClusterTest(clusterType = Type.ZK, metadataVersion = MetadataVersion.IBP_3_3_IV1) @ClusterTest(clusterType = Type.ZK, metadataVersion = MetadataVersion.IBP_3_3_IV1)
public void testDescribeWithZK() { public void testDescribeWithZK(ClusterInstance cluster) {
String commandOutput = ToolsTestUtils.captureStandardOut(() -> String commandOutput = ToolsTestUtils.captureStandardOut(() ->
assertEquals(0, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(), "describe")) assertEquals(0, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(), "describe"))
); );
@ -62,7 +54,7 @@ public class FeatureCommandTest {
} }
@ClusterTest(clusterType = Type.KRAFT, metadataVersion = MetadataVersion.IBP_3_3_IV1) @ClusterTest(clusterType = Type.KRAFT, metadataVersion = MetadataVersion.IBP_3_3_IV1)
public void testDescribeWithKRaft() { public void testDescribeWithKRaft(ClusterInstance cluster) {
String commandOutput = ToolsTestUtils.captureStandardOut(() -> String commandOutput = ToolsTestUtils.captureStandardOut(() ->
assertEquals(0, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(), "describe")) assertEquals(0, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(), "describe"))
); );
@ -72,7 +64,7 @@ public class FeatureCommandTest {
} }
@ClusterTest(clusterType = Type.KRAFT, metadataVersion = MetadataVersion.IBP_3_7_IV4) @ClusterTest(clusterType = Type.KRAFT, metadataVersion = MetadataVersion.IBP_3_7_IV4)
public void testDescribeWithKRaftAndBootstrapControllers() { public void testDescribeWithKRaftAndBootstrapControllers(ClusterInstance cluster) {
String commandOutput = ToolsTestUtils.captureStandardOut(() -> String commandOutput = ToolsTestUtils.captureStandardOut(() ->
assertEquals(0, FeatureCommand.mainNoExit("--bootstrap-controller", cluster.bootstrapControllers(), "describe")) assertEquals(0, FeatureCommand.mainNoExit("--bootstrap-controller", cluster.bootstrapControllers(), "describe"))
); );
@ -82,7 +74,7 @@ public class FeatureCommandTest {
} }
@ClusterTest(clusterType = Type.ZK, metadataVersion = MetadataVersion.IBP_3_3_IV1) @ClusterTest(clusterType = Type.ZK, metadataVersion = MetadataVersion.IBP_3_3_IV1)
public void testUpgradeMetadataVersionWithZk() { public void testUpgradeMetadataVersionWithZk(ClusterInstance cluster) {
String commandOutput = ToolsTestUtils.captureStandardOut(() -> String commandOutput = ToolsTestUtils.captureStandardOut(() ->
assertEquals(1, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(), assertEquals(1, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
"upgrade", "--metadata", "3.3-IV2")) "upgrade", "--metadata", "3.3-IV2"))
@ -92,7 +84,7 @@ public class FeatureCommandTest {
} }
@ClusterTest(clusterType = Type.KRAFT, metadataVersion = MetadataVersion.IBP_3_3_IV1) @ClusterTest(clusterType = Type.KRAFT, metadataVersion = MetadataVersion.IBP_3_3_IV1)
public void testUpgradeMetadataVersionWithKraft() { public void testUpgradeMetadataVersionWithKraft(ClusterInstance cluster) {
String commandOutput = ToolsTestUtils.captureStandardOut(() -> String commandOutput = ToolsTestUtils.captureStandardOut(() ->
assertEquals(0, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(), assertEquals(0, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
"upgrade", "--feature", "metadata.version=5")) "upgrade", "--feature", "metadata.version=5"))
@ -107,7 +99,7 @@ public class FeatureCommandTest {
} }
@ClusterTest(clusterType = Type.ZK, metadataVersion = MetadataVersion.IBP_3_3_IV1) @ClusterTest(clusterType = Type.ZK, metadataVersion = MetadataVersion.IBP_3_3_IV1)
public void testDowngradeMetadataVersionWithZk() { public void testDowngradeMetadataVersionWithZk(ClusterInstance cluster) {
String commandOutput = ToolsTestUtils.captureStandardOut(() -> String commandOutput = ToolsTestUtils.captureStandardOut(() ->
assertEquals(1, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(), assertEquals(1, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
"disable", "--feature", "metadata.version")) "disable", "--feature", "metadata.version"))
@ -130,7 +122,7 @@ public class FeatureCommandTest {
} }
@ClusterTest(clusterType = Type.KRAFT, metadataVersion = MetadataVersion.IBP_3_3_IV1) @ClusterTest(clusterType = Type.KRAFT, metadataVersion = MetadataVersion.IBP_3_3_IV1)
public void testDowngradeMetadataVersionWithKRaft() { public void testDowngradeMetadataVersionWithKRaft(ClusterInstance cluster) {
String commandOutput = ToolsTestUtils.captureStandardOut(() -> String commandOutput = ToolsTestUtils.captureStandardOut(() ->
assertEquals(1, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(), assertEquals(1, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
"disable", "--feature", "metadata.version")) "disable", "--feature", "metadata.version"))
@ -160,9 +152,11 @@ public class FeatureCommandTest {
int pos = output.indexOf("Epoch: "); int pos = output.indexOf("Epoch: ");
return (pos > 0) ? output.substring(0, pos) : output; return (pos > 0) ? output.substring(0, pos) : output;
} }
}
class FeatureCommandUnitTest { /**
* Unit test of {@link FeatureCommand} tool.
*/
@Test @Test
public void testLevelToString() { public void testLevelToString() {
assertEquals("5", FeatureCommand.levelToString("foo.bar", (short) 5)); assertEquals("5", FeatureCommand.levelToString("foo.bar", (short) 5));
@ -177,7 +171,7 @@ class FeatureCommandUnitTest {
} }
@Test @Test
public void testdowngradeType() { public void testDowngradeType() {
assertEquals(SAFE_DOWNGRADE, FeatureCommand.downgradeType( assertEquals(SAFE_DOWNGRADE, FeatureCommand.downgradeType(
new Namespace(singletonMap("unsafe", Boolean.FALSE)))); new Namespace(singletonMap("unsafe", Boolean.FALSE))));
assertEquals(UNSAFE_DOWNGRADE, FeatureCommand.downgradeType( assertEquals(UNSAFE_DOWNGRADE, FeatureCommand.downgradeType(