Class TestcontainersKafkaCluster
java.lang.Object
io.kroxylicious.testing.kafka.testcontainers.TestcontainersKafkaCluster
- All Implemented Interfaces:
KafkaCluster,KafkaListenerSource,AdminSource,AutoCloseable,org.testcontainers.lifecycle.Startable
public class TestcontainersKafkaCluster
extends Object
implements org.testcontainers.lifecycle.Startable, KafkaCluster, KafkaListenerSource, AdminSource
Provides an easy way to launch a Kafka cluster with multiple brokers in a container
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe type Kafka container.static classTestcontainersKafkaCluster.LoggingGenericContainer<C extends org.testcontainers.containers.GenericContainer<C>>The type Logging generic container.static classContainer used for running one-short commands.static classThe type Zookeeper container.Nested classes/interfaces inherited from interface io.kroxylicious.testing.kafka.common.KafkaListenerSource
KafkaListenerSource.Listener -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe constant ANON_PORT.static final Stringstatic final Stringenvironment variable specifying the apache kafka image repository.static final intThe constant CLIENT_PORT.static final Stringenvironment variable specifying the kafka image repository.static final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final String -
Constructor Summary
ConstructorsConstructorDescriptionTestcontainersKafkaCluster(KafkaClusterConfig clusterConfig) Instantiates a new Testcontainers kafka cluster.TestcontainersKafkaCluster(org.testcontainers.utility.DockerImageName kafkaImage, org.testcontainers.utility.DockerImageName zookeeperImage, KafkaClusterConfig clusterConfig) Deprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()org.apache.kafka.clients.admin.AdminCreates an admin client with administrator privileges.getKafkaClientConfiguration(String user, String password) getKafkaListener(KafkaListenerSource.Listener listener, int nodeId) Gets the kafka listen for the given listener and nodeId.Gets kafka version.intvoidremoveBroker(int nodeId) voidstart()voidstartNodes(IntPredicate nodeIdPredicate) voidstop()voidstopNodes(IntPredicate nodeIdPredicate, TerminationStyle terminationStyle) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.testcontainers.lifecycle.Startable
getDependencies
-
Field Details
-
LEGACY_ZOOKEEPER_IMAGE_TAG
Deprecated.- See Also:
-
LEGACY_ZOOKEEPER_IMAGE_REPO
Deprecated.- See Also:
-
LEGACY_KAFKA_IMAGE_REPO
Deprecated.environment variable specifying the ogunalp native kafka image repository.- See Also:
-
APACHE_KAFKA_IMAGE_REPO
environment variable specifying the apache kafka image repository.- See Also:
-
KAFKA_IMAGE_TAG
environment variable specifying the kafka image repository.- See Also:
-
CLIENT_PORT
public static final int CLIENT_PORTThe constant CLIENT_PORT.- See Also:
-
ANON_PORT
public static final int ANON_PORTThe constant ANON_PORT.- See Also:
-
WILDCARD_BIND_ADDRESS
- See Also:
-
APACHE_CONTAINER_UID
- See Also:
-
-
Constructor Details
-
TestcontainersKafkaCluster
Instantiates a new Testcontainers kafka cluster.- Parameters:
clusterConfig- the cluster config
-
TestcontainersKafkaCluster
@Deprecated(forRemoval=true) public TestcontainersKafkaCluster(org.testcontainers.utility.DockerImageName kafkaImage, org.testcontainers.utility.DockerImageName zookeeperImage, KafkaClusterConfig clusterConfig) Deprecated, for removal: This API element is subject to removal in a future version.please useTestcontainersKafkaCluster(KafkaClusterConfig)The Image arguments have been replaced by environment variablesInstantiates a new Testcontainers kafka cluster.- Parameters:
kafkaImage- IGNORED the kafka imagezookeeperImage- IGNORED the zookeeper imageclusterConfig- the cluster config
-
-
Method Details
-
getBootstrapServers
- Specified by:
getBootstrapServersin interfaceKafkaCluster
-
getBootstrapControllers
- Specified by:
getBootstrapControllersin interfaceKafkaCluster
-
getKafkaVersion
Gets kafka version.- Returns:
- the kafka version
-
start
public void start()- Specified by:
startin interfaceKafkaCluster- Specified by:
startin interfaceorg.testcontainers.lifecycle.Startable
-
addBroker
public int addBroker()- Specified by:
addBrokerin interfaceKafkaCluster
-
removeBroker
public void removeBroker(int nodeId) throws UnsupportedOperationException, IllegalArgumentException, IllegalStateException - Specified by:
removeBrokerin interfaceKafkaCluster- Throws:
UnsupportedOperationExceptionIllegalArgumentExceptionIllegalStateException
-
stopNodes
- Specified by:
stopNodesin interfaceKafkaCluster
-
startNodes
- Specified by:
startNodesin interfaceKafkaCluster
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceKafkaCluster- Specified by:
closein interfaceorg.testcontainers.lifecycle.Startable
-
getNumOfBrokers
public int getNumOfBrokers()- Specified by:
getNumOfBrokersin interfaceKafkaCluster
-
getStoppedBrokers
- Specified by:
getStoppedBrokersin interfaceKafkaCluster
-
stop
public void stop()- Specified by:
stopin interfaceorg.testcontainers.lifecycle.Startable
-
getClusterId
- Specified by:
getClusterIdin interfaceKafkaCluster
-
getKafkaClientConfiguration
- Specified by:
getKafkaClientConfigurationin interfaceKafkaCluster
-
getKafkaClientConfiguration
- Specified by:
getKafkaClientConfigurationin interfaceKafkaCluster
-
getControllerAdminClientConfiguration
- Specified by:
getControllerAdminClientConfigurationin interfaceKafkaCluster
-
getKafkaListener
Description copied from interface:KafkaListenerSourceGets the kafka listen for the given listener and nodeId.- Specified by:
getKafkaListenerin interfaceKafkaListenerSource- Parameters:
listener- listenernodeId- kafkanode.id- Returns:
- kafka listener.
-
createAdmin
@NonNull public org.apache.kafka.clients.admin.Admin createAdmin()Description copied from interface:AdminSourceCreates an admin client with administrator privileges. It is the caller's responsibility to close the admin client returned.- Specified by:
createAdminin interfaceAdminSource- Returns:
- admin client
-
TestcontainersKafkaCluster(KafkaClusterConfig)The Image arguments have been replaced by environment variables