From 1dd26e07b33fed14f64cfd15fbbba9f962acd816 Mon Sep 17 00:00:00 2001 From: TaiJu Wu Date: Fri, 13 Sep 2024 23:34:52 +0800 Subject: [PATCH] address comments --- .../java/kafka/admin/ClientTelemetryTest.java | 18 ++++++++++++++++++ .../admin/ConfigCommandIntegrationTest.java | 12 ------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/core/src/test/java/kafka/admin/ClientTelemetryTest.java b/core/src/test/java/kafka/admin/ClientTelemetryTest.java index e7c1474027300..dd844e0b010a4 100644 --- a/core/src/test/java/kafka/admin/ClientTelemetryTest.java +++ b/core/src/test/java/kafka/admin/ClientTelemetryTest.java @@ -38,6 +38,7 @@ import org.apache.kafka.common.MetricName; import org.apache.kafka.common.TopicPartition; import org.apache.kafka.common.Uuid; +import org.apache.kafka.common.errors.InvalidConfigurationException; import org.apache.kafka.common.metrics.KafkaMetric; import org.apache.kafka.common.metrics.MetricsReporter; import org.apache.kafka.common.serialization.StringDeserializer; @@ -58,10 +59,13 @@ import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; +import java.util.stream.Stream; +import static java.util.Arrays.asList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @ExtendWith(value = ClusterTestExtensions.class) @@ -120,6 +124,20 @@ public void testClientInstanceId(ClusterInstance clusterInstance) throws Interru } } + private static String[] toArray(List... lists) { + return Stream.of(lists).flatMap(List::stream).toArray(String[]::new); + } + @ClusterTest(types = {Type.CO_KRAFT, Type.KRAFT}) + public void testIntervalMsParser(ClusterInstance clusterInstance) { + List alterOpts = asList("--bootstrap-server", clusterInstance.bootstrapServers(), + "--alter", "--entity-type", "client-metrics", "--entity-name", "test", "--add-config", "interval.ms=bbb"); + try (Admin client = clusterInstance.createAdminClient()) { + ConfigCommand.ConfigCommandOptions addOpts = new ConfigCommand.ConfigCommandOptions(toArray(alterOpts)); + + Throwable e = assertThrows(ExecutionException.class, () -> ConfigCommand.alterConfig(client, addOpts)); + assertTrue(e.getMessage().contains(InvalidConfigurationException.class.getSimpleName())); + } + } @ClusterTest(types = Type.KRAFT) public void testMetrics(ClusterInstance clusterInstance) { diff --git a/core/src/test/java/kafka/admin/ConfigCommandIntegrationTest.java b/core/src/test/java/kafka/admin/ConfigCommandIntegrationTest.java index 73b06e226108b..c2941847b274e 100644 --- a/core/src/test/java/kafka/admin/ConfigCommandIntegrationTest.java +++ b/core/src/test/java/kafka/admin/ConfigCommandIntegrationTest.java @@ -39,7 +39,6 @@ import org.apache.kafka.server.config.ZooKeeperInternals; import org.apache.kafka.test.TestUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.platform.commons.util.StringUtils; @@ -529,17 +528,6 @@ public void testUpdatePerBrokerConfigInKRaftThenShouldFail() { } } - @ClusterTest(types = {Type.CO_KRAFT, Type.KRAFT}) - public void testIntervalMsParser() { - alterOpts = asList("--bootstrap-server", cluster.bootstrapServers(), - "--alter", "--entity-type", "client-metrics", "--entity-name", "test"); - try (Admin client = cluster.createAdminClient()) { - Throwable e = assertThrows(ExecutionException.class, () -> - alterConfigWithKraft(client, Optional.of(defaultBrokerId), singletonMap("interval.ms", "aaa"))); - Assertions.assertTrue(e.getMessage().contains("InvalidConfigurationException")); - } - } - private void assertNonZeroStatusExit(Stream args, Consumer checkErrOut) { AtomicReference exitStatus = new AtomicReference<>(); Exit.setExitProcedure((status, __) -> {