mirror of https://github.com/apache/kafka.git
KAFKA-17039 KIP-919 supports for unregisterBroker (#19063)
Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
parent
2ccc73783e
commit
e0c77140b2
|
@ -4729,7 +4729,7 @@ public class KafkaAdminClient extends AdminClient {
|
|||
final KafkaFutureImpl<Void> future = new KafkaFutureImpl<>();
|
||||
final long now = time.milliseconds();
|
||||
final Call call = new Call("unregisterBroker", calcDeadlineMs(now, options.timeoutMs()),
|
||||
new LeastLoadedNodeProvider()) {
|
||||
new LeastLoadedBrokerOrActiveKController()) {
|
||||
|
||||
@Override
|
||||
UnregisterBrokerRequest.Builder createRequest(int timeoutMs) {
|
||||
|
|
|
@ -833,8 +833,9 @@ class KRaftClusterTest {
|
|||
Option(image.brokers().get(brokerId)).isEmpty
|
||||
}
|
||||
|
||||
@Test
|
||||
def testUnregisterBroker(): Unit = {
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = Array(true, false))
|
||||
def testUnregisterBroker(usingBootstrapController: Boolean): Unit = {
|
||||
val cluster = new KafkaClusterTestKit.Builder(
|
||||
new TestKitNodes.Builder().
|
||||
setNumBrokerNodes(4).
|
||||
|
@ -848,7 +849,7 @@ class KRaftClusterTest {
|
|||
cluster.brokers().get(0).shutdown()
|
||||
TestUtils.waitUntilTrue(() => !brokerIsUnfenced(clusterImage(cluster, 1), 0),
|
||||
"Timed out waiting for broker 0 to be fenced.")
|
||||
val admin = Admin.create(cluster.clientProperties())
|
||||
val admin = createAdminClient(cluster, bootstrapController = usingBootstrapController);
|
||||
try {
|
||||
admin.unregisterBroker(0)
|
||||
} finally {
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.kafka.tools;
|
|||
|
||||
import org.apache.kafka.clients.admin.Admin;
|
||||
import org.apache.kafka.clients.admin.MockAdminClient;
|
||||
import org.apache.kafka.common.errors.UnsupportedEndpointTypeException;
|
||||
import org.apache.kafka.common.test.ClusterInstance;
|
||||
import org.apache.kafka.common.test.api.ClusterTest;
|
||||
import org.apache.kafka.common.test.api.Type;
|
||||
|
@ -30,12 +29,10 @@ import java.io.PrintStream;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
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;
|
||||
|
||||
|
@ -102,13 +99,7 @@ public class ClusterToolTest {
|
|||
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());
|
||||
assertDoesNotThrow(() -> ClusterTool.execute("unregister", "--bootstrap-controller", clusterInstance.bootstrapControllers(), "--id", String.valueOf(brokerId)));
|
||||
}
|
||||
|
||||
@ClusterTest(brokers = 3, types = {Type.KRAFT, Type.CO_KRAFT})
|
||||
|
|
Loading…
Reference in New Issue