From d0e3122e2ca296a1b886ba4181b4471743baef00 Mon Sep 17 00:00:00 2001 From: Ozan Gunalp Date: Thu, 20 Jul 2023 15:51:16 +0200 Subject: [PATCH 1/2] Reactive messaging virtual threads tests --- .../disable-native-profile | 1 + .../amqp-virtual-threads/pom.xml | 126 +++++++++++++++ .../it/vthreads/amqp/AssertHelper.java | 68 ++++++++ .../it/vthreads/amqp/PriceAlertService.java | 23 +++ .../it/vthreads/amqp/PriceConsumer.java | 61 +++++++ .../src/main/resources/application.properties | 7 + .../it/vthreads/amqp/VirtualThreadTest.java | 36 +++++ .../it/vthreads/amqp/WireMockExtension.java | 41 +++++ .../disable-native-profile | 1 + .../jms-virtual-threads/pom.xml | 151 ++++++++++++++++++ .../quarkus/it/vthreads/jms/AssertHelper.java | 68 ++++++++ .../it/vthreads/jms/PriceAlertService.java | 23 +++ .../it/vthreads/jms/PriceConsumer.java | 55 +++++++ .../src/main/resources/application.properties | 10 ++ .../it/vthreads/jms/VirtualThreadTest.java | 36 +++++ .../it/vthreads/jms/WireMockExtension.java | 41 +++++ .../disable-native-profile | 1 + .../kafka-virtual-threads/pom.xml | 125 +++++++++++++++ .../it/vthreads/kafka/AssertHelper.java | 68 ++++++++ .../it/vthreads/kafka/PriceAlertService.java | 23 +++ .../it/vthreads/kafka/PriceConsumer.java | 61 +++++++ .../src/main/resources/application.properties | 8 + .../it/vthreads/kafka/VirtualThreadTest.java | 36 +++++ .../it/vthreads/kafka/WireMockExtension.java | 41 +++++ integration-tests/virtual-threads/pom.xml | 18 +-- 25 files changed, 1120 insertions(+), 9 deletions(-) create mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/disable-native-profile create mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/pom.xml create mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/AssertHelper.java create mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/PriceAlertService.java create mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/PriceConsumer.java create mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/src/main/resources/application.properties create mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/src/test/java/io/quarkus/it/vthreads/amqp/VirtualThreadTest.java create mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/src/test/java/io/quarkus/it/vthreads/amqp/WireMockExtension.java create mode 100644 integration-tests/virtual-threads/jms-virtual-threads/disable-native-profile create mode 100644 integration-tests/virtual-threads/jms-virtual-threads/pom.xml create mode 100644 integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/AssertHelper.java create mode 100644 integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/PriceAlertService.java create mode 100644 integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/PriceConsumer.java create mode 100644 integration-tests/virtual-threads/jms-virtual-threads/src/main/resources/application.properties create mode 100644 integration-tests/virtual-threads/jms-virtual-threads/src/test/java/io/quarkus/it/vthreads/jms/VirtualThreadTest.java create mode 100644 integration-tests/virtual-threads/jms-virtual-threads/src/test/java/io/quarkus/it/vthreads/jms/WireMockExtension.java create mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/disable-native-profile create mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/pom.xml create mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/AssertHelper.java create mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/PriceAlertService.java create mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/PriceConsumer.java create mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/src/main/resources/application.properties create mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/src/test/java/io/quarkus/it/vthreads/kafka/VirtualThreadTest.java create mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/src/test/java/io/quarkus/it/vthreads/kafka/WireMockExtension.java diff --git a/integration-tests/virtual-threads/amqp-virtual-threads/disable-native-profile b/integration-tests/virtual-threads/amqp-virtual-threads/disable-native-profile new file mode 100644 index 0000000000000..011a7cc4571d5 --- /dev/null +++ b/integration-tests/virtual-threads/amqp-virtual-threads/disable-native-profile @@ -0,0 +1 @@ +This file disables the native profile in the parent pom.xml of this module. \ No newline at end of file diff --git a/integration-tests/virtual-threads/amqp-virtual-threads/pom.xml b/integration-tests/virtual-threads/amqp-virtual-threads/pom.xml new file mode 100644 index 0000000000000..077972f0c96c7 --- /dev/null +++ b/integration-tests/virtual-threads/amqp-virtual-threads/pom.xml @@ -0,0 +1,126 @@ + + + 4.0.0 + + + quarkus-virtual-threads-integration-tests-parent + io.quarkus + 999-SNAPSHOT + + + quarkus-integration-test-virtual-threads-amqp + Quarkus - Integration Tests - Virtual Threads - AMQP 1.0 + + + + io.quarkus + quarkus-resteasy-reactive-jackson + + + io.quarkus + quarkus-smallrye-reactive-messaging-amqp + + + io.quarkus + quarkus-rest-client-reactive + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + org.awaitility + awaitility + test + + + org.assertj + assertj-core + test + + + io.quarkus + quarkus-test-vertx + test + + + io.quarkus + quarkus-junit5-mockito + test + + + com.github.tomakehurst + wiremock-jre8-standalone + test + + + io.quarkus + quarkus-test-common + test + + + + + io.quarkus + quarkus-smallrye-reactive-messaging-amqp-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-rest-client-reactive-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-resteasy-reactive-jackson-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + + io.quarkus + quarkus-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + diff --git a/integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/AssertHelper.java b/integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/AssertHelper.java new file mode 100644 index 0000000000000..cf4317de2b273 --- /dev/null +++ b/integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/AssertHelper.java @@ -0,0 +1,68 @@ +package io.quarkus.it.vthreads.amqp; + +import java.lang.reflect.Method; + +import io.quarkus.arc.Arc; +import io.smallrye.common.vertx.VertxContext; +import io.vertx.core.Vertx; + +public class AssertHelper { + + /** + * Asserts that the current method: + * - runs on a duplicated context + * - runs on a virtual thread + * - has the request scope activated + */ + public static void assertEverything() { + assertThatTheRequestScopeIsActive(); + assertThatItRunsOnVirtualThread(); + assertThatItRunsOnADuplicatedContext(); + } + + public static void assertThatTheRequestScopeIsActive() { + if (!Arc.container().requestContext().isActive()) { + throw new AssertionError(("Expected the request scope to be active")); + } + } + + public static void assertThatItRunsOnADuplicatedContext() { + var context = Vertx.currentContext(); + if (context == null) { + throw new AssertionError("The method does not run on a Vert.x context"); + } + if (!VertxContext.isOnDuplicatedContext()) { + throw new AssertionError("The method does not run on a Vert.x **duplicated** context"); + } + } + + public static void assertThatItRunsOnVirtualThread() { + // We cannot depend on a Java 20. + try { + Method isVirtual = Thread.class.getMethod("isVirtual"); + isVirtual.setAccessible(true); + boolean virtual = (Boolean) isVirtual.invoke(Thread.currentThread()); + if (!virtual) { + throw new AssertionError("Thread " + Thread.currentThread() + " is not a virtual thread"); + } + } catch (Exception e) { + throw new AssertionError( + "Thread " + Thread.currentThread() + " is not a virtual thread - cannot invoke Thread.isVirtual()", e); + } + } + + public static void assertThatItDoesNotRunOnVirtualThread() { + // We cannot depend on a Java 20. + try { + Method isVirtual = Thread.class.getMethod("isVirtual"); + isVirtual.setAccessible(true); + boolean virtual = (Boolean) isVirtual.invoke(Thread.currentThread()); + if (virtual) { + throw new AssertionError("Thread " + Thread.currentThread() + " is a virtual thread"); + } + } catch (Exception e) { + throw new AssertionError( + "Thread " + Thread.currentThread() + " is a virtual thread - but cannot invoke Thread.isVirtual()", e); + } + } +} diff --git a/integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/PriceAlertService.java b/integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/PriceAlertService.java new file mode 100644 index 0000000000000..11e9ac1df01bd --- /dev/null +++ b/integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/PriceAlertService.java @@ -0,0 +1,23 @@ +package io.quarkus.it.vthreads.amqp; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.MediaType; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +@Path("price") +@RegisterRestClient(configKey = "price-alert") +public interface PriceAlertService { + + @Path("alert") + @POST + @Consumes(MediaType.TEXT_PLAIN) + String alert(double value); + + @Path("alert-message") + @POST + @Consumes(MediaType.TEXT_PLAIN) + String alertMessage(double value); +} diff --git a/integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/PriceConsumer.java b/integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/PriceConsumer.java new file mode 100644 index 0000000000000..d77507c91ace9 --- /dev/null +++ b/integration-tests/virtual-threads/amqp-virtual-threads/src/main/java/io/quarkus/it/vthreads/amqp/PriceConsumer.java @@ -0,0 +1,61 @@ +package io.quarkus.it.vthreads.amqp; + +import static io.quarkus.it.vthreads.amqp.AssertHelper.assertThatItDoesNotRunOnVirtualThread; +import static io.quarkus.it.vthreads.amqp.AssertHelper.assertThatItRunsOnADuplicatedContext; +import static io.quarkus.it.vthreads.amqp.AssertHelper.assertThatItRunsOnVirtualThread; + +import java.util.Random; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.atomic.AtomicInteger; + +import jakarta.enterprise.context.ApplicationScoped; + +import org.eclipse.microprofile.reactive.messaging.Incoming; +import org.eclipse.microprofile.reactive.messaging.Message; +import org.eclipse.microprofile.reactive.messaging.Outgoing; +import org.eclipse.microprofile.rest.client.inject.RestClient; + +import io.smallrye.common.annotation.RunOnVirtualThread; + +@ApplicationScoped +public class PriceConsumer { + + @RestClient + PriceAlertService alertService; + + @Incoming("prices") + @RunOnVirtualThread + public CompletionStage consume(Message msg) { + assertThatItRunsOnVirtualThread(); + assertThatItRunsOnADuplicatedContext(); + double price = msg.getPayload(); + if (price > 90.0) { + alertService.alertMessage(price); + } + return msg.ack().thenAccept(x -> { + assertThatItRunsOnADuplicatedContext(); + assertThatItDoesNotRunOnVirtualThread(); + }); + } + + @Incoming("prices") + @RunOnVirtualThread + public void consume(double price) { + assertThatItRunsOnVirtualThread(); + assertThatItRunsOnADuplicatedContext(); + if (price > 90.0) { + alertService.alert(price); + } + } + + Random r = new Random(); + AtomicInteger i = new AtomicInteger(); + + @Outgoing("prices-out") + @RunOnVirtualThread + public Message randomPriceGenerator() { + assertThatItRunsOnVirtualThread(); + return Message.of(r.nextDouble() * 10 * i.incrementAndGet()); + } + +} diff --git a/integration-tests/virtual-threads/amqp-virtual-threads/src/main/resources/application.properties b/integration-tests/virtual-threads/amqp-virtual-threads/src/main/resources/application.properties new file mode 100644 index 0000000000000..f212b575de362 --- /dev/null +++ b/integration-tests/virtual-threads/amqp-virtual-threads/src/main/resources/application.properties @@ -0,0 +1,7 @@ +price-alert/mp-rest/url=${test.url} +mp.messaging.incoming.prices.broadcast=true +mp.messaging.outgoing.prices-out.address=prices + +smallrye.messaging.worker..max-concurrency=10 + +quarkus.native.additional-build-args=--enable-preview diff --git a/integration-tests/virtual-threads/amqp-virtual-threads/src/test/java/io/quarkus/it/vthreads/amqp/VirtualThreadTest.java b/integration-tests/virtual-threads/amqp-virtual-threads/src/test/java/io/quarkus/it/vthreads/amqp/VirtualThreadTest.java new file mode 100644 index 0000000000000..4d44358a66087 --- /dev/null +++ b/integration-tests/virtual-threads/amqp-virtual-threads/src/test/java/io/quarkus/it/vthreads/amqp/VirtualThreadTest.java @@ -0,0 +1,36 @@ +package io.quarkus.it.vthreads.amqp; + +import static com.github.tomakehurst.wiremock.client.CountMatchingStrategy.GREATER_THAN_OR_EQUAL; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.http.RequestMethod.POST; +import static com.github.tomakehurst.wiremock.matching.RequestPatternBuilder.newRequestPattern; +import static org.awaitility.Awaitility.await; + +import org.junit.jupiter.api.Test; + +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.client.CountMatchingStrategy; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(WireMockExtension.class) +public class VirtualThreadTest { + + public static final int EXPECTED_CALLS = 10; + WireMockServer mockServer; + + @Test + void testAlert() { + await().untilAsserted(() -> mockServer.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, EXPECTED_CALLS), + newRequestPattern(POST, urlPathEqualTo("/price/alert")))); + } + + @Test + void testAlertMessage() { + await().untilAsserted(() -> mockServer.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, EXPECTED_CALLS), + newRequestPattern(POST, urlPathEqualTo("/price/alert-message")))); + } + +} diff --git a/integration-tests/virtual-threads/amqp-virtual-threads/src/test/java/io/quarkus/it/vthreads/amqp/WireMockExtension.java b/integration-tests/virtual-threads/amqp-virtual-threads/src/test/java/io/quarkus/it/vthreads/amqp/WireMockExtension.java new file mode 100644 index 0000000000000..8d3499c6d2856 --- /dev/null +++ b/integration-tests/virtual-threads/amqp-virtual-threads/src/test/java/io/quarkus/it/vthreads/amqp/WireMockExtension.java @@ -0,0 +1,41 @@ +package io.quarkus.it.vthreads.amqp; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + +import java.util.Map; + +import com.github.tomakehurst.wiremock.WireMockServer; + +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; + +public class WireMockExtension implements QuarkusTestResourceLifecycleManager { + + private WireMockServer wireMockServer; + + @Override + public Map start() { + wireMockServer = new WireMockServer(); + wireMockServer.start(); + + wireMockServer.stubFor(post(urlEqualTo("/price/alert")) + .willReturn(aResponse().withBody("ok"))); + wireMockServer.stubFor(post(urlEqualTo("/price/alert-message")) + .willReturn(aResponse().withBody("ok"))); + + return Map.of("price-alert/mp-rest/url", wireMockServer.baseUrl()); + } + + @Override + public void inject(TestInjector testInjector) { + testInjector.injectIntoFields(wireMockServer, f -> f.getType().isAssignableFrom(WireMockServer.class)); + } + + @Override + public void stop() { + if (null != wireMockServer) { + wireMockServer.stop(); + } + } +} diff --git a/integration-tests/virtual-threads/jms-virtual-threads/disable-native-profile b/integration-tests/virtual-threads/jms-virtual-threads/disable-native-profile new file mode 100644 index 0000000000000..011a7cc4571d5 --- /dev/null +++ b/integration-tests/virtual-threads/jms-virtual-threads/disable-native-profile @@ -0,0 +1 @@ +This file disables the native profile in the parent pom.xml of this module. \ No newline at end of file diff --git a/integration-tests/virtual-threads/jms-virtual-threads/pom.xml b/integration-tests/virtual-threads/jms-virtual-threads/pom.xml new file mode 100644 index 0000000000000..c9696a8c7a126 --- /dev/null +++ b/integration-tests/virtual-threads/jms-virtual-threads/pom.xml @@ -0,0 +1,151 @@ + + + 4.0.0 + + + quarkus-virtual-threads-integration-tests-parent + io.quarkus + 999-SNAPSHOT + + + quarkus-integration-test-virtual-threads-jms + Quarkus - Integration Tests - Virtual Threads - JMS + + + + + io.quarkiverse.artemis + quarkus-artemis-bom + 3.0.1 + pom + import + + + + + + io.quarkus + quarkus-resteasy-reactive-jackson + + + io.quarkus + quarkus-smallrye-reactive-messaging + + + io.smallrye.reactive + smallrye-reactive-messaging-jms + 4.8.0 + + + io.quarkus + quarkus-rest-client-reactive + + + io.quarkiverse.artemis + quarkus-artemis-jms + + + io.quarkiverse.artemis + quarkus-test-artemis + test + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + org.awaitility + awaitility + test + + + org.assertj + assertj-core + test + + + io.quarkus + quarkus-test-vertx + test + + + io.quarkus + quarkus-junit5-mockito + test + + + com.github.tomakehurst + wiremock-jre8-standalone + test + + + io.quarkus + quarkus-test-common + test + + + + + io.quarkus + quarkus-smallrye-reactive-messaging-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-rest-client-reactive-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-resteasy-reactive-jackson-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + + io.quarkus + quarkus-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + diff --git a/integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/AssertHelper.java b/integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/AssertHelper.java new file mode 100644 index 0000000000000..1f1c0ad2965dd --- /dev/null +++ b/integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/AssertHelper.java @@ -0,0 +1,68 @@ +package io.quarkus.it.vthreads.jms; + +import java.lang.reflect.Method; + +import io.quarkus.arc.Arc; +import io.smallrye.common.vertx.VertxContext; +import io.vertx.core.Vertx; + +public class AssertHelper { + + /** + * Asserts that the current method: + * - runs on a duplicated context + * - runs on a virtual thread + * - has the request scope activated + */ + public static void assertEverything() { + assertThatTheRequestScopeIsActive(); + assertThatItRunsOnVirtualThread(); + assertThatItRunsOnADuplicatedContext(); + } + + public static void assertThatTheRequestScopeIsActive() { + if (!Arc.container().requestContext().isActive()) { + throw new AssertionError(("Expected the request scope to be active")); + } + } + + public static void assertThatItRunsOnADuplicatedContext() { + var context = Vertx.currentContext(); + if (context == null) { + throw new AssertionError("The method does not run on a Vert.x context"); + } + if (!VertxContext.isOnDuplicatedContext()) { + throw new AssertionError("The method does not run on a Vert.x **duplicated** context"); + } + } + + public static void assertThatItRunsOnVirtualThread() { + // We cannot depend on a Java 20. + try { + Method isVirtual = Thread.class.getMethod("isVirtual"); + isVirtual.setAccessible(true); + boolean virtual = (Boolean) isVirtual.invoke(Thread.currentThread()); + if (!virtual) { + throw new AssertionError("Thread " + Thread.currentThread() + " is not a virtual thread"); + } + } catch (Exception e) { + throw new AssertionError( + "Thread " + Thread.currentThread() + " is not a virtual thread - cannot invoke Thread.isVirtual()", e); + } + } + + public static void assertThatItDoesNotRunOnVirtualThread() { + // We cannot depend on a Java 20. + try { + Method isVirtual = Thread.class.getMethod("isVirtual"); + isVirtual.setAccessible(true); + boolean virtual = (Boolean) isVirtual.invoke(Thread.currentThread()); + if (virtual) { + throw new AssertionError("Thread " + Thread.currentThread() + " is a virtual thread"); + } + } catch (Exception e) { + throw new AssertionError( + "Thread " + Thread.currentThread() + " is a virtual thread - but cannot invoke Thread.isVirtual()", e); + } + } +} diff --git a/integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/PriceAlertService.java b/integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/PriceAlertService.java new file mode 100644 index 0000000000000..9554c0ad931ea --- /dev/null +++ b/integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/PriceAlertService.java @@ -0,0 +1,23 @@ +package io.quarkus.it.vthreads.jms; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.MediaType; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +@Path("price") +@RegisterRestClient(configKey = "price-alert") +public interface PriceAlertService { + + @Path("alert") + @POST + @Consumes(MediaType.TEXT_PLAIN) + String alert(double value); + + @Path("alert-message") + @POST + @Consumes(MediaType.TEXT_PLAIN) + String alertMessage(double value); +} diff --git a/integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/PriceConsumer.java b/integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/PriceConsumer.java new file mode 100644 index 0000000000000..336974a7c66d8 --- /dev/null +++ b/integration-tests/virtual-threads/jms-virtual-threads/src/main/java/io/quarkus/it/vthreads/jms/PriceConsumer.java @@ -0,0 +1,55 @@ +package io.quarkus.it.vthreads.jms; + +import static io.quarkus.it.vthreads.jms.AssertHelper.assertThatItDoesNotRunOnVirtualThread; +import static io.quarkus.it.vthreads.jms.AssertHelper.assertThatItRunsOnVirtualThread; + +import java.util.Random; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.atomic.AtomicInteger; + +import jakarta.enterprise.context.ApplicationScoped; + +import org.eclipse.microprofile.reactive.messaging.Incoming; +import org.eclipse.microprofile.reactive.messaging.Message; +import org.eclipse.microprofile.reactive.messaging.Outgoing; +import org.eclipse.microprofile.rest.client.inject.RestClient; + +import io.smallrye.common.annotation.RunOnVirtualThread; + +@ApplicationScoped +public class PriceConsumer { + + @RestClient + PriceAlertService alertService; + + @Incoming("prices") + @RunOnVirtualThread + public CompletionStage consume(Message msg) { + assertThatItRunsOnVirtualThread(); + double price = msg.getPayload(); + if (price > 90.0) { + alertService.alertMessage(price); + } + return msg.ack().thenAccept(x -> assertThatItDoesNotRunOnVirtualThread()); + } + + @Incoming("prices") + @RunOnVirtualThread + public void consume(double price) { + assertThatItRunsOnVirtualThread(); + if (price > 90.0) { + alertService.alert(price); + } + } + + Random r = new Random(); + AtomicInteger i = new AtomicInteger(); + + @Outgoing("prices-out") + @RunOnVirtualThread + public Message randomPriceGenerator() { + assertThatItRunsOnVirtualThread(); + return Message.of(r.nextDouble() * 10 * i.incrementAndGet()); + } + +} diff --git a/integration-tests/virtual-threads/jms-virtual-threads/src/main/resources/application.properties b/integration-tests/virtual-threads/jms-virtual-threads/src/main/resources/application.properties new file mode 100644 index 0000000000000..176a3abff2075 --- /dev/null +++ b/integration-tests/virtual-threads/jms-virtual-threads/src/main/resources/application.properties @@ -0,0 +1,10 @@ +price-alert/mp-rest/url=${test.url} +mp.messaging.incoming.prices.broadcast=true +mp.messaging.outgoing.prices-out.destination=prices + +smallrye.messaging.worker..max-concurrency=5 + +quarkus.native.additional-build-args=--enable-preview + +quarkus.artemis.devservices.enabled=true +quarkus.artemis.devservices.image-name=quay.io/artemiscloud/activemq-artemis-broker:1.0.18 diff --git a/integration-tests/virtual-threads/jms-virtual-threads/src/test/java/io/quarkus/it/vthreads/jms/VirtualThreadTest.java b/integration-tests/virtual-threads/jms-virtual-threads/src/test/java/io/quarkus/it/vthreads/jms/VirtualThreadTest.java new file mode 100644 index 0000000000000..bb115b5ea1d3e --- /dev/null +++ b/integration-tests/virtual-threads/jms-virtual-threads/src/test/java/io/quarkus/it/vthreads/jms/VirtualThreadTest.java @@ -0,0 +1,36 @@ +package io.quarkus.it.vthreads.jms; + +import static com.github.tomakehurst.wiremock.client.CountMatchingStrategy.GREATER_THAN_OR_EQUAL; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.http.RequestMethod.POST; +import static com.github.tomakehurst.wiremock.matching.RequestPatternBuilder.newRequestPattern; +import static org.awaitility.Awaitility.await; + +import org.junit.jupiter.api.Test; + +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.client.CountMatchingStrategy; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(WireMockExtension.class) +public class VirtualThreadTest { + + public static final int EXPECTED_CALLS = 10; + WireMockServer mockServer; + + @Test + void testAlert() { + await().untilAsserted(() -> mockServer.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, EXPECTED_CALLS), + newRequestPattern(POST, urlPathEqualTo("/price/alert")))); + } + + @Test + void testAlertMessage() { + await().untilAsserted(() -> mockServer.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, EXPECTED_CALLS), + newRequestPattern(POST, urlPathEqualTo("/price/alert-message")))); + } + +} diff --git a/integration-tests/virtual-threads/jms-virtual-threads/src/test/java/io/quarkus/it/vthreads/jms/WireMockExtension.java b/integration-tests/virtual-threads/jms-virtual-threads/src/test/java/io/quarkus/it/vthreads/jms/WireMockExtension.java new file mode 100644 index 0000000000000..43584cd30366f --- /dev/null +++ b/integration-tests/virtual-threads/jms-virtual-threads/src/test/java/io/quarkus/it/vthreads/jms/WireMockExtension.java @@ -0,0 +1,41 @@ +package io.quarkus.it.vthreads.jms; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + +import java.util.Map; + +import com.github.tomakehurst.wiremock.WireMockServer; + +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; + +public class WireMockExtension implements QuarkusTestResourceLifecycleManager { + + private WireMockServer wireMockServer; + + @Override + public Map start() { + wireMockServer = new WireMockServer(); + wireMockServer.start(); + + wireMockServer.stubFor(post(urlEqualTo("/price/alert")) + .willReturn(aResponse().withBody("ok"))); + wireMockServer.stubFor(post(urlEqualTo("/price/alert-message")) + .willReturn(aResponse().withBody("ok"))); + + return Map.of("price-alert/mp-rest/url", wireMockServer.baseUrl()); + } + + @Override + public void inject(TestInjector testInjector) { + testInjector.injectIntoFields(wireMockServer, f -> f.getType().isAssignableFrom(WireMockServer.class)); + } + + @Override + public void stop() { + if (null != wireMockServer) { + wireMockServer.stop(); + } + } +} diff --git a/integration-tests/virtual-threads/kafka-virtual-threads/disable-native-profile b/integration-tests/virtual-threads/kafka-virtual-threads/disable-native-profile new file mode 100644 index 0000000000000..011a7cc4571d5 --- /dev/null +++ b/integration-tests/virtual-threads/kafka-virtual-threads/disable-native-profile @@ -0,0 +1 @@ +This file disables the native profile in the parent pom.xml of this module. \ No newline at end of file diff --git a/integration-tests/virtual-threads/kafka-virtual-threads/pom.xml b/integration-tests/virtual-threads/kafka-virtual-threads/pom.xml new file mode 100644 index 0000000000000..a2c0d1f7fc8f2 --- /dev/null +++ b/integration-tests/virtual-threads/kafka-virtual-threads/pom.xml @@ -0,0 +1,125 @@ + + + 4.0.0 + + + quarkus-virtual-threads-integration-tests-parent + io.quarkus + 999-SNAPSHOT + + + quarkus-integration-test-virtual-threads-kafka + Quarkus - Integration Tests - Virtual Threads - Kafka + + + + io.quarkus + quarkus-resteasy-reactive-jackson + + + io.quarkus + quarkus-smallrye-reactive-messaging-kafka + + + io.quarkus + quarkus-rest-client-reactive + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + org.awaitility + awaitility + test + + + org.assertj + assertj-core + test + + + io.quarkus + quarkus-test-vertx + test + + + io.quarkus + quarkus-junit5-mockito + test + + + com.github.tomakehurst + wiremock-jre8-standalone + test + + + io.quarkus + quarkus-test-common + test + + + + + io.quarkus + quarkus-smallrye-reactive-messaging-kafka-deployment + ${project.version} + pom + test + + + * + * + + + + io.quarkus + quarkus-rest-client-reactive-deployment + ${project.version} + pom + test + + + * + * + + + + + io.quarkus + quarkus-resteasy-reactive-jackson-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + + io.quarkus + quarkus-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + diff --git a/integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/AssertHelper.java b/integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/AssertHelper.java new file mode 100644 index 0000000000000..35299e5918b7c --- /dev/null +++ b/integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/AssertHelper.java @@ -0,0 +1,68 @@ +package io.quarkus.it.vthreads.kafka; + +import java.lang.reflect.Method; + +import io.quarkus.arc.Arc; +import io.smallrye.common.vertx.VertxContext; +import io.vertx.core.Vertx; + +public class AssertHelper { + + /** + * Asserts that the current method: + * - runs on a duplicated context + * - runs on a virtual thread + * - has the request scope activated + */ + public static void assertEverything() { + assertThatTheRequestScopeIsActive(); + assertThatItRunsOnVirtualThread(); + assertThatItRunsOnADuplicatedContext(); + } + + public static void assertThatTheRequestScopeIsActive() { + if (!Arc.container().requestContext().isActive()) { + throw new AssertionError(("Expected the request scope to be active")); + } + } + + public static void assertThatItRunsOnADuplicatedContext() { + var context = Vertx.currentContext(); + if (context == null) { + throw new AssertionError("The method does not run on a Vert.x context"); + } + if (!VertxContext.isOnDuplicatedContext()) { + throw new AssertionError("The method does not run on a Vert.x **duplicated** context"); + } + } + + public static void assertThatItRunsOnVirtualThread() { + // We cannot depend on a Java 20. + try { + Method isVirtual = Thread.class.getMethod("isVirtual"); + isVirtual.setAccessible(true); + boolean virtual = (Boolean) isVirtual.invoke(Thread.currentThread()); + if (!virtual) { + throw new AssertionError("Thread " + Thread.currentThread() + " is not a virtual thread"); + } + } catch (Exception e) { + throw new AssertionError( + "Thread " + Thread.currentThread() + " is not a virtual thread - cannot invoke Thread.isVirtual()", e); + } + } + + public static void assertThatItDoesNotRunOnVirtualThread() { + // We cannot depend on a Java 20. + try { + Method isVirtual = Thread.class.getMethod("isVirtual"); + isVirtual.setAccessible(true); + boolean virtual = (Boolean) isVirtual.invoke(Thread.currentThread()); + if (virtual) { + throw new AssertionError("Thread " + Thread.currentThread() + " is a virtual thread"); + } + } catch (Exception e) { + throw new AssertionError( + "Thread " + Thread.currentThread() + " is a virtual thread - but cannot invoke Thread.isVirtual()", e); + } + } +} diff --git a/integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/PriceAlertService.java b/integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/PriceAlertService.java new file mode 100644 index 0000000000000..c45867475f199 --- /dev/null +++ b/integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/PriceAlertService.java @@ -0,0 +1,23 @@ +package io.quarkus.it.vthreads.kafka; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.MediaType; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +@Path("price") +@RegisterRestClient(configKey = "price-alert") +public interface PriceAlertService { + + @Path("alert") + @POST + @Consumes(MediaType.TEXT_PLAIN) + String alert(double value); + + @Path("alert-message") + @POST + @Consumes(MediaType.TEXT_PLAIN) + String alertMessage(double value); +} diff --git a/integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/PriceConsumer.java b/integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/PriceConsumer.java new file mode 100644 index 0000000000000..f9256b5065789 --- /dev/null +++ b/integration-tests/virtual-threads/kafka-virtual-threads/src/main/java/io/quarkus/it/vthreads/kafka/PriceConsumer.java @@ -0,0 +1,61 @@ +package io.quarkus.it.vthreads.kafka; + +import static io.quarkus.it.vthreads.kafka.AssertHelper.assertThatItDoesNotRunOnVirtualThread; +import static io.quarkus.it.vthreads.kafka.AssertHelper.assertThatItRunsOnADuplicatedContext; +import static io.quarkus.it.vthreads.kafka.AssertHelper.assertThatItRunsOnVirtualThread; + +import java.util.Random; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.atomic.AtomicInteger; + +import jakarta.enterprise.context.ApplicationScoped; + +import org.eclipse.microprofile.reactive.messaging.Incoming; +import org.eclipse.microprofile.reactive.messaging.Message; +import org.eclipse.microprofile.reactive.messaging.Outgoing; +import org.eclipse.microprofile.rest.client.inject.RestClient; + +import io.smallrye.common.annotation.RunOnVirtualThread; + +@ApplicationScoped +public class PriceConsumer { + + @RestClient + PriceAlertService alertService; + + @Incoming("prices") + @RunOnVirtualThread + public CompletionStage consume(Message msg) { + assertThatItRunsOnVirtualThread(); + assertThatItRunsOnADuplicatedContext(); + double price = msg.getPayload(); + if (price > 90.0) { + alertService.alertMessage(price); + } + return msg.ack().thenAccept(x -> { + assertThatItRunsOnADuplicatedContext(); + assertThatItDoesNotRunOnVirtualThread(); + }); + } + + @Incoming("prices") + @RunOnVirtualThread + public void consume(double price) { + assertThatItRunsOnVirtualThread(); + assertThatItRunsOnADuplicatedContext(); + if (price > 90.0) { + alertService.alert(price); + } + } + + Random r = new Random(); + AtomicInteger i = new AtomicInteger(); + + @Outgoing("prices-out") + @RunOnVirtualThread + public Message randomPriceGenerator() { + assertThatItRunsOnVirtualThread(); + return Message.of(r.nextDouble() * 10 * i.incrementAndGet()); + } + +} diff --git a/integration-tests/virtual-threads/kafka-virtual-threads/src/main/resources/application.properties b/integration-tests/virtual-threads/kafka-virtual-threads/src/main/resources/application.properties new file mode 100644 index 0000000000000..f4a4265ca9756 --- /dev/null +++ b/integration-tests/virtual-threads/kafka-virtual-threads/src/main/resources/application.properties @@ -0,0 +1,8 @@ +price-alert/mp-rest/url=${test.url} +mp.messaging.incoming.prices.broadcast=true +mp.messaging.incoming.prices.auto.offset.reset=earliest +mp.messaging.outgoing.prices-out.topic=prices + +smallrye.messaging.worker..max-concurrency=10 + +quarkus.native.additional-build-args=--enable-preview diff --git a/integration-tests/virtual-threads/kafka-virtual-threads/src/test/java/io/quarkus/it/vthreads/kafka/VirtualThreadTest.java b/integration-tests/virtual-threads/kafka-virtual-threads/src/test/java/io/quarkus/it/vthreads/kafka/VirtualThreadTest.java new file mode 100644 index 0000000000000..547055b00a1f1 --- /dev/null +++ b/integration-tests/virtual-threads/kafka-virtual-threads/src/test/java/io/quarkus/it/vthreads/kafka/VirtualThreadTest.java @@ -0,0 +1,36 @@ +package io.quarkus.it.vthreads.kafka; + +import static com.github.tomakehurst.wiremock.client.CountMatchingStrategy.GREATER_THAN_OR_EQUAL; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.http.RequestMethod.POST; +import static com.github.tomakehurst.wiremock.matching.RequestPatternBuilder.newRequestPattern; +import static org.awaitility.Awaitility.await; + +import org.junit.jupiter.api.Test; + +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.client.CountMatchingStrategy; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +@QuarkusTestResource(WireMockExtension.class) +public class VirtualThreadTest { + + public static final int EXPECTED_CALLS = 10; + WireMockServer mockServer; + + @Test + void testAlert() { + await().untilAsserted(() -> mockServer.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, EXPECTED_CALLS), + newRequestPattern(POST, urlPathEqualTo("/price/alert")))); + } + + @Test + void testAlertMessage() { + await().untilAsserted(() -> mockServer.verify(new CountMatchingStrategy(GREATER_THAN_OR_EQUAL, EXPECTED_CALLS), + newRequestPattern(POST, urlPathEqualTo("/price/alert-message")))); + } + +} diff --git a/integration-tests/virtual-threads/kafka-virtual-threads/src/test/java/io/quarkus/it/vthreads/kafka/WireMockExtension.java b/integration-tests/virtual-threads/kafka-virtual-threads/src/test/java/io/quarkus/it/vthreads/kafka/WireMockExtension.java new file mode 100644 index 0000000000000..d081410fb3bb9 --- /dev/null +++ b/integration-tests/virtual-threads/kafka-virtual-threads/src/test/java/io/quarkus/it/vthreads/kafka/WireMockExtension.java @@ -0,0 +1,41 @@ +package io.quarkus.it.vthreads.kafka; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; + +import java.util.Map; + +import com.github.tomakehurst.wiremock.WireMockServer; + +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; + +public class WireMockExtension implements QuarkusTestResourceLifecycleManager { + + private WireMockServer wireMockServer; + + @Override + public Map start() { + wireMockServer = new WireMockServer(); + wireMockServer.start(); + + wireMockServer.stubFor(post(urlEqualTo("/price/alert")) + .willReturn(aResponse().withBody("ok"))); + wireMockServer.stubFor(post(urlEqualTo("/price/alert-message")) + .willReturn(aResponse().withBody("ok"))); + + return Map.of("price-alert/mp-rest/url", wireMockServer.baseUrl()); + } + + @Override + public void inject(TestInjector testInjector) { + testInjector.injectIntoFields(wireMockServer, f -> f.getType().isAssignableFrom(WireMockServer.class)); + } + + @Override + public void stop() { + if (null != wireMockServer) { + wireMockServer.stop(); + } + } +} diff --git a/integration-tests/virtual-threads/pom.xml b/integration-tests/virtual-threads/pom.xml index 7d84384f550bb..dcf51ce6db74c 100644 --- a/integration-tests/virtual-threads/pom.xml +++ b/integration-tests/virtual-threads/pom.xml @@ -23,7 +23,13 @@ true - + + grpc-virtual-threads + resteasy-reactive-virtual-threads + mailer-virtual-threads + redis-virtual-threads + rest-client-reactive-virtual-threads + @@ -90,7 +96,8 @@ org.jboss.logmanager.LogManager ${maven.home} - --enable-preview -Djdk.tracePinnedThreads + + --enable-preview -Djdk.tracePinnedThreads -Dgradle.scan.captureTestLogging=false ${skipTests} @@ -204,13 +211,6 @@ [20,) - - grpc-virtual-threads - resteasy-reactive-virtual-threads - mailer-virtual-threads - redis-virtual-threads - rest-client-reactive-virtual-threads - 20 true From 6ab68f5d49708909bab844ad5b3c1aa4ffd7047c Mon Sep 17 00:00:00 2001 From: Ozan Gunalp Date: Fri, 21 Jul 2023 17:54:52 +0200 Subject: [PATCH 2/2] Enable native tests in CI for virtual thread tests Move JVM 19 tests to 20 --- .github/filter-virtual-threads-tests-json.sh | 51 +++++++++++++ .github/matrix-jvm-tests.json | 4 +- .github/virtual-threads-tests.json | 16 ++++ .github/workflows/ci-actions-incremental.yml | 47 +++++++----- integration-tests/pom.xml | 16 +--- .../disable-native-profile | 1 - .../it/vthreads/amqp/NoPinningVerify.java | 76 +++++++++++++++++++ .../it/vthreads/amqp/VirtualThreadITCase.java | 7 ++ ...{NoPinningIT.java => NoPinningVerify.java} | 2 +- .../disable-native-profile | 1 - .../it/vthreads/jms/NoPinningVerify.java | 76 +++++++++++++++++++ .../it/vthreads/jms/VirtualThreadITCase.java | 7 ++ .../disable-native-profile | 1 - .../it/vthreads/kafka/NoPinningVerify.java | 76 +++++++++++++++++++ .../vthreads/kafka/VirtualThreadITCase.java | 7 ++ ...{NoPinningIT.java => NoPinningVerify.java} | 2 +- integration-tests/virtual-threads/pom.xml | 18 ++++- ...{NoPinningIT.java => NoPinningVerify.java} | 2 +- ...{NoPinningIT.java => NoPinningVerify.java} | 2 +- ...{NoPinningIT.java => NoPinningVerify.java} | 2 +- 20 files changed, 370 insertions(+), 44 deletions(-) create mode 100755 .github/filter-virtual-threads-tests-json.sh create mode 100644 .github/virtual-threads-tests.json delete mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/disable-native-profile create mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/src/test/java/io/quarkus/it/vthreads/amqp/NoPinningVerify.java create mode 100644 integration-tests/virtual-threads/amqp-virtual-threads/src/test/java/io/quarkus/it/vthreads/amqp/VirtualThreadITCase.java rename integration-tests/virtual-threads/grpc-virtual-threads/src/test/java/io/quarkus/grpc/example/streaming/{NoPinningIT.java => NoPinningVerify.java} (98%) delete mode 100644 integration-tests/virtual-threads/jms-virtual-threads/disable-native-profile create mode 100644 integration-tests/virtual-threads/jms-virtual-threads/src/test/java/io/quarkus/it/vthreads/jms/NoPinningVerify.java create mode 100644 integration-tests/virtual-threads/jms-virtual-threads/src/test/java/io/quarkus/it/vthreads/jms/VirtualThreadITCase.java delete mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/disable-native-profile create mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/src/test/java/io/quarkus/it/vthreads/kafka/NoPinningVerify.java create mode 100644 integration-tests/virtual-threads/kafka-virtual-threads/src/test/java/io/quarkus/it/vthreads/kafka/VirtualThreadITCase.java rename integration-tests/virtual-threads/mailer-virtual-threads/src/test/java/io/quarkus/virtual/mail/{NoPinningIT.java => NoPinningVerify.java} (98%) rename integration-tests/virtual-threads/redis-virtual-threads/src/test/java/io/quarkus/virtual/redis/{NoPinningIT.java => NoPinningVerify.java} (98%) rename integration-tests/virtual-threads/rest-client-reactive-virtual-threads/src/test/java/io/quarkus/virtual/rest/{NoPinningIT.java => NoPinningVerify.java} (98%) rename integration-tests/virtual-threads/resteasy-reactive-virtual-threads/src/test/java/io/quarkus/virtual/rr/{NoPinningIT.java => NoPinningVerify.java} (98%) diff --git a/.github/filter-virtual-threads-tests-json.sh b/.github/filter-virtual-threads-tests-json.sh new file mode 100755 index 0000000000000..28c2efee14f6c --- /dev/null +++ b/.github/filter-virtual-threads-tests-json.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Purpose: Prints a filtered version of virtual-threads-tests.json, with "test-modules" reduced to the ones passed in as the first argument. +# This first argument is expected to the define one module per line. +# "include" elements that (after filtering) have no "test-modules" anymore are deleted entirely! +# Note: This script is only for CI and does therefore not aim to be compatible with BSD/macOS. + +set -e -u -o pipefail +shopt -s failglob + +# path of this shell script +PRG_PATH=$( cd "$(dirname "$0")" ; pwd -P ) + +JSON=$(cat ${PRG_PATH}/virtual-threads-tests.json) + +# Step 0: print unfiltered json and exit in case the parameter is empty (assumption: full build) +if [ -z "$1" ] +then + echo "${JSON}" + exit 0 +fi + +# Step 1: build an expression for grep that will only extract the given modules from each "test-modules" list, +# including a trailing comma (if exists). Note: mvn doesn't mind something like -pl 'foo,'. +EXPR='((?:(?<=^)|(?<=,)|(?<=, ))(' +while read -r impacted +do + EXPR+="${impacted}|" +done < <(echo -n "$1" | ggrep -Po '(?<=integration-tests/virtual-threads/).+') +EXPR+=')(,|$))+' + +# Step 2: apply the filter expression via grep to each "test-modules" list and replace each original list with the filtered one +while read -r modules +do + # Notes: + # - trailing "|" (after EXPR) avoids grep return code > 0 if nothing matches (which is a valid case) + # - "paste" joins all matches to get a single line + FILTERED=$(echo -n "${modules}" | ggrep -Po "${EXPR}|" | paste -sd " " -) + JSON=$(echo -n "${JSON}" | sed "s|${modules}|${FILTERED}|") +done < <(echo -n "${JSON}" | jq -r '.include[] | ."test-modules"') + +# Step 3: delete entire elements from "include" array that now have an empty "test-modules" list +JSON=$(echo "${JSON}" | jq 'del(.include[] | select(."test-modules" == ""))') + +# Step 4: echo final result, printing only {} in case _all_ elements were removed from "include" array +if [ -z "$(echo "${JSON}" | jq '.include[]')" ] +then + echo -n '{}' +else + echo -n "${JSON}" +fi diff --git a/.github/matrix-jvm-tests.json b/.github/matrix-jvm-tests.json index b20241376fe3d..e4ace13213865 100644 --- a/.github/matrix-jvm-tests.json +++ b/.github/matrix-jvm-tests.json @@ -13,8 +13,8 @@ "os-name": "ubuntu-latest" } , { - "name": "19", - "java-version": 19, + "name": "20", + "java-version": 20, "maven_args": "$JVM_TEST_MAVEN_ARGS", "maven_opts": "-Xmx2g -XX:MaxMetaspaceSize=1g", "os-name": "ubuntu-latest" diff --git a/.github/virtual-threads-tests.json b/.github/virtual-threads-tests.json new file mode 100644 index 0000000000000..22fd2166fa317 --- /dev/null +++ b/.github/virtual-threads-tests.json @@ -0,0 +1,16 @@ +{ + "include": [ + { + "category": "Main", + "timeout": 45, + "test-modules": "grpc-virtual-threads, mailer-virtual-threads, redis-virtual-threads, rest-client-reactive-virtual-threads, resteasy-reactive-virtual-threads", + "os-name": "ubuntu-latest" + }, + { + "category": "Messaging", + "timeout": 45, + "test-modules": "amqp-virtual-threads, jms-virtual-threads, kafka-virtual-threads", + "os-name": "ubuntu-latest" + } + ] +} diff --git a/.github/workflows/ci-actions-incremental.yml b/.github/workflows/ci-actions-incremental.yml index 05122939c3143..f6df078b36e60 100644 --- a/.github/workflows/ci-actions-incremental.yml +++ b/.github/workflows/ci-actions-incremental.yml @@ -205,6 +205,7 @@ jobs: outputs: native_matrix: ${{ steps.calc-native-matrix.outputs.matrix }} jvm_matrix: ${{ steps.calc-jvm-matrix.outputs.matrix }} + virtual_threads_matrix: ${{ steps.calc-virtual_threads-matrix.outputs.matrix }} run_jvm: ${{ steps.calc-run-flags.outputs.run_jvm }} run_devtools: ${{ steps.calc-run-flags.outputs.run_devtools }} run_gradle: ${{ steps.calc-run-flags.outputs.run_gradle }} @@ -226,6 +227,13 @@ jobs: json=$(.github/filter-jvm-tests-json.sh) echo "${json}" echo "matrix=${json}" >> $GITHUB_OUTPUT + - name: Calculate matrix from virtual-threads-tests.json + id: calc-virtual_threads-matrix + run: | + echo "GIB_IMPACTED_MODULES: ${GIB_IMPACTED_MODULES}" + json=$(.github/filter-virtual-threads-tests-json.sh "${GIB_IMPACTED_MODULES}" | tr -d '\n') + echo "${json}" + echo "matrix=${json}" >> $GITHUB_OUTPUT - name: Calculate run flags id: calc-run-flags run: | @@ -602,23 +610,17 @@ jobs: quarkus-quickstarts/target/build-report.json quarkus-quickstarts/LICENSE retention-days: 2 - virtual-thread-tests: - name: Virtual Thread Support Tests - JDK ${{matrix.java.name}} - runs-on: ${{matrix.java.os-name}} + virtual-thread-native-tests: + name: Virtual Thread Support Tests Native - ${{matrix.category}} + runs-on: ${{matrix.os-name}} needs: [build-jdk11, calculate-test-jobs] # Skip main in forks - if: "needs.calculate-test-jobs.outputs.run_quickstarts == 'true' && (github.repository == 'quarkusio/quarkus' || !endsWith(github.ref, '/main'))" - timeout-minutes: 90 + if: "needs.calculate-test-jobs.outputs.virtual_threads_matrix != '{}' && (github.repository == 'quarkusio/quarkus' || !endsWith(github.ref, '/main'))" + timeout-minutes: ${{matrix.timeout}} strategy: + max-parallel: 12 fail-fast: false - matrix: - java: - - { - name: "20", - java-version: 20, - os-name: "ubuntu-latest", - extra-args: "--enable-preview" - } + matrix: ${{ fromJson(needs.calculate-test-jobs.outputs.virtual_threads_matrix) }} steps: - uses: actions/checkout@v3 - name: Download Maven Repo @@ -629,19 +631,28 @@ jobs: - name: Extract Maven Repo shell: bash run: tar -xzf maven-repo.tgz -C ~ - - name: Set up JDK ${{ matrix.java.java-version }} + - name: Set up JDK 20 uses: actions/setup-java@v3 with: distribution: temurin - java-version: ${{ matrix.java.java-version }} - - name: Run tests + java-version: 20 + # We do this so we can get better analytics for the downloaded version of the build images + - name: Update Docker Client User Agent + shell: bash + run: | + cat <<< $(jq '.HttpHeaders += {"User-Agent": "Quarkus-CI-Docker-Client"}' ~/.docker/config.json) > ~/.docker/config.json + - name: Build + shell: bash + env: + TEST_MODULES: ${{matrix.test-modules}} + CONTAINER_BUILD: ${{startsWith(matrix.os-name, 'windows') && 'false' || 'true'}} run: | - export LANG=en_US && ./mvnw -e -B -fae --settings .github/mvn-settings.xml -f integration-tests/virtual-threads clean verify -Dnative -Dextra-args=${{matrix.java.extra-args}} -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-20 + export LANG=en_US && ./mvnw $COMMON_MAVEN_ARGS -f integration-tests/virtual-threads -pl "$TEST_MODULES" $NATIVE_TEST_MAVEN_ARGS -Dextra-args=--enable-preview -Dquarkus.native.container-build=true -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-20 - name: Upload build reports (if build failed) uses: actions/upload-artifact@v3 if: ${{ failure() || cancelled() }} with: - name: "build-reports-Virtual Thread Support - JDK ${{matrix.java.name}}" + name: "build-reports-Virtual Thread Support Tests Native - ${{matrix.category}}" path: | integration-tests/virtual-threads/**/target/*-reports/TEST-*.xml integration-tests/virtual-threads/target/build-report.json diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 4d581c0c235cc..7ad38528f0246 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -388,6 +388,8 @@ istio management-interface management-interface-auth + + virtual-threads @@ -405,20 +407,6 @@ - - - java-20 - - - !no-test-modules - - [20,) - - - virtual-threads - - -