diff --git a/test-suite-groovy/build.gradle.kts b/test-suite-groovy/build.gradle.kts
index e60c23efa..2776ffe56 100644
--- a/test-suite-groovy/build.gradle.kts
+++ b/test-suite-groovy/build.gradle.kts
@@ -9,7 +9,6 @@ dependencies {
testImplementation(libs.testcontainers.kafka)
testImplementation(mnTest.micronaut.test.spock)
testRuntimeOnly(libs.junit.jupiter.engine)
- testImplementation(libs.awaitility)
testImplementation(mnReactor.micronaut.reactor)
testImplementation(mnSerde.micronaut.serde.jackson)
testImplementation(projects.micronautKafka)
diff --git a/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/AbstractKafkaTest.groovy b/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/AbstractKafkaTest.groovy
index 4975b83c8..09fbfe25b 100644
--- a/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/AbstractKafkaTest.groovy
+++ b/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/AbstractKafkaTest.groovy
@@ -3,25 +3,20 @@ package io.micronaut.kafka.docs
import io.micronaut.test.support.TestPropertyProvider
import org.testcontainers.containers.KafkaContainer
import org.testcontainers.utility.DockerImageName
+import spock.lang.AutoCleanup
+import spock.lang.Shared
import spock.lang.Specification
-/**
- * @see Singleton containers
- */
abstract class AbstractKafkaTest extends Specification implements TestPropertyProvider {
- static final KafkaContainer MY_KAFKA
-
- static {
- MY_KAFKA = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest"))
- MY_KAFKA.start()
- }
+ @Shared
+ @AutoCleanup
+ KafkaContainer kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest"))
@Override
Map getProperties() {
- while (!MY_KAFKA.isRunning()) {
- MY_KAFKA.start()
- }
- ["kafka.bootstrap.servers": MY_KAFKA.getBootstrapServers()]
+ kafkaContainer.start()
+
+ ["kafka.bootstrap.servers": kafkaContainer.getBootstrapServers()]
}
}
diff --git a/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/MyTest.groovy b/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/MyTest.groovy
index 0f4052db5..ff1e23a38 100644
--- a/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/MyTest.groovy
+++ b/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/MyTest.groovy
@@ -1,15 +1,18 @@
package io.micronaut.kafka.docs
-import io.micronaut.configuration.kafka.annotation.*
-import io.micronaut.context.annotation.*
+
+import io.micronaut.configuration.kafka.annotation.KafkaClient
+import io.micronaut.configuration.kafka.annotation.KafkaListener
+import io.micronaut.configuration.kafka.annotation.OffsetReset
+import io.micronaut.configuration.kafka.annotation.Topic
+import io.micronaut.context.annotation.Property
+import io.micronaut.context.annotation.Requires
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
+import spock.util.concurrent.PollingConditions
-import static java.util.concurrent.TimeUnit.SECONDS
-import static org.awaitility.Awaitility.await
-
-@Property(name = "spec.name", value = "MyTest")
@MicronautTest
+@Property(name = "spec.name", value = "MyTest")
class MyTest extends AbstractKafkaTest {
@Inject
@@ -17,6 +20,8 @@ class MyTest extends AbstractKafkaTest {
@Inject
MyConsumer consumer
+ PollingConditions conditions = new PollingConditions()
+
void "test kafka running"() {
given:
String message = "hello"
@@ -25,10 +30,9 @@ class MyTest extends AbstractKafkaTest {
producer.produce(message)
then:
- await().atMost(5, SECONDS).until(() -> consumer.consumed == message)
-
- cleanup:
- MY_KAFKA.stop()
+ conditions.within(5) {
+ consumer.consumed == message
+ }
}
@Requires(property = "spec.name", value = "MyTest")
diff --git a/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/quickstart/QuickStartTest.groovy b/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/quickstart/QuickStartTest.groovy
index aa6e81ae3..bc64ab4e4 100644
--- a/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/quickstart/QuickStartTest.groovy
+++ b/test-suite-groovy/src/test/groovy/io/micronaut/kafka/docs/quickstart/QuickStartTest.groovy
@@ -1,12 +1,10 @@
package io.micronaut.kafka.docs.quickstart
-import io.micronaut.context.ApplicationContext
import io.micronaut.context.BeanContext
import io.micronaut.context.annotation.Property
import io.micronaut.kafka.docs.AbstractKafkaTest
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
-import spock.lang.Specification
@Property(name = 'spec.name', value = 'QuickStartTest')
@MicronautTest
@@ -21,7 +19,5 @@ class QuickStartTest extends AbstractKafkaTest {
ProductClient client = beanContext.getBean(ProductClient.class)
client.sendProduct('Nike', 'Blue Trainers')
// end::quickstart[]
-
- MY_KAFKA.stop()
}
}
diff --git a/test-suite/src/test/java/io/micronaut/kafka/docs/MyTest.java b/test-suite/src/test/java/io/micronaut/kafka/docs/MyTest.java
index c72b7f75b..cea597afc 100644
--- a/test-suite/src/test/java/io/micronaut/kafka/docs/MyTest.java
+++ b/test-suite/src/test/java/io/micronaut/kafka/docs/MyTest.java
@@ -12,6 +12,7 @@
@MicronautTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class MyTest extends AbstractKafkaTest {
+
@Test
void testKafkaRunning(MyProducer producer, MyConsumer consumer) {
final String message = "hello";