Package com.bakdata.kafka
Class TestApplicationRunner
java.lang.Object
com.bakdata.kafka.TestApplicationRunner
Class that provides helpers for using running
KafkaApplication in tests-
Method Summary
Modifier and TypeMethodDescriptionvoidclean(KafkaApplication<?, ?, ?, ?, ?, ?, ?, ?> app) Clean the application.intclean(KafkaApplication<?, ?, ?, ?, ?, ?, ?, ?> app, String... args) Clean the application with the given arguments.voidconfigure(KafkaApplication<?, ?, ?, ?, ?, ?, ?, ?> app) Configure the application according to the test environment.static TestApplicationRunnerCreate a test application runner with the given bootstrap servers.Create a newKafkaTestClientfor the configured test environment.voidreset(KafkaStreamsApplication<? extends StreamsApp> app) Reset the application.intreset(KafkaStreamsApplication<? extends StreamsApp> app, String... args) Reset the application with the given arguments.run(KafkaApplication<?, ?, ?, ?, ?, ?, ?, ?> app) Run the application asynchronously.run(KafkaApplication<?, ?, ?, ?, ?, ?, ?, ?> app, String... args) Run the application asynchronously with the given arguments.verify(KafkaStreamsApplication<? extends StreamsApp> app) Create a newConsumerGroupVerifierfor the provided application.withKafkaConfig(Map<String, String> newKafkaConfig) Configure arbitrary Kafka propertiesDisable for Kafka Streams.Configure a schema registry for (de-)serialization.withSchemaRegistry(@NonNull TestSchemaRegistry schemaRegistry) Configure a schema registry for (de-)serialization.withSessionTimeout(Duration sessionTimeout) ConfigureConsumerConfig.SESSION_TIMEOUT_MS_CONFIGfor Kafka consumers.withStateDir(Path stateDir) ConfigureStreamsConfig.STATE_DIR_CONFIGfor Kafka Streams.
-
Method Details
-
create
Create a test application runner with the given bootstrap servers.- Parameters:
bootstrapServers- bootstrap servers to connect to- Returns:
- test application runner
-
withStateDir
ConfigureStreamsConfig.STATE_DIR_CONFIGfor Kafka Streams. Useful for testing- Parameters:
stateDir- directory to use for storing Kafka Streams state- Returns:
- a copy of this runtime configuration with configured Kafka Streams state directory
-
withNoStateStoreCaching
Disable for Kafka Streams. Useful for testing- Returns:
- a copy of this runtime configuration with Kafka Streams state store caching disabled
-
withSessionTimeout
ConfigureConsumerConfig.SESSION_TIMEOUT_MS_CONFIGfor Kafka consumers. Useful for testing- Parameters:
sessionTimeout- session timeout- Returns:
- a copy of this runtime configuration with configured consumer session timeout
-
withKafkaConfig
Configure arbitrary Kafka properties- Parameters:
newKafkaConfig- properties to configure- Returns:
- a copy of this runtime configuration with provided properties
-
withSchemaRegistry
public TestApplicationRunner withSchemaRegistry(@NonNull @NonNull TestSchemaRegistry schemaRegistry) Configure a schema registry for (de-)serialization.- Parameters:
schemaRegistry- schema registry to use- Returns:
- a copy of this runtime configuration with configured schema registry
-
withSchemaRegistry
Configure a schema registry for (de-)serialization.- Returns:
- a copy of this runtime configuration with configured schema registry
-
run
Run the application asynchronously with the given arguments.--bootstrap-servers,--schema -registry-url, and--kafka-configare automatically configured.- Parameters:
app- application to runargs- CLI arguments to pass to the application- Returns:
CompletableFutureproviding the application exit code
-
clean
Clean the application with the given arguments.--bootstrap-servers,--schema-registry-url, and--kafka-configare automatically configured.- Parameters:
app- application to cleanargs- CLI arguments to pass to the application- Returns:
- application exit code
-
reset
Reset the application with the given arguments.--bootstrap-servers,--schema-registry-url, and--kafka-configare automatically configured.- Parameters:
app- application to resetargs- CLI arguments to pass to the application- Returns:
- application exit code
-
run
Run the application asynchronously. Bootstrap servers, Schema Registry and Kafka config are automatically configured.- Parameters:
app- application to run- Returns:
CompletableFutureto await execution
-
clean
Clean the application. Bootstrap servers, Schema Registry and Kafka config are automatically configured.- Parameters:
app- application to clean
-
reset
Reset the application. Bootstrap servers, Schema Registry and Kafka config are automatically configured.- Parameters:
app- application to reset
-
verify
Create a newConsumerGroupVerifierfor the provided application.- Parameters:
app- application to verify- Returns:
ConsumerGroupVerifier
-
newTestClient
Create a newKafkaTestClientfor the configured test environment.- Returns:
KafkaTestClient
-
configure
Configure the application according to the test environment. Bootstrap servers, Schema Registry and Kafka config are configured.- Parameters:
app- application to configure
-