From e19254c01cb73cebbd7d2e77c36ef3c3d6ab31e2 Mon Sep 17 00:00:00 2001 From: Emmanuel Hugonnet Date: Mon, 6 Nov 2023 16:59:16 +0100 Subject: [PATCH] WFLY-18473: helloworld-jms Quickstart Common Enhancements CY2023Q3. * Using integration-testing as a way to execute the client * provisionned server is ready to handle the client Issue: https://issues.redhat.com/browse/WFLY-18473 Signed-off-by: Emmanuel Hugonnet --- .../quickstart_helloworld-jms_ci.yml | 15 ++ helloworld-jms/README.adoc | 57 +---- helloworld-jms/pom.xml | 199 +++++++++++++----- .../helloworld-jms-logging.properties | 39 ++++ .../{ => src/main/scripts}/configure-jms.cli | 0 .../jms/HelloWorldJMSClientIT.java} | 42 ++-- .../helloworld-jms-logging.properties | 39 ++++ 7 files changed, 271 insertions(+), 120 deletions(-) create mode 100644 .github/workflows/quickstart_helloworld-jms_ci.yml create mode 100644 helloworld-jms/src/main/resources/helloworld-jms-logging.properties rename helloworld-jms/{ => src/main/scripts}/configure-jms.cli (100%) rename helloworld-jms/src/{main/java/org/jboss/as/quickstarts/jms/HelloWorldJMSClient.java => test/java/org/jboss/as/quickstarts/jms/HelloWorldJMSClientIT.java} (72%) create mode 100644 helloworld-jms/src/test/resources/helloworld-jms-logging.properties diff --git a/.github/workflows/quickstart_helloworld-jms_ci.yml b/.github/workflows/quickstart_helloworld-jms_ci.yml new file mode 100644 index 0000000000..f19506d529 --- /dev/null +++ b/.github/workflows/quickstart_helloworld-jms_ci.yml @@ -0,0 +1,15 @@ +name: WildFly helloworld-jms Quickstart CI + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths: + - 'helloworld-jms/**' + - '.github/workflows/quickstart_ci.yml' +jobs: + call-quickstart_ci: + uses: ./.github/workflows/quickstart_ci.yml + with: + QUICKSTART_PATH: helloworld-jms + TEST_PROVISIONED_SERVER: true + TEST_OPENSHIFT: false \ No newline at end of file diff --git a/helloworld-jms/README.adoc b/helloworld-jms/README.adoc index 060b46ed71..f39f1dfb5d 100644 --- a/helloworld-jms/README.adoc +++ b/helloworld-jms/README.adoc @@ -44,7 +44,7 @@ You configure the JMS `test` queue by running JBoss CLI commands. For your conve * xref:back_up_standalone_server_configuration[Back up the {productName} standalone server configuration] as described above. * xref:start_the_eap_standalone_server[Start the {productName} server with the standalone full profile] as described above. -. Review the `configure-jms.cli` file in the root of this quickstart directory. This script adds the `test` queue to the `messaging` subsystem in the server configuration file. +. Review the `configure-jms.cli` file in the `src/main/scripts/` folder of this quickstart directory. This script adds the `test` queue to the `messaging` subsystem in the server configuration file. . Open a new terminal, navigate to the root directory of this quickstart, and run the following command, replacing __{jbossHomeName}__ with the path to your server: + [source,subs="+quotes,attributes+",options="nowrap"] @@ -75,26 +75,11 @@ The following `testQueue` jms-queue was configured in the default server configu ---- -== Build and Execute the Quickstart +// Server Distribution Testing +include::../shared-doc/run-integration-tests-with-server-distribution.adoc[leveloffset=+1] -. xref:start_the_eap_standalone_server[Start the {productName} server with the standalone full profile] as described above. -. Open a terminal and navigate to the root of the helloworld-jms quickstart directory: -+ -[source,options="nowrap"] ----- -$ cd PATH_TO_QUICKSTARTS/helloworld-jms ----- - -. Type the following command to compile and execute the quickstart: -+ -[source,options="nowrap"] ----- -$ mvn clean compile exec:java ----- - - -== Investigate the Console Output +=== Investigate the Console Output If the Maven command is successful, with the default configuration you will see output similar to this: @@ -117,9 +102,9 @@ timestamp org.jboss.as.quickstarts.jms.HelloWorldJMSClient main INFO: Received message with content Hello, World! ---- -== Optional Properties +=== Optional Properties -The example provides for a certain amount of customization for the `mvn:exec` plug-in using the system properties. +The example provides for a certain amount of customization for the integration test using the system properties. [cols="20%,30%,50%",options="headers"] |=== @@ -167,32 +152,4 @@ This script removes the `test` queue from the `messaging` subsystem in the serve The batch executed successfully ---- -// Restore the {productName} Standalone Server Configuration Manually -include::../shared-doc/restore-standalone-server-configuration-manual.adoc[leveloffset=+2] -// Run the Quickstart in Red Hat CodeReady Studio or Eclipse -include::../shared-doc/run-the-quickstart-in-jboss-developer-studio.adoc[leveloffset=+1] - -// Additional Red Hat CodeReady Studio instructions -This quickstart consists of multiple projects, so it deploys and runs differently in {JBDSProductName} than the other quickstarts. - -. Make sure you xref:add_the_application_user[add the authorized application user] as described above. -. Configure and start the {productName} server in {JBDSProductName}: -** Define a server runtime environment that uses the `standalone-full.xml` configuration file. -** Start the server defined in the previous step. -. Outside of {JBDSProductName}, configure the JMS `test` queue by running the JBoss CLI commands as described above under xref:configure_the_server[Configure the Server]. -. In {JBDSProductName}, right-click on the *{artifactId}* project and choose *Run As* -> *Java Application*. In the *Select Java Application* window, choose *HellowWorldJMSClient - org.jboss.as.quickstarts.jms* and click *OK*. The client output displays in the *Console* window. -The output messages appear in the *Console* window. -. Make sure you xref:restore_the_server_configuration[restore the {productName} server configuration] when you have completed testing this quickstart. - -// Debug the Application -include::../shared-doc/debug-the-application.adoc[leveloffset=+1] - -//************************************************* -// Product Release content only -//************************************************* -ifdef::ProductRelease[] - -// Quickstart not compatible with OpenShift -include::../shared-doc/openshift-incompatibility.adoc[leveloffset=+1] - -endif::[] \ No newline at end of file +include::../shared-doc/openshift-incompatibility.adoc[leveloffset=+1] \ No newline at end of file diff --git a/helloworld-jms/pom.xml b/helloworld-jms/pom.xml index c66305c2d8..fda209d1c5 100644 --- a/helloworld-jms/pom.xml +++ b/helloworld-jms/pom.xml @@ -43,8 +43,13 @@ - - 30.0.0.Final + + 30.0.0.Final + + ${version.server} + 5.0.0.Final + 4.2.0.Final + 5.10.0 @@ -108,10 +113,15 @@ org.wildfly.bom wildfly-ee-with-tools - ${version.server.bom} + ${version.bom.ee} pom import + + org.junit.jupiter + junit-jupiter-engine + ${version.junit-jupiter-engine} + @@ -128,55 +138,144 @@ wildfly-jms-client-bom pom + + org.junit.jupiter + junit-jupiter-engine + test + - - ${project.artifactId} - - - org.codehaus.mojo - exec-maven-plugin - - org.jboss.as.quickstarts.jms.HelloWorldJMSClient - - - - - java.logging.config.file - ./helloworld-jms-logging.properties - - - - - + + + + org.wildfly.plugins + wildfly-maven-plugin + ${version.plugin.wildfly} + + + + + + + provisioned-server + + + + org.wildfly.plugins + wildfly-maven-plugin + + + + org.wildfly:wildfly-galleon-pack:${version.server} + + + + cloud-server + ejb + embedded-activemq + + ROOT.war + + + + + + + false + + + + + + + package + + + + + + + + + openshift + + + + org.wildfly.plugins + wildfly-maven-plugin + + + + org.wildfly:wildfly-galleon-pack:${version.server} + + + org.wildfly.cloud:wildfly-cloud-galleon-pack:${version.pack.cloud} + + + + cloud-server + ejb + embedded-activemq + + ROOT.war + + + + + + + false + + + + + + + package + + + + + + + + + integration-testing + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.2.1 + + + **/HelloWorldJMSClientIT + + + helloworld-jms-logging.properties + + http-remoting://127.0.0.1:8080 + quickstartUser + quickstartPwd1! + jms/RemoteConnectionFactory + jms/queue/test + 5 + Hello, World! Test 5 + + + + + + integration-test + verify + + + + + + + + diff --git a/helloworld-jms/src/main/resources/helloworld-jms-logging.properties b/helloworld-jms/src/main/resources/helloworld-jms-logging.properties new file mode 100644 index 0000000000..7a7d8bae9f --- /dev/null +++ b/helloworld-jms/src/main/resources/helloworld-jms-logging.properties @@ -0,0 +1,39 @@ +# +# JBoss, Home of Professional Open Source +# Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual +# contributors by the @authors tag. See the copyright.txt in the +# distribution for a full listing of individual contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Specify the handlers to create in the root logger +# (all loggers are children of the root logger) +# The following creates two handlers +handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler + +# Set the default logging level for the root logger +.level = ALL + +# Set the default logging level for new ConsoleHandler instances +java.util.logging.ConsoleHandler.level = ALL + +# Set the default logging level for new FileHandler instances +java.util.logging.FileHandler.level = ALL +java.util.logging.FileHandler.pattern = helloworld-jms.log +java.util.logging.FileHandler.limit = 50000 +java.util.logging.FileHandler.count = 1 + +# Set the default formatter for new ConsoleHandler instances +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +# Set the default logging level for the logger named com.mycompany +org.jboss.as.quickstarts.jms = ALL diff --git a/helloworld-jms/configure-jms.cli b/helloworld-jms/src/main/scripts/configure-jms.cli similarity index 100% rename from helloworld-jms/configure-jms.cli rename to helloworld-jms/src/main/scripts/configure-jms.cli diff --git a/helloworld-jms/src/main/java/org/jboss/as/quickstarts/jms/HelloWorldJMSClient.java b/helloworld-jms/src/test/java/org/jboss/as/quickstarts/jms/HelloWorldJMSClientIT.java similarity index 72% rename from helloworld-jms/src/main/java/org/jboss/as/quickstarts/jms/HelloWorldJMSClient.java rename to helloworld-jms/src/test/java/org/jboss/as/quickstarts/jms/HelloWorldJMSClientIT.java index bdf89b0e01..5b9bf1b769 100644 --- a/helloworld-jms/src/main/java/org/jboss/as/quickstarts/jms/HelloWorldJMSClient.java +++ b/helloworld-jms/src/test/java/org/jboss/as/quickstarts/jms/HelloWorldJMSClientIT.java @@ -23,12 +23,15 @@ import jakarta.jms.Destination; import jakarta.jms.JMSConsumer; import jakarta.jms.JMSContext; +import java.util.logging.Level; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.junit.jupiter.api.Test; -public class HelloWorldJMSClient { - private static final Logger log = Logger.getLogger(HelloWorldJMSClient.class.getName()); +public class HelloWorldJMSClientIT { + + private static final Logger log = Logger.getLogger(HelloWorldJMSClientIT.class.getName()); // Set up all the default values private static final String DEFAULT_MESSAGE = "Hello, World!"; @@ -40,38 +43,36 @@ public class HelloWorldJMSClient { private static final String INITIAL_CONTEXT_FACTORY = "org.wildfly.naming.client.WildFlyInitialContextFactory"; private static final String PROVIDER_URL = "http-remoting://127.0.0.1:8080"; - public static void main(String[] args) { + @Test + public void testSendAndReceiveMessage() { + String userName = System.getProperty("username", DEFAULT_USERNAME); + String password = System.getProperty("password", DEFAULT_PASSWORD); + // Set up the namingContext for the JNDI lookup + final Properties env = new Properties(); + env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); + env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL)); + env.put(Context.SECURITY_PRINCIPAL, userName); + env.put(Context.SECURITY_CREDENTIALS, password); Context namingContext = null; - try { - String userName = System.getProperty("username", DEFAULT_USERNAME); - String password = System.getProperty("password", DEFAULT_PASSWORD); - - // Set up the namingContext for the JNDI lookup - final Properties env = new Properties(); - env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); - env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL)); - env.put(Context.SECURITY_PRINCIPAL, userName); - env.put(Context.SECURITY_CREDENTIALS, password); namingContext = new InitialContext(env); - // Perform the JNDI lookups String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY); - log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\""); + log.log(Level.INFO, "Attempting to acquire connection factory \"{0}\"", connectionFactoryString); ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString); - log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI"); + log.log(Level.INFO, "Found connection factory \"{0}\" in JNDI", connectionFactoryString); String destinationString = System.getProperty("destination", DEFAULT_DESTINATION); - log.info("Attempting to acquire destination \"" + destinationString + "\""); + log.log(Level.INFO, "Attempting to acquire destination \"{0}\"", destinationString); Destination destination = (Destination) namingContext.lookup(destinationString); - log.info("Found destination \"" + destinationString + "\" in JNDI"); + log.log(Level.INFO, "Found destination \"{0}\" in JNDI", destinationString); int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT)); String content = System.getProperty("message.content", DEFAULT_MESSAGE); try (JMSContext context = connectionFactory.createContext(userName, password)) { - log.info("Sending " + count + " messages with content: " + content); + log.log(Level.INFO, "Sending {0} messages with content: {1}", new Object[]{count, content}); // Send the specified number of messages for (int i = 0; i < count; i++) { context.createProducer().send(destination, content); @@ -82,10 +83,11 @@ public static void main(String[] args) { // Then receive the same number of messages that were sent for (int i = 0; i < count; i++) { String text = consumer.receiveBody(String.class, 5000); - log.info("Received message with content " + text); + log.log(Level.INFO, "Received message with content {0}", text); } } } catch (NamingException e) { + e.printStackTrace(); log.severe(e.getMessage()); } finally { if (namingContext != null) { diff --git a/helloworld-jms/src/test/resources/helloworld-jms-logging.properties b/helloworld-jms/src/test/resources/helloworld-jms-logging.properties new file mode 100644 index 0000000000..7a7d8bae9f --- /dev/null +++ b/helloworld-jms/src/test/resources/helloworld-jms-logging.properties @@ -0,0 +1,39 @@ +# +# JBoss, Home of Professional Open Source +# Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual +# contributors by the @authors tag. See the copyright.txt in the +# distribution for a full listing of individual contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Specify the handlers to create in the root logger +# (all loggers are children of the root logger) +# The following creates two handlers +handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler + +# Set the default logging level for the root logger +.level = ALL + +# Set the default logging level for new ConsoleHandler instances +java.util.logging.ConsoleHandler.level = ALL + +# Set the default logging level for new FileHandler instances +java.util.logging.FileHandler.level = ALL +java.util.logging.FileHandler.pattern = helloworld-jms.log +java.util.logging.FileHandler.limit = 50000 +java.util.logging.FileHandler.count = 1 + +# Set the default formatter for new ConsoleHandler instances +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +# Set the default logging level for the logger named com.mycompany +org.jboss.as.quickstarts.jms = ALL