From c64c335f75b7bb1ee161a2f535507f0d31a80cca Mon Sep 17 00:00:00 2001 From: Victor Gallet Date: Thu, 28 Oct 2021 15:38:48 +0200 Subject: [PATCH 1/3] Reactive Messaging codestart * fix #20872 * created `MyReactiveMessagingApplication` to demonstrates `@Emitter`, `@Incoming` and `@Outgoing` annotations. * created dynamic application.yml based on selected extension * added codestart integration test --- .../base/README.tpl.qute.md | 12 ++++ .../main/resources/application.tpl.qute.yml | 66 +++++++++++++++++++ .../codestart.yml | 12 ++++ .../acme/MyReactiveMessagingApplication.java | 35 ++++++++++ .../MyReactiveMessagingApplicationTest.java | 59 +++++++++++++++++ .../resources/META-INF/quarkus-extension.yaml | 7 +- .../resources/META-INF/quarkus-extension.yaml | 5 ++ .../resources/META-INF/quarkus-extension.yaml | 5 ++ .../resources/META-INF/quarkus-extension.yaml | 5 ++ .../codestarts/QuarkusCodestartTest.java | 4 +- .../quarkus/QuarkusCodestartBuildIT.java | 2 +- .../quarkus/ReactiveMessagingCodestartIT.java | 54 +++++++++++++++ .../src_main_resources_application.properties | 8 +++ ...ark_us_MyReactiveMessagingApplication.java | 35 ++++++++++ .../src_main_resources_application.properties | 8 +++ ...us_MyReactiveMessagingApplicationTest.java | 59 +++++++++++++++++ .../src_main_resources_application.properties | 16 +++++ 17 files changed, 389 insertions(+), 3 deletions(-) create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/base/README.tpl.qute.md create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/base/src/main/resources/application.tpl.qute.yml create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/codestart.yml create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/java/src/main/java/org/acme/MyReactiveMessagingApplication.java create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/java/src/test/java/org/acme/MyReactiveMessagingApplicationTest.java create mode 100644 integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/ReactiveMessagingCodestartIT.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testAMQPContent/src_main_resources_application.properties create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_main_java_ilove_quark_us_MyReactiveMessagingApplication.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_main_resources_application.properties create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_test_java_ilove_quark_us_MyReactiveMessagingApplicationTest.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testMQTTContent/src_main_resources_application.properties diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/base/README.tpl.qute.md b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/base/README.tpl.qute.md new file mode 100644 index 0000000000000..4b89133ba542e --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/base/README.tpl.qute.md @@ -0,0 +1,12 @@ +{#include readme-header /} + +{#each input.selected-extensions-ga} +{#switch it} +{#case 'io.quarkus:quarkus-smallrye-reactive-messaging-kafka'} +[Related Apache Kafka guide section...](https://quarkus.io/guides/kafka-reactive-getting-started) + +{#case 'io.quarkus:quarkus-smallrye-reactive-messaging-amqp'} +[Related Apache AMQP 1.0 guide section...](https://quarkus.io/guides/amqp) + +{/switch} +{/each} \ No newline at end of file diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/base/src/main/resources/application.tpl.qute.yml b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/base/src/main/resources/application.tpl.qute.yml new file mode 100644 index 0000000000000..65162fb33deb7 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/base/src/main/resources/application.tpl.qute.yml @@ -0,0 +1,66 @@ +{#each input.selected-extensions-ga} +{#switch it} +{#case 'io.quarkus:quarkus-smallrye-reactive-messaging-kafka'} +mp: + messaging: + outgoing: + source-out: + connector: smallrye-kafka + topic: word + uppercase-out: + connector: smallrye-kafka + topic: uppercase-word + incoming: + source-in: + connector: smallrye-kafka + topic: word + uppercase-in: + connector: smallrye-kafka + topic: uppercase-word + +{#case 'io.quarkus:quarkus-smallrye-reactive-messaging-mqtt'} +mp: + messaging: + outgoing: + source-out: + connector: smallrye-mqtt + host: localhost + port: '1883' + topic: word + uppercase-out: + connector: smallrye-mqtt + host: localhost + port: '1883' + topic: uppercase-word + incoming: + source-in: + connector: smallrye-mqtt + host: localhost + port: '1883' + topic: word + uppercase-in: + connector: smallrye-mqtt + host: localhost + port: '1883' + topic: uppercase-word + +{#case 'io.quarkus:quarkus-smallrye-reactive-messaging-amqp'} +mp: + messaging: + outgoing: + source-out: + address: word + connector: smallrye-amqp + uppercase-out: + connector: smallrye-amqp + address: uppercase-word + incoming: + source-in: + connector: smallrye-amqp + address: word + uppercase-in: + address: uppercase-word + connector: smallrye-amqp + +{/switch} +{/each} \ No newline at end of file diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/codestart.yml b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/codestart.yml new file mode 100644 index 0000000000000..1ad7664aa2fe9 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/codestart.yml @@ -0,0 +1,12 @@ +name: reactive-messaging-codestart +ref: reactive-messaging +tags: extension-codestart +type: code +metadata: + title: Reactive Messaging codestart + description: Use SmallRye Reactive Messaging +language: + base: + dependencies: + test-dependencies: + - io.smallrye.reactive:smallrye-reactive-messaging-in-memory diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/java/src/main/java/org/acme/MyReactiveMessagingApplication.java b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/java/src/main/java/org/acme/MyReactiveMessagingApplication.java new file mode 100644 index 0000000000000..3db201f7deca8 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/java/src/main/java/org/acme/MyReactiveMessagingApplication.java @@ -0,0 +1,35 @@ +package org.acme; + +import io.quarkus.runtime.StartupEvent; +import org.eclipse.microprofile.reactive.messaging.*; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; +import java.util.stream.Stream; + +@ApplicationScoped +public class MyReactiveMessagingApplication { + + @Inject + @Channel("source-out") + Emitter emitter; + + /** Sends message to the source channel, can be used from a JAX-RS resource or any bean of your application **/ + void onStart(@Observes StartupEvent ev) { + Stream.of("Hello", "with", "SmallRye", "reactive", "message").forEach(string -> emitter.send(string)); + } + + /** Consume the message from the source channel, uppercase it and send it to the uppercase channel **/ + @Incoming("source-in") + @Outgoing("uppercase-out") + public Message toUpperCase(Message message) { + return message.withPayload(message.getPayload().toUpperCase()); + } + + /** Consume the uppercase channel and print the message **/ + @Incoming("uppercase-in") + public void sink(String word) { + System.out.println(">> " + word); + } +} diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/java/src/test/java/org/acme/MyReactiveMessagingApplicationTest.java b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/java/src/test/java/org/acme/MyReactiveMessagingApplicationTest.java new file mode 100644 index 0000000000000..e712418a249d0 --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/reactive-messaging-codestart/java/src/test/java/org/acme/MyReactiveMessagingApplicationTest.java @@ -0,0 +1,59 @@ +package org.acme; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import io.quarkus.test.junit.QuarkusTest; +import io.smallrye.reactive.messaging.connectors.InMemoryConnector; +import io.smallrye.reactive.messaging.connectors.InMemorySink; +import io.smallrye.reactive.messaging.connectors.InMemorySource; +import org.junit.jupiter.api.Test; + +import javax.enterprise.inject.Any; +import javax.inject.Inject; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@QuarkusTest +@QuarkusTestResource(MyReactiveMessagingApplicationTest.InMemoryChannelTestResource.class) +class MyReactiveMessagingApplicationTest { + + @Inject + @Any + InMemoryConnector connector; + + @Test + void test() { + InMemorySource source = connector.source("source-in"); + InMemorySink uppercase = connector.sink("uppercase-out"); + + source.send("Hello"); + source.send("In-memory"); + source.send("Connectors"); + + assertEquals(3, uppercase.received().size()); + assertTrue(uppercase.received().stream().anyMatch(message -> message.getPayload().equals("HELLO"))); + assertTrue(uppercase.received().stream().anyMatch(message -> message.getPayload().equals("IN-MEMORY"))); + assertTrue(uppercase.received().stream().anyMatch(message -> message.getPayload().equals("CONNECTORS"))); + + } + + public static class InMemoryChannelTestResource implements QuarkusTestResourceLifecycleManager { + + @Override + public Map start() { + Map env = new HashMap<>(); + env.putAll(InMemoryConnector.switchIncomingChannelsToInMemory("source-in")); + env.putAll(InMemoryConnector.switchOutgoingChannelsToInMemory("uppercase-out")); + return env; + } + + @Override + public void stop() { + InMemoryConnector.clear(); + } + } +} \ No newline at end of file diff --git a/extensions/reactive-messaging-http/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/reactive-messaging-http/runtime/src/main/resources/META-INF/quarkus-extension.yaml index e1b4386991ef7..a02988488bad1 100644 --- a/extensions/reactive-messaging-http/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/reactive-messaging-http/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -10,4 +10,9 @@ metadata: - "web" - "reactive" - "messaging" - status: "experimental" \ No newline at end of file + status: "experimental" + codestart: + name: "reactive-messaging" + languages: + - "java" + artifact: "io.quarkus:quarkus-project-core-extension-codestarts" \ No newline at end of file diff --git a/extensions/smallrye-reactive-messaging-amqp/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/smallrye-reactive-messaging-amqp/runtime/src/main/resources/META-INF/quarkus-extension.yaml index 977c0d3ae2981..dd55665d3d076 100644 --- a/extensions/smallrye-reactive-messaging-amqp/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/smallrye-reactive-messaging-amqp/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -14,3 +14,8 @@ metadata: - "mp.messaging." - "quarkus.reactive-messaging." - "quarkus.amqp." + codestart: + name: "reactive-messaging" + languages: + - "java" + artifact: "io.quarkus:quarkus-project-core-extension-codestarts" diff --git a/extensions/smallrye-reactive-messaging-kafka/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/smallrye-reactive-messaging-kafka/runtime/src/main/resources/META-INF/quarkus-extension.yaml index 0d1fc63af6163..16c2f38660922 100644 --- a/extensions/smallrye-reactive-messaging-kafka/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/smallrye-reactive-messaging-kafka/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -14,3 +14,8 @@ metadata: - "mp.messaging." - "quarkus.reactive-messaging." - "quarkus.kafka." + codestart: + name: "reactive-messaging" + languages: + - "java" + artifact: "io.quarkus:quarkus-project-core-extension-codestarts" diff --git a/extensions/smallrye-reactive-messaging-mqtt/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/smallrye-reactive-messaging-mqtt/runtime/src/main/resources/META-INF/quarkus-extension.yaml index dd61940bd732c..b9b60e7c19a99 100644 --- a/extensions/smallrye-reactive-messaging-mqtt/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/smallrye-reactive-messaging-mqtt/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -11,3 +11,8 @@ metadata: config: - "mp.messaging." - "quarkus.reactive-messaging." + codestart: + name: "reactive-messaging" + languages: + - "java" + artifact: "io.quarkus:quarkus-project-core-extension-codestarts" diff --git a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java index 4b72d772ab051..f741564f59aa5 100644 --- a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java +++ b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.Instant; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -280,7 +281,8 @@ private AbstractPathAssert checkGeneratedSource(String sourceDir, Language la private String getTestId() { String tool = buildTool != null ? buildTool.getKey() + "-" : ""; - return tool + String.join("-", codestarts); + String suffix = codestarts.isEmpty() ? String.valueOf(Instant.now().toEpochMilli()) : String.join("-", codestarts); + return tool + suffix; } private void generateRealDataProjectIfNeeded(Path path, Language language) throws IOException { diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java index 7c429cf1a55ef..61b967ffe9ef7 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java @@ -37,7 +37,7 @@ class QuarkusCodestartBuildIT extends PlatformAwareTestBase { private static final Path testDirPath = Paths.get("target/quarkus-codestart-build-test"); private static final Set EXCLUDED = Sets.newHashSet("spring-web-codestart", "picocli-codestart", - "hibernate-orm-codestart"); + "hibernate-orm-codestart", "reactive-messaging"); @BeforeAll static void setUp() throws IOException { diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/ReactiveMessagingCodestartIT.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/ReactiveMessagingCodestartIT.java new file mode 100644 index 0000000000000..3d276c7766796 --- /dev/null +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/ReactiveMessagingCodestartIT.java @@ -0,0 +1,54 @@ +package io.quarkus.devtools.codestarts.quarkus; + +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; +import io.quarkus.maven.ArtifactKey; + +public class ReactiveMessagingCodestartIT { + + @RegisterExtension + public static QuarkusCodestartTest kafkaCodestartTest = QuarkusCodestartTest.builder() + .extension(ArtifactKey.fromString("io.quarkus:quarkus-smallrye-reactive-messaging-kafka")) + .languages(JAVA) + .build(); + + @RegisterExtension + public static QuarkusCodestartTest amqpCodestartTest = QuarkusCodestartTest.builder() + .extension(ArtifactKey.fromString("io.quarkus:quarkus-smallrye-reactive-messaging-amqp")) + .languages(JAVA) + .build(); + + @RegisterExtension + public static QuarkusCodestartTest mqttCodestartTest = QuarkusCodestartTest.builder() + .extension(ArtifactKey.fromString("io.quarkus:quarkus-smallrye-reactive-messaging-mqtt")) + .languages(JAVA) + .build(); + + @Test + void testKafkaContent() throws Throwable { + kafkaCodestartTest.checkGeneratedSource("org.acme.MyReactiveMessagingApplication"); + kafkaCodestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/application.properties"); + kafkaCodestartTest.checkGeneratedTestSource("org.acme.MyReactiveMessagingApplicationTest"); + } + + @Test + void testMQTTContent() throws Throwable { + mqttCodestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/application.properties"); + } + + @Test + void testAMQPContent() throws Throwable { + amqpCodestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/application.properties"); + } + + @Test + void buildAll() throws Throwable { + kafkaCodestartTest.buildAllProjects(); + mqttCodestartTest.buildAllProjects(); + amqpCodestartTest.buildAllProjects(); + } +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testAMQPContent/src_main_resources_application.properties b/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testAMQPContent/src_main_resources_application.properties new file mode 100644 index 0000000000000..c5fbcd65a5680 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testAMQPContent/src_main_resources_application.properties @@ -0,0 +1,8 @@ +mp.messaging.outgoing.uppercase-out.connector=smallrye-amqp +mp.messaging.outgoing.uppercase-out.address=uppercase-word +mp.messaging.incoming.source-in.connector=smallrye-amqp +mp.messaging.incoming.uppercase-in.address=uppercase-word +mp.messaging.outgoing.source-out.address=word +mp.messaging.incoming.source-in.address=word +mp.messaging.outgoing.source-out.connector=smallrye-amqp +mp.messaging.incoming.uppercase-in.connector=smallrye-amqp diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_main_java_ilove_quark_us_MyReactiveMessagingApplication.java b/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_main_java_ilove_quark_us_MyReactiveMessagingApplication.java new file mode 100644 index 0000000000000..11e683e6f393f --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_main_java_ilove_quark_us_MyReactiveMessagingApplication.java @@ -0,0 +1,35 @@ +package ilove.quark.us; + +import io.quarkus.runtime.StartupEvent; +import org.eclipse.microprofile.reactive.messaging.*; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; +import java.util.stream.Stream; + +@ApplicationScoped +public class MyReactiveMessagingApplication { + + @Inject + @Channel("source-out") + Emitter emitter; + + /** Sends message to the source channel, can be used from a JAX-RS resource or any bean of your application **/ + void onStart(@Observes StartupEvent ev) { + Stream.of("Hello", "with", "SmallRye", "reactive", "message").forEach(string -> emitter.send(string)); + } + + /** Consume the message from the source channel, uppercase it and send it to the uppercase channel **/ + @Incoming("source-in") + @Outgoing("uppercase-out") + public Message toUpperCase(Message message) { + return message.withPayload(message.getPayload().toUpperCase()); + } + + /** Consume the uppercase channel and print the message **/ + @Incoming("uppercase-in") + public void sink(String word) { + System.out.println(">> " + word); + } +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_main_resources_application.properties b/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_main_resources_application.properties new file mode 100644 index 0000000000000..0b6dfe2325a36 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_main_resources_application.properties @@ -0,0 +1,8 @@ +mp.messaging.outgoing.uppercase-out.connector=smallrye-kafka +mp.messaging.incoming.source-in.connector=smallrye-kafka +mp.messaging.outgoing.source-out.topic=word +mp.messaging.incoming.source-in.topic=word +mp.messaging.incoming.uppercase-in.topic=uppercase-word +mp.messaging.outgoing.source-out.connector=smallrye-kafka +mp.messaging.outgoing.uppercase-out.topic=uppercase-word +mp.messaging.incoming.uppercase-in.connector=smallrye-kafka diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_test_java_ilove_quark_us_MyReactiveMessagingApplicationTest.java b/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_test_java_ilove_quark_us_MyReactiveMessagingApplicationTest.java new file mode 100644 index 0000000000000..aa937365cdb11 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testKafkaContent/src_test_java_ilove_quark_us_MyReactiveMessagingApplicationTest.java @@ -0,0 +1,59 @@ +package ilove.quark.us; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; +import io.quarkus.test.junit.QuarkusTest; +import io.smallrye.reactive.messaging.connectors.InMemoryConnector; +import io.smallrye.reactive.messaging.connectors.InMemorySink; +import io.smallrye.reactive.messaging.connectors.InMemorySource; +import org.junit.jupiter.api.Test; + +import javax.enterprise.inject.Any; +import javax.inject.Inject; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@QuarkusTest +@QuarkusTestResource(MyReactiveMessagingApplicationTest.InMemoryChannelTestResource.class) +class MyReactiveMessagingApplicationTest { + + @Inject + @Any + InMemoryConnector connector; + + @Test + void test() { + InMemorySource source = connector.source("source-in"); + InMemorySink uppercase = connector.sink("uppercase-out"); + + source.send("Hello"); + source.send("In-memory"); + source.send("Connectors"); + + assertEquals(3, uppercase.received().size()); + assertTrue(uppercase.received().stream().anyMatch(message -> message.getPayload().equals("HELLO"))); + assertTrue(uppercase.received().stream().anyMatch(message -> message.getPayload().equals("IN-MEMORY"))); + assertTrue(uppercase.received().stream().anyMatch(message -> message.getPayload().equals("CONNECTORS"))); + + } + + public static class InMemoryChannelTestResource implements QuarkusTestResourceLifecycleManager { + + @Override + public Map start() { + Map env = new HashMap<>(); + env.putAll(InMemoryConnector.switchIncomingChannelsToInMemory("source-in")); + env.putAll(InMemoryConnector.switchOutgoingChannelsToInMemory("uppercase-out")); + return env; + } + + @Override + public void stop() { + InMemoryConnector.clear(); + } + } +} \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testMQTTContent/src_main_resources_application.properties b/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testMQTTContent/src_main_resources_application.properties new file mode 100644 index 0000000000000..5fb0fc20f3ffd --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/ReactiveMessagingCodestartIT/testMQTTContent/src_main_resources_application.properties @@ -0,0 +1,16 @@ +mp.messaging.outgoing.source-out.host=localhost +mp.messaging.outgoing.uppercase-out.connector=smallrye-mqtt +mp.messaging.outgoing.source-out.topic=word +mp.messaging.incoming.uppercase-in.host=localhost +mp.messaging.incoming.source-in.topic=word +mp.messaging.incoming.uppercase-in.topic=uppercase-word +mp.messaging.outgoing.uppercase-out.port=1883 +mp.messaging.outgoing.uppercase-out.topic=uppercase-word +mp.messaging.incoming.source-in.port=1883 +mp.messaging.incoming.uppercase-in.connector=smallrye-mqtt +mp.messaging.incoming.source-in.connector=smallrye-mqtt +mp.messaging.incoming.source-in.host=localhost +mp.messaging.outgoing.uppercase-out.host=localhost +mp.messaging.incoming.uppercase-in.port=1883 +mp.messaging.outgoing.source-out.port=1883 +mp.messaging.outgoing.source-out.connector=smallrye-mqtt From 4bae693ce948e531ad2bbf08d15c13caf717b89b Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Thu, 25 Nov 2021 17:04:57 +0100 Subject: [PATCH 2/3] Improve testId in QuarkusCodestartTest and fix QuarkusCodestartBuildIT --- .../testing/codestarts/QuarkusCodestartTest.java | 14 ++++++++++---- .../quarkus/QuarkusCodestartBuildIT.java | 9 ++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java index f741564f59aa5..e13049c20ada2 100644 --- a/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java +++ b/independent-projects/tools/devtools-testing/src/main/java/io/quarkus/devtools/testing/codestarts/QuarkusCodestartTest.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; -import java.time.Instant; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -30,7 +29,11 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.assertj.core.api.AbstractPathAssert; import org.assertj.core.api.Assertions; import org.assertj.core.api.ListAssert; @@ -280,9 +283,12 @@ private AbstractPathAssert checkGeneratedSource(String sourceDir, Language la } private String getTestId() { - String tool = buildTool != null ? buildTool.getKey() + "-" : ""; - String suffix = codestarts.isEmpty() ? String.valueOf(Instant.now().toEpochMilli()) : String.join("-", codestarts); - return tool + suffix; + final String id = Stream.of( + buildTool != null ? Stream.of(buildTool.getKey()) : Stream. empty(), + this.extensions.stream().map(ArtifactCoords::getArtifactId), + this.codestarts.stream(), + Stream.of(UUID.randomUUID().toString())).flatMap(Function.identity()).collect(Collectors.joining("-")); + return id; } private void generateRealDataProjectIfNeeded(Path path, Language language) throws IOException { diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java index 61b967ffe9ef7..415070a21d879 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartBuildIT.java @@ -36,8 +36,11 @@ class QuarkusCodestartBuildIT extends PlatformAwareTestBase { private static final Path testDirPath = Paths.get("target/quarkus-codestart-build-test"); - private static final Set EXCLUDED = Sets.newHashSet("spring-web-codestart", "picocli-codestart", - "hibernate-orm-codestart", "reactive-messaging"); + private static final Set EXCLUDED = Sets.newHashSet( + "spring-web-codestart", + "picocli-codestart", + "hibernate-orm-codestart", + "reactive-messaging-codestart"); @BeforeAll static void setUp() throws IOException { @@ -135,7 +138,7 @@ private String genName(String buildtool, String language, List codestart if (codestarts.isEmpty()) { name += "-default"; } else if (codestarts.size() > 2) { - name += "-" + UUID.randomUUID().toString(); + name += "-" + UUID.randomUUID(); } else { name += "-" + String.join("-", codestarts); } From eca87b6697db4b2a8713e5cb3c45b8e13a713baf Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Wed, 1 Dec 2021 09:33:10 +0100 Subject: [PATCH 3/3] Disable build test on Windows because no docker on CI --- .../quarkus/ReactiveMessagingCodestartIT.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/ReactiveMessagingCodestartIT.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/ReactiveMessagingCodestartIT.java index 3d276c7766796..e6c6ac7ba9181 100644 --- a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/ReactiveMessagingCodestartIT.java +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/ReactiveMessagingCodestartIT.java @@ -3,6 +3,8 @@ import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; @@ -46,9 +48,20 @@ void testAMQPContent() throws Throwable { } @Test - void buildAll() throws Throwable { + @DisabledOnOs(OS.WINDOWS) + void buildKafka() throws Throwable { kafkaCodestartTest.buildAllProjects(); + } + + @Test + @DisabledOnOs(OS.WINDOWS) + void buildMQTT() throws Throwable { mqttCodestartTest.buildAllProjects(); + } + + @Test + @DisabledOnOs(OS.WINDOWS) + void buildAMQP() throws Throwable { amqpCodestartTest.buildAllProjects(); } }