Files
spring-kafka/samples/sample-05/README.adoc
Artem Bilan 0f69553736 GH-666: Single global embedded Kafka with JUnit 5 (#2308)
* GH-666: Single global embedded Kafka with JUnit 5

Fixes https://github.com/spring-projects/spring-kafka/issues/666

* Introduce a `GlobalEmbeddedKafkaTestExecutionListener` which is registered
by the service loader from JUnit Platform
* Make its activation conditional based on the `spring.kafka.global.embedded.enabled`
system property
* Expose some other configuration properties for the target global `EmbeddedKafkaBroker`
* Verify its functionality via manual `Launcher.execute()`
* Add more `@DirtiesContext` to some tests in the `spring-kafka-test` which don't close
their embedded brokers on the exit

* * Print local launcher summary into SOUT for tracing the nested problems

* * Fix prefix for `file:` resource in the test

* * Make `junit-platform-launcher` as provided dep -
this is part of JUnit platform the test plan is going to be run
* Add missed new line in the end of `junit-platform.properties`
* Rethrow an exception from the local launcher in the `GlobalEmbeddedKafkaTestExecutionListenerTests`
to fail if its suite test classes have failed.

* * Fix JavaDocs for `GlobalEmbeddedKafkaTestExecutionListener` constants
* Move system properties clean up in the `GlobalEmbeddedKafkaTestExecutionListenerTests` into `@AfterAll`
* Add docs for this new feature
* Add `sample-05` to demonstrate global embedded Kafka in action via Maven configuration

* * Mention `sample-05` in the common `README.adoc` for samples

* * Fix language in the `testing.adoc`
* Add new lines into new files
* Add `spring.kafka.consumer.auto-offset-reset=earliest` to make a consumer to start from the beginning of the partition:
fixes a race condition when publishing happens before consumer is started
* Make `mvnw` as an executable
* Add `spring.embedded.kafka.brokers.property` explanation into docs

* * Fix language in docs

Co-authored-by: Gary Russell <grussell@vmware.com>

* * Make `Sample05Application2Tests` passing
* Remove `deliberately failing` sentence from the JavaDoc an README
* Clean up unused imports

Co-authored-by: Gary Russell <grussell@vmware.com>
2022-06-22 17:14:14 -04:00

24 lines
1.7 KiB
Plaintext

== Sample 5
This sample demonstrates a global embedded Kafka broker in action.
This kind of broker is enabled via `spring.kafka.global.embedded.enabled = true` JUnit Platform property configured in the Maven Surefire plugin.
Additional properties for the underlying `GlobalEmbeddedKafkaTestExecutionListener`, and therefore embedded Kafka broker(s), are provided via standard `junit-platform.properties` file or extra configuration parameters for the Maven Surefire plugin.
Run only `./mvnw test` command for this sample.
The Maven will report to the output similar two log messages:
```
11:03:44.383 [main] INFO o.s.k.t.j.GlobalEmbeddedKafkaTestExecutionListener - Started global Embedded Kafka on: 127.0.0.1:53671
...
11:03:48.439 [main] INFO o.s.k.t.j.GlobalEmbeddedKafkaTestExecutionListener - Stopped global Embedded Kafka.
```
One in the beginning of the test plan - and another in the end before reporting failures.
The application by itself is going to fail because it has a configuration like `spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}`.
This property makes it available only when an `EmbeddedKafkaBroker` is started, which is done by the `GlobalEmbeddedKafkaTestExecutionListener` and only when `spring.kafka.global.embedded.enabled = true`.
Running unit tests from IDE will lead to similar failure - the `GlobalEmbeddedKafkaTestExecutionListener` is not enabled by default and there is no an `@EmbeddedKafka` present in these tests.
The `Sample05Application2Tests` demonstrates that global embedded Kafka broker config for {@code auto.create.topics.enable=false} is in an effect.
See `kafka-broker.properties` added via Maven Surefire plugin.
See `/test/resources/kafka-broker.properties` and Maven Surefire plugin configuration in the pom.xml.