Hello,
I'm using SB 3.1.4. The problem is that if I activate AOT for the tests, if the tests use @EmbeddedKafka
the AOT process is blocked.
If I press Ctrl+c then the process proceeds correctly
I have a simple example at https://github.com/rgarciapariente/kakfka-aot
Just run mvn clean verify
to reproduce the problem.
I have tested on windows and on Linux (ubuntu with wsl2)
Thanks & regards
Comment From: wilkinsona
Thanks for the report. This is a lifecycle issue that's out of Spring Boot's control. The AOT processing of test contexts that's performed by Spring Framework is causing Spring for Apache Kafka to start an embedded Kafka instance. This instance is never stopped which prevents the JVM that's performing the AOT processing from exiting. This will either have to be addressed in Spring for Apache Kafka so that Kafka isn't started or in Spring Framework so that it's stopped. We'll transfer this issue to the Framework team so that they can continue the investigation.
Comment From: snicoll
The embedded broker is created in EmbeddedKafkaContextCustomizer
via a ContextCustomizer
implementation. It forces the broker to be initialized in the customizeContext
callback.
I believe this is a Spring Kafka issue. It casting the factory into a registry is also a symptom of the problem. The javadoc for customizeContext
states:
Customize the supplied ConfigurableApplicationContext after bean definitions have been loaded into the context but before the context has been refreshed.
@garyrussell what do you think? I am afraid I won't have the rights to move this to the Spring Kafka project if you agree it should be handled there.
Comment From: garyrussell
We explicitly point out in the documentation that spring-kafka-test
and the embedded kafka broker are not supported in native images:
https://docs.spring.io/spring-kafka/docs/current/reference/html/#native-images
We (Spring) cannot take on the responsibility of making the Kafka broker work in that environment. We recommend using docker for testing native images (as is done in the Spring AOT smoke tests).
I can say that the Kafka team is working on providing a GraalVM docker image for the broker. https://cwiki.apache.org/confluence/display/KAFKA/KIP-974%3A+Docker+Image+for+GraalVM+based+Native+Kafka+Broker
There is active discussion about it in the Apache Kafka mailing llists.
Comment From: snicoll
I understand the reasoning behind not supporting the embedded broker in a native image, and therefore a test that uses it should be flagged with @DisabledInAotMode
.
That said, the report above was really about the JVM and how the ContextCustomizer
is implemented. I really think it shouldn't start the broker in that method. I am going to close this issue based on the feedback though. Thanks!
Comment From: garyrussell
It's not clear why the broker is not stopped when the application context is shut down; the customizer registers the broker as a disposable bean.
cc/ @artembilan Can you take a look?