mirror of https://github.com/apache/kafka.git
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:
parent
47841e0bb9
commit
643db430a7
|
@ -53,13 +53,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
@Tag("integration")
|
||||
public class DeleteRecordsCommandTest {
|
||||
|
||||
private final ClusterInstance cluster;
|
||||
public DeleteRecordsCommandTest(ClusterInstance cluster) {
|
||||
this.cluster = cluster;
|
||||
}
|
||||
|
||||
@ClusterTest
|
||||
public void testCommand() throws Exception {
|
||||
public void testCommand(ClusterInstance cluster) throws Exception {
|
||||
Properties adminProps = new Properties();
|
||||
|
||||
adminProps.put(AdminClientConfig.RETRIES_CONFIG, 1);
|
||||
|
@ -112,12 +107,11 @@ public class DeleteRecordsCommandTest {
|
|||
});
|
||||
assertTrue(output.contains(expOut));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit test of {@link DeleteRecordsCommand} tool.
|
||||
*/
|
||||
class DeleteRecordsCommandUnitTest {
|
||||
/**
|
||||
* Unit test of {@link DeleteRecordsCommand} tool.
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testOffsetFileNotExists() {
|
||||
assertThrows(IOException.class, () -> DeleteRecordsCommand.execute(new String[]{
|
||||
|
@ -168,7 +162,7 @@ class DeleteRecordsCommandUnitTest {
|
|||
"{\"topic\":\"t\", \"partition\":1, \"offset\":1, \"ignored\":\"field\"}," +
|
||||
"{\"topic\":\"t\", \"partition\":0, \"offset\":2}," +
|
||||
"{\"topic\":\"t\", \"partition\":0, \"offset\":0}" +
|
||||
"]}"
|
||||
"]}"
|
||||
);
|
||||
|
||||
assertEquals(2, res.size());
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import kafka.test.ClusterInstance;
|
||||
import kafka.test.annotation.ClusterTest;
|
||||
import kafka.test.annotation.ClusterTestDefaults;
|
||||
import kafka.test.annotation.Type;
|
||||
import kafka.test.junit.ClusterTestExtensions;
|
||||
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;
|
||||
|
||||
@ExtendWith(value = ClusterTestExtensions.class)
|
||||
@ClusterTestDefaults(clusterType = Type.KRAFT)
|
||||
@Tag("integration")
|
||||
public class FeatureCommandTest {
|
||||
|
||||
private final ClusterInstance cluster;
|
||||
public FeatureCommandTest(ClusterInstance cluster) {
|
||||
this.cluster = cluster;
|
||||
}
|
||||
|
||||
@ClusterTest(clusterType = Type.ZK, metadataVersion = MetadataVersion.IBP_3_3_IV1)
|
||||
public void testDescribeWithZK() {
|
||||
public void testDescribeWithZK(ClusterInstance cluster) {
|
||||
String commandOutput = ToolsTestUtils.captureStandardOut(() ->
|
||||
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)
|
||||
public void testDescribeWithKRaft() {
|
||||
public void testDescribeWithKRaft(ClusterInstance cluster) {
|
||||
String commandOutput = ToolsTestUtils.captureStandardOut(() ->
|
||||
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)
|
||||
public void testDescribeWithKRaftAndBootstrapControllers() {
|
||||
public void testDescribeWithKRaftAndBootstrapControllers(ClusterInstance cluster) {
|
||||
String commandOutput = ToolsTestUtils.captureStandardOut(() ->
|
||||
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)
|
||||
public void testUpgradeMetadataVersionWithZk() {
|
||||
public void testUpgradeMetadataVersionWithZk(ClusterInstance cluster) {
|
||||
String commandOutput = ToolsTestUtils.captureStandardOut(() ->
|
||||
assertEquals(1, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
|
||||
"upgrade", "--metadata", "3.3-IV2"))
|
||||
|
@ -92,7 +84,7 @@ public class FeatureCommandTest {
|
|||
}
|
||||
|
||||
@ClusterTest(clusterType = Type.KRAFT, metadataVersion = MetadataVersion.IBP_3_3_IV1)
|
||||
public void testUpgradeMetadataVersionWithKraft() {
|
||||
public void testUpgradeMetadataVersionWithKraft(ClusterInstance cluster) {
|
||||
String commandOutput = ToolsTestUtils.captureStandardOut(() ->
|
||||
assertEquals(0, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
|
||||
"upgrade", "--feature", "metadata.version=5"))
|
||||
|
@ -107,7 +99,7 @@ public class FeatureCommandTest {
|
|||
}
|
||||
|
||||
@ClusterTest(clusterType = Type.ZK, metadataVersion = MetadataVersion.IBP_3_3_IV1)
|
||||
public void testDowngradeMetadataVersionWithZk() {
|
||||
public void testDowngradeMetadataVersionWithZk(ClusterInstance cluster) {
|
||||
String commandOutput = ToolsTestUtils.captureStandardOut(() ->
|
||||
assertEquals(1, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
|
||||
"disable", "--feature", "metadata.version"))
|
||||
|
@ -130,7 +122,7 @@ public class FeatureCommandTest {
|
|||
}
|
||||
|
||||
@ClusterTest(clusterType = Type.KRAFT, metadataVersion = MetadataVersion.IBP_3_3_IV1)
|
||||
public void testDowngradeMetadataVersionWithKRaft() {
|
||||
public void testDowngradeMetadataVersionWithKRaft(ClusterInstance cluster) {
|
||||
String commandOutput = ToolsTestUtils.captureStandardOut(() ->
|
||||
assertEquals(1, FeatureCommand.mainNoExit("--bootstrap-server", cluster.bootstrapServers(),
|
||||
"disable", "--feature", "metadata.version"))
|
||||
|
@ -160,28 +152,30 @@ public class FeatureCommandTest {
|
|||
int pos = output.indexOf("Epoch: ");
|
||||
return (pos > 0) ? output.substring(0, pos) : output;
|
||||
}
|
||||
}
|
||||
|
||||
class FeatureCommandUnitTest {
|
||||
/**
|
||||
* Unit test of {@link FeatureCommand} tool.
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testLevelToString() {
|
||||
assertEquals("5", FeatureCommand.levelToString("foo.bar", (short) 5));
|
||||
assertEquals("3.3-IV0",
|
||||
FeatureCommand.levelToString(MetadataVersion.FEATURE_NAME, MetadataVersion.IBP_3_3_IV0.featureLevel()));
|
||||
FeatureCommand.levelToString(MetadataVersion.FEATURE_NAME, MetadataVersion.IBP_3_3_IV0.featureLevel()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetadataVersionsToString() {
|
||||
assertEquals("3.3-IV0, 3.3-IV1, 3.3-IV2, 3.3-IV3",
|
||||
FeatureCommand.metadataVersionsToString(MetadataVersion.IBP_3_3_IV0, MetadataVersion.IBP_3_3_IV3));
|
||||
FeatureCommand.metadataVersionsToString(MetadataVersion.IBP_3_3_IV0, MetadataVersion.IBP_3_3_IV3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testdowngradeType() {
|
||||
public void testDowngradeType() {
|
||||
assertEquals(SAFE_DOWNGRADE, FeatureCommand.downgradeType(
|
||||
new Namespace(singletonMap("unsafe", Boolean.FALSE))));
|
||||
new Namespace(singletonMap("unsafe", Boolean.FALSE))));
|
||||
assertEquals(UNSAFE_DOWNGRADE, FeatureCommand.downgradeType(
|
||||
new Namespace(singletonMap("unsafe", Boolean.TRUE))));
|
||||
new Namespace(singletonMap("unsafe", Boolean.TRUE))));
|
||||
assertEquals(SAFE_DOWNGRADE, FeatureCommand.downgradeType(new Namespace(emptyMap())));
|
||||
}
|
||||
|
||||
|
@ -190,9 +184,9 @@ class FeatureCommandUnitTest {
|
|||
assertArrayEquals(new String[]{"foo.bar", "5"}, FeatureCommand.parseNameAndLevel("foo.bar=5"));
|
||||
assertArrayEquals(new String[]{"quux", "0"}, FeatureCommand.parseNameAndLevel("quux=0"));
|
||||
assertTrue(assertThrows(RuntimeException.class, () -> FeatureCommand.parseNameAndLevel("baaz"))
|
||||
.getMessage().contains("Can't parse feature=level string baaz: equals sign not found."));
|
||||
.getMessage().contains("Can't parse feature=level string baaz: equals sign not found."));
|
||||
assertTrue(assertThrows(RuntimeException.class, () -> FeatureCommand.parseNameAndLevel("w=tf"))
|
||||
.getMessage().contains("Can't parse feature=level string w=tf: unable to parse tf as a short."));
|
||||
.getMessage().contains("Can't parse feature=level string w=tf: unable to parse tf as a short."));
|
||||
}
|
||||
|
||||
private static MockAdminClient buildAdminClient() {
|
||||
|
@ -209,9 +203,9 @@ class FeatureCommandUnitTest {
|
|||
maxSupportedFeatureLevels.put("foo.bar", (short) 10);
|
||||
|
||||
return new MockAdminClient.Builder().
|
||||
minSupportedFeatureLevels(minSupportedFeatureLevels).
|
||||
featureLevels(featureLevels).
|
||||
maxSupportedFeatureLevels(maxSupportedFeatureLevels).build();
|
||||
minSupportedFeatureLevels(minSupportedFeatureLevels).
|
||||
featureLevels(featureLevels).
|
||||
maxSupportedFeatureLevels(maxSupportedFeatureLevels).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -224,7 +218,7 @@ class FeatureCommandUnitTest {
|
|||
}
|
||||
});
|
||||
assertEquals(format("Feature: foo.bar\tSupportedMinVersion: 0\tSupportedMaxVersion: 10\tFinalizedVersionLevel: 5\tEpoch: 123%n" +
|
||||
"Feature: metadata.version\tSupportedMinVersion: 3.3-IV0\tSupportedMaxVersion: 3.3-IV3\tFinalizedVersionLevel: 3.3-IV2\tEpoch: 123"), describeResult);
|
||||
"Feature: metadata.version\tSupportedMinVersion: 3.3-IV0\tSupportedMaxVersion: 3.3-IV3\tFinalizedVersionLevel: 3.3-IV2\tEpoch: 123"), describeResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -238,7 +232,7 @@ class FeatureCommandUnitTest {
|
|||
assertTrue(t.getMessage().contains("1 out of 2 operation(s) failed."));
|
||||
});
|
||||
assertEquals(format("foo.bar was upgraded to 6.%n" +
|
||||
"Could not upgrade metadata.version to 5. Can't upgrade to lower version."), upgradeOutput);
|
||||
"Could not upgrade metadata.version to 5. Can't upgrade to lower version."), upgradeOutput);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -252,7 +246,7 @@ class FeatureCommandUnitTest {
|
|||
assertTrue(t.getMessage().contains("1 out of 2 operation(s) failed."));
|
||||
});
|
||||
assertEquals(format("foo.bar can be upgraded to 6.%n" +
|
||||
"Can not upgrade metadata.version to 5. Can't upgrade to lower version."), upgradeOutput);
|
||||
"Can not upgrade metadata.version to 5. Can't upgrade to lower version."), upgradeOutput);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -266,7 +260,7 @@ class FeatureCommandUnitTest {
|
|||
assertTrue(t.getMessage().contains("1 out of 2 operation(s) failed."));
|
||||
});
|
||||
assertEquals(format("foo.bar was downgraded to 1.%n" +
|
||||
"Could not downgrade metadata.version to 7. Can't downgrade to newer version."), downgradeOutput);
|
||||
"Could not downgrade metadata.version to 7. Can't downgrade to newer version."), downgradeOutput);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -280,7 +274,7 @@ class FeatureCommandUnitTest {
|
|||
assertTrue(t.getMessage().contains("1 out of 2 operation(s) failed."));
|
||||
});
|
||||
assertEquals(format("foo.bar can be downgraded to 1.%n" +
|
||||
"Can not downgrade metadata.version to 7. Can't downgrade to newer version."), downgradeOutput);
|
||||
"Can not downgrade metadata.version to 7. Can't downgrade to newer version."), downgradeOutput);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -293,8 +287,8 @@ class FeatureCommandUnitTest {
|
|||
assertTrue(t.getMessage().contains("1 out of 3 operation(s) failed."));
|
||||
});
|
||||
assertEquals(format("foo.bar was disabled.%n" +
|
||||
"Could not disable metadata.version. Can't downgrade below 4%n" +
|
||||
"quux was disabled."), disableOutput);
|
||||
"Could not disable metadata.version. Can't downgrade below 4%n" +
|
||||
"quux was disabled."), disableOutput);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -307,7 +301,7 @@ class FeatureCommandUnitTest {
|
|||
assertTrue(t.getMessage().contains("1 out of 3 operation(s) failed."));
|
||||
});
|
||||
assertEquals(format("foo.bar can be disabled.%n" +
|
||||
"Can not disable metadata.version. Can't downgrade below 4%n" +
|
||||
"quux can be disabled."), disableOutput);
|
||||
"Can not disable metadata.version. Can't downgrade below 4%n" +
|
||||
"quux can be disabled."), disableOutput);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue