Class AbstractKafkaTestResource<T extends AbstractKafkaTestResource<T>>

java.lang.Object
com.salesforce.kafka.test.AbstractKafkaTestResource<T>
Type Parameters:
T - The concrete implementation of this class, to allow for method chaining.

public abstract class AbstractKafkaTestResource<T extends AbstractKafkaTestResource<T>>
extends Object
Shared code between JUnit4 and JUnit5 shared resources.
  • Constructor Details

  • Method Details

    • withBrokerProperty

      public T withBrokerProperty​(String name, String value)
      Helper to allow overriding Kafka broker properties. Can only be called prior to the service being started.
      Parameters:
      name - Kafka broker configuration property name.
      value - Value to set for the configuration property.
      Returns:
      SharedKafkaTestResource instance for method chaining.
      Throws:
      IllegalArgumentException - if name argument is null.
      IllegalStateException - if method called after service has started.
    • withBrokers

      public T withBrokers​(int brokerCount)
      Set how many brokers to include in the test cluster.
      Parameters:
      brokerCount - The number of brokers.
      Returns:
      SharedKafkaTestResource for method chaining.
    • registerListener

      public T registerListener​(BrokerListener listener)
      Register additional listeners on the kafka brokers.
      Parameters:
      listener - listener instance to register.
      Returns:
      SharedKafkaTestResource for method chaining.
    • getKafkaTestUtils

      public KafkaTestUtils getKafkaTestUtils()
      KafkaTestUtils is a collection of re-usable/common access patterns for interacting with the Kafka cluster.
      Returns:
      Instance of KafkaTestUtils configured to operate on the Kafka cluster.
    • getZookeeperConnectString

      public String getZookeeperConnectString()
      Returns connection string for zookeeper clients.
      Returns:
      Connection string to connect to the Zookeeper instance.
    • getKafkaConnectString

      public String getKafkaConnectString()
      bootstrap.servers string to configure Kafka consumers or producers to access the Kafka cluster.
      Returns:
      Connect string to use for Kafka clients.
    • getKafkaBrokers

      public KafkaBrokers getKafkaBrokers()
      Returns an immutable list of broker hosts for the kafka cluster.
      Returns:
      immutable list of hosts for brokers within the cluster.
    • getRegisteredListener

      protected BrokerListener getRegisteredListener()
      Returns all registered listener.
      Returns:
      The configured listener.
    • getKafkaCluster

      protected KafkaCluster getKafkaCluster()
    • setKafkaCluster

      protected void setKafkaCluster​(KafkaCluster kafkaCluster)
    • getBrokerProperties

      protected Properties getBrokerProperties()
    • getNumberOfBrokers

      protected int getNumberOfBrokers()
    • validateState

      protected void validateState​(boolean shouldKafkaExistYet, String errorMessage) throws IllegalStateException
      Helper method for ensure state consistency.
      Parameters:
      shouldKafkaExistYet - True if KafkaCluster should exist, false if it should not.
      errorMessage - Error message to throw if the state is not consistent.
      Throws:
      IllegalStateException - if the kafkaCluster state is not consistent.