Package com.salesforce.kafka.test
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 Summary
Constructors Constructor Description AbstractKafkaTestResource()Default constructor.AbstractKafkaTestResource(Properties brokerProperties)Constructor allowing passing additional broker properties. -
Method Summary
Modifier and Type Method Description protected PropertiesgetBrokerProperties()KafkaBrokersgetKafkaBrokers()Returns an immutable list of broker hosts for the kafka cluster.protected KafkaClustergetKafkaCluster()StringgetKafkaConnectString()bootstrap.servers string to configure Kafka consumers or producers to access the Kafka cluster.KafkaTestUtilsgetKafkaTestUtils()KafkaTestUtils is a collection of re-usable/common access patterns for interacting with the Kafka cluster.protected intgetNumberOfBrokers()protected BrokerListenergetRegisteredListener()Returns all registered listener.StringgetZookeeperConnectString()Returns connection string for zookeeper clients.TregisterListener(BrokerListener listener)Register additional listeners on the kafka brokers.protected voidsetKafkaCluster(KafkaCluster kafkaCluster)protected voidvalidateState(boolean shouldKafkaExistYet, String errorMessage)Helper method for ensure state consistency.TwithBrokerProperty(String name, String value)Helper to allow overriding Kafka broker properties.TwithBrokers(int brokerCount)Set how many brokers to include in the test cluster.
-
Constructor Details
-
AbstractKafkaTestResource
public AbstractKafkaTestResource()Default constructor. -
AbstractKafkaTestResource
Constructor allowing passing additional broker properties.- Parameters:
brokerProperties- properties for Kafka broker.
-
-
Method Details
-
withBrokerProperty
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
Set how many brokers to include in the test cluster.- Parameters:
brokerCount- The number of brokers.- Returns:
- SharedKafkaTestResource for method chaining.
-
registerListener
Register additional listeners on the kafka brokers.- Parameters:
listener- listener instance to register.- Returns:
- SharedKafkaTestResource for method chaining.
-
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
Returns connection string for zookeeper clients.- Returns:
- Connection string to connect to the Zookeeper instance.
-
getKafkaConnectString
bootstrap.servers string to configure Kafka consumers or producers to access the Kafka cluster.- Returns:
- Connect string to use for Kafka clients.
-
getKafkaBrokers
Returns an immutable list of broker hosts for the kafka cluster.- Returns:
- immutable list of hosts for brokers within the cluster.
-
getRegisteredListener
Returns all registered listener.- Returns:
- The configured listener.
-
getKafkaCluster
-
setKafkaCluster
-
getBrokerProperties
-
getNumberOfBrokers
protected int getNumberOfBrokers() -
validateState
protected void validateState(boolean shouldKafkaExistYet, String errorMessage) throws IllegalStateExceptionHelper 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.
-