Class KafkaClusterTestKit

java.lang.Object
org.apache.kafka.common.test.KafkaClusterTestKit
All Implemented Interfaces:
AutoCloseable

public class KafkaClusterTestKit extends Object implements AutoCloseable
  • Method Details

    • format

      public void format() throws Exception
      Throws:
      Exception
    • startup

    • restartBrokersWithSwappedClientListenerPorts

      public void restartBrokersWithSwappedClientListenerPorts(int nodeId1, int nodeId2) throws IOException
      Stops and restarts the brokers with swapped client listener ports. This simulates a network routing anomaly, such as a misconfigured proxy. Clients should rebootstrap, reconnect and continue working.
      Parameters:
      nodeId1 - The ID of the first broker.
      nodeId2 - The ID of the second broker.
      Throws:
      IOException
    • restartBroker

      public void restartBroker(int nodeId, Map<String,Object> propOverrides)
      Shuts down the given broker (if it isn't already) and starts it back up with a possibly modified static configuration. This allows tests to change read-only configs, such as log.dirs, which can only be applied when the broker process (re)starts.

      The broker keeps its identity (node ID, cluster metadata, bound ports): a new SharedServer/BrokerServer pair is created from the previous broker's MetaPropertiesEnsemble and socket factory, but with a KafkaConfig derived from the previous one with propOverrides applied on top.

      Parameters:
      nodeId - The ID of the broker to restart.
      propOverrides - Configs to override in the broker's static configuration.
    • waitForReadyBrokers

      public void waitForReadyBrokers() throws ExecutionException, InterruptedException
      Wait for a controller to mark all the brokers as ready (registered and unfenced). And also wait for the metadata cache up-to-date in each broker server.
      Throws:
      ExecutionException
      InterruptedException
    • admin

      public org.apache.kafka.clients.admin.Admin admin()
    • admin

      public org.apache.kafka.clients.admin.Admin admin(Map<String,Object> configs)
    • admin

      public org.apache.kafka.clients.admin.Admin admin(Map<String,Object> configs, boolean usingBootstrapControllers)
    • bootstrapServers

      public String bootstrapServers()
    • bootstrapControllers

      public String bootstrapControllers()
    • controllers

      public Map<Integer, kafka.server.ControllerServer> controllers()
    • interBrokerPortFuture

      public scala.Option<CompletableFuture<Integer>> interBrokerPortFuture()
    • waitForActiveController

      public org.apache.kafka.controller.Controller waitForActiveController() throws InterruptedException
      Throws:
      InterruptedException
    • brokers

      public Map<Integer, kafka.server.BrokerServer> brokers()
    • raftManagers

      public Map<Integer, kafka.raft.KafkaRaftManager<org.apache.kafka.server.common.ApiMessageAndVersion>> raftManagers()
    • nodes

      public TestKitNodes nodes()
    • fatalFaultHandler

      public MockFaultHandler fatalFaultHandler()
    • nonFatalFaultHandler

      public MockFaultHandler nonFatalFaultHandler()
    • sslManager

      public SslManager sslManager()
    • shutdownAll

      public void shutdownAll() throws Exception
      Throws:
      Exception
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • clusterId

      public String clusterId()