Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groovify the groovy test-suite #824

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion test-suite-groovy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://www.testcontainers.org/test_framework_integration/manual_lifecycle_control/#singleton-containers">Singleton containers</a>
*/
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<String, String> getProperties() {
while (!MY_KAFKA.isRunning()) {
MY_KAFKA.start()
}
["kafka.bootstrap.servers": MY_KAFKA.getBootstrapServers()]
kafkaContainer.start()

["kafka.bootstrap.servers": kafkaContainer.getBootstrapServers()]
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
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
MyProducer producer
@Inject
MyConsumer consumer

PollingConditions conditions = new PollingConditions()

void "test kafka running"() {
given:
String message = "hello"
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,7 +19,5 @@ class QuickStartTest extends AbstractKafkaTest {
ProductClient client = beanContext.getBean(ProductClient.class)
client.sendProduct('Nike', 'Blue Trainers')
// end::quickstart[]

MY_KAFKA.stop()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down