Add awaitility module: testing async @Async/@Scheduled/@KafkaListener code without Thread.sleep
Covers replacing Thread.sleep with await() across a void @Async method, an @EmbeddedKafka-backed @KafkaListener, and an already-running @Scheduled job; verifies Awaitility 4.3.0's real defaults (10s timeout, 100ms poll interval) and its default-uncaught-exception-handler swap directly against the jar; and documents a real pom.xml trap where Boot 4.1.1 split Kafka's autoconfiguration (spring-boot-kafka) out of spring-kafka itself, which silently leaves @KafkaListener beans with no running container.
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<!-- Boot 4.1.1 manages Spring Framework 7.0.9, Spring Kafka 4.1.1 and Awaitility 4.3.0.
|
||||
Versions were read from spring-boot-dependencies-4.1.1.pom and
|
||||
spring-boot-starter-test-4.1.1.pom, not from release notes. -->
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>4.1.1</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.ankurm</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<java.version>25</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- NOT org.springframework.kafka:spring-kafka directly, that was Boot 3.x's shape.
|
||||
In Boot 4.1.1 the Kafka autoconfiguration classes (KafkaTemplate, ConsumerFactory,
|
||||
the KafkaListenerEndpointRegistry that @KafkaListener needs) were extracted out of the
|
||||
monolithic spring-boot-autoconfigure jar into their own module, org.springframework.boot
|
||||
:spring-boot-kafka. Depending on spring-kafka alone now gets you the annotations and
|
||||
KafkaTemplate class with none of the autoconfiguration wiring: every @KafkaListener bean
|
||||
is created but no container ever starts, silently, with no error at context startup.
|
||||
This starter is what actually pulls spring-boot-kafka (confirmed via its real POM on
|
||||
Maven Central) in on top of spring-kafka itself. -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-kafka</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- No explicit <awaitility> dependency anywhere in this file. spring-boot-starter-test
|
||||
4.1.1 already declares org.awaitility:awaitility:4.3.0 as a compile-scope dependency
|
||||
of its own, confirmed against the real POM on Maven Central, not assumed. Every
|
||||
project using this starter already has Awaitility on its test classpath today. -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- The test-scope sibling of spring-boot-starter-kafka above: pulls spring-kafka-test
|
||||
(the @EmbeddedKafka JUnit 5 extension and KafkaTestUtils) on the same Boot-4.1.1-managed
|
||||
version as everything else here. @EmbeddedKafka starts a real, in-process Kafka broker
|
||||
for the duration of a test class, no Docker, no Testcontainers, no network port opened
|
||||
outside this JVM, which is also why it is the only honest way to demonstrate Kafka
|
||||
listener testing in a sandbox with no Docker daemon. -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-kafka-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
Reference in New Issue
Block a user