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 TypeMethodDescriptionvoid
clean
(KafkaApplication<?, ?, ?, ?, ?, ?, ?, ?> app) Clean the application.int
clean
(KafkaApplication<?, ?, ?, ?, ?, ?, ?, ?> app, String... args) Clean the application with the given arguments.void
configure
(KafkaApplication<?, ?, ?, ?, ?, ?, ?, ?> app) Configure the application according to the test environment.static TestApplicationRunner
Create a test application runner with the given bootstrap servers.Create a newKafkaTestClient
for the configured test environment.void
reset
(KafkaStreamsApplication<? extends StreamsApp> app) Reset the application.int
reset
(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 newConsumerGroupVerifier
for 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_CONFIG
for Kafka consumers.withStateDir
(Path stateDir) ConfigureStreamsConfig.STATE_DIR_CONFIG
for 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_CONFIG
for 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_CONFIG
for 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-config
are automatically configured.- Parameters:
app
- application to runargs
- CLI arguments to pass to the application- Returns:
CompletableFuture
providing the application exit code
-
clean
Clean the application with the given arguments.--bootstrap-servers
,--schema-registry-url
, and--kafka-config
are 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-config
are 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:
CompletableFuture
to 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 newConsumerGroupVerifier
for the provided application.- Parameters:
app
- application to verify- Returns:
ConsumerGroupVerifier
-
newTestClient
Create a newKafkaTestClient
for 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
-