mirror of https://github.com/apache/kafka.git
KAFKA-16551 add integration test with bootstrap controller for ClusterTool (#16439)
Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
parent
63304fb6e5
commit
f995edccad
|
@ -18,10 +18,12 @@ package org.apache.kafka.tools;
|
||||||
|
|
||||||
import kafka.test.ClusterInstance;
|
import kafka.test.ClusterInstance;
|
||||||
import kafka.test.annotation.ClusterTest;
|
import kafka.test.annotation.ClusterTest;
|
||||||
|
import kafka.test.annotation.Type;
|
||||||
import kafka.test.junit.ClusterTestExtensions;
|
import kafka.test.junit.ClusterTestExtensions;
|
||||||
|
|
||||||
import org.apache.kafka.clients.admin.Admin;
|
import org.apache.kafka.clients.admin.Admin;
|
||||||
import org.apache.kafka.clients.admin.MockAdminClient;
|
import org.apache.kafka.clients.admin.MockAdminClient;
|
||||||
|
import org.apache.kafka.common.errors.UnsupportedEndpointTypeException;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.Timeout;
|
import org.junit.jupiter.api.Timeout;
|
||||||
|
@ -30,9 +32,12 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@Timeout(value = 60)
|
@Timeout(value = 60)
|
||||||
|
@ -67,6 +72,28 @@ public class ClusterToolTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ClusterTest(types = {Type.KRAFT, Type.CO_KRAFT})
|
||||||
|
public void testClusterIdWithBootstrapController(ClusterInstance clusterInstance) {
|
||||||
|
String output = ToolsTestUtils.captureStandardOut(() ->
|
||||||
|
assertDoesNotThrow(() -> ClusterTool.execute("cluster-id", "--bootstrap-controller", clusterInstance.bootstrapControllers())));
|
||||||
|
assertTrue(output.contains("Cluster ID: " + clusterInstance.clusterId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ClusterTest(brokers = 3, types = {Type.KRAFT, Type.CO_KRAFT})
|
||||||
|
public void testUnregisterWithBootstrapController(ClusterInstance clusterInstance) {
|
||||||
|
Set<Integer> brokerIds = clusterInstance.brokerIds();
|
||||||
|
brokerIds.removeAll(clusterInstance.controllerIds());
|
||||||
|
int brokerId = assertDoesNotThrow(() -> brokerIds.stream().findFirst().get());
|
||||||
|
clusterInstance.shutdownBroker(brokerId);
|
||||||
|
ExecutionException exception =
|
||||||
|
assertThrows(ExecutionException.class,
|
||||||
|
() -> ClusterTool.execute("unregister", "--bootstrap-controller", clusterInstance.bootstrapControllers(), "--id", String.valueOf(brokerId)));
|
||||||
|
assertNotNull(exception.getCause());
|
||||||
|
assertEquals(UnsupportedEndpointTypeException.class, exception.getCause().getClass());
|
||||||
|
assertEquals("This Admin API is not yet supported when communicating directly with " +
|
||||||
|
"the controller quorum.", exception.getCause().getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrintClusterId() throws Exception {
|
public void testPrintClusterId() throws Exception {
|
||||||
Admin adminClient = new MockAdminClient.Builder().
|
Admin adminClient = new MockAdminClient.Builder().
|
||||||
|
|
Loading…
Reference in New Issue