diff --git a/.github/workflows/quickstart_microprofile-fault-tolerance_ci.yml b/.github/workflows/quickstart_microprofile-fault-tolerance_ci.yml new file mode 100644 index 0000000000..6c0b9abc24 --- /dev/null +++ b/.github/workflows/quickstart_microprofile-fault-tolerance_ci.yml @@ -0,0 +1,14 @@ +name: WildFly microprofile-fault-tolerance Quickstart CI + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths: + - 'microprofile-fault-tolerance/**' + - '.github/workflows/quickstart_ci.yml' +jobs: + call-quickstart_ci: + uses: ./.github/workflows/quickstart_ci.yml + with: + QUICKSTART_PATH: microprofile-fault-tolerance + MICROPROFILE: true diff --git a/microprofile-fault-tolerance/README.adoc b/microprofile-fault-tolerance/README.adoc index ce98d8b301..8e149e0030 100644 --- a/microprofile-fault-tolerance/README.adoc +++ b/microprofile-fault-tolerance/README.adoc @@ -622,28 +622,18 @@ See details in the section < - - 30.0.0.Final - 30.0.0.Final - 30.0.0.Final - 10.0.0.Final - 1.0.1 - registry.redhat.io/ubi8/openjdk-11:latest + + 30.0.0.Final + + ${version.server} + ${version.server} + 5.0.0.Final + 4.2.0.Final + 10.0.0.Final + + 4.3.1 @@ -122,7 +125,7 @@ org.wildfly.bom wildfly-ee-with-tools - ${version.server.bom} + ${version.bom.ee} pom import @@ -130,7 +133,7 @@ org.wildfly.bom wildfly-microprofile - ${version.microprofile.bom} + ${version.bom.microprofile} pom import @@ -189,30 +192,37 @@ io.rest-assured rest-assured - 4.3.1 + ${version.io.rest-assured} + test + + + org.jboss.resteasy + resteasy-jackson2-provider test - microprofile-fault-tolerance - - - - org.wildfly.plugins - wildfly-maven-plugin - - - + ${project.artifactId} + + org.wildfly.plugins + wildfly-maven-plugin + ${version.plugin.wildfly} + + + org.wildfly.plugins + wildfly-jar-maven-plugin + ${version.plugin.wildfly-jar} + org.asciidoctor asciidoctor-maven-plugin - ${version.server.bom} - ${version.microprofile.bom} + ${version.bom.ee} + ${version.bom.microprofile} @@ -227,12 +237,13 @@ org.wildfly.plugins wildfly-jar-maven-plugin - ${version.wildfly-jar.maven.plugin} - wildfly@maven(org.jboss.universe:community-universe)#${version.server.bootable-jar} + + wildfly@maven(org.jboss.universe:community-universe)#${version.server} + jaxrs-server - microprofile-platform + microprofile-fault-tolerance true @@ -249,24 +260,29 @@ + - bootable-jar-openshift + openshift org.wildfly.plugins - wildfly-jar-maven-plugin - ${version.wildfly-jar.maven.plugin} + wildfly-maven-plugin - wildfly@maven(org.jboss.universe:community-universe)#${version.server.bootable-jar} + + + org.wildfly:wildfly-galleon-pack:${version.server} + + + org.wildfly.cloud:wildfly-cloud-galleon-pack:${version.pack.cloud} + + + - jaxrs-server - microprofile-platform + cloud-server + microprofile-fault-tolerance - - true - - + ROOT.war @@ -276,83 +292,26 @@ - - org.eclipse.jkube - openshift-maven-plugin - ${version.jkube.maven.plugin} - - - - resource - build - - - - - - - - NodePort - - - - - - - - - - - arq-managed - - - org.wildfly.arquillian - wildfly-arquillian-container-managed - test - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - ${version.failsafe.plugin} - - - - integration-test - verify - - - - + - - arq-remote - - - org.wildfly.arquillian - wildfly-arquillian-container-remote - test - - + integration-testing org.apache.maven.plugins maven-failsafe-plugin - ${version.failsafe.plugin} + + + **/CoffeeResourceIT + + integration-test - verify @@ -360,6 +319,7 @@ + diff --git a/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/Coffee.java b/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/Coffee.java index 9435fb36aa..4506bcc329 100644 --- a/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/Coffee.java +++ b/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/Coffee.java @@ -17,8 +17,9 @@ package org.wildfly.quickstarts.microprofile.faulttolerance; /** + * A simple entity class. + * * @author Radoslav Husar - * A sample entity class. */ public class Coffee { diff --git a/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeRepositoryService.java b/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeRepositoryService.java index 9980cdb4f6..50ac0fc0e1 100644 --- a/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeRepositoryService.java +++ b/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeRepositoryService.java @@ -36,11 +36,11 @@ public class CoffeeRepositoryService { private static final Logger LOGGER = Logger.getLogger(CoffeeRepositoryService.class); - private Map coffeeList = new HashMap<>(); + private final Map coffeeList = new HashMap<>(); - private Map availability = new HashMap<>(); + private final Map availability = new HashMap<>(); - private AtomicLong counter = new AtomicLong(0); + private final AtomicLong counter = new AtomicLong(0); public CoffeeRepositoryService() { diff --git a/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeResource.java b/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeResource.java index 3c7dd62c6c..ba49cbd63c 100644 --- a/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeResource.java +++ b/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeResource.java @@ -24,6 +24,7 @@ import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; @@ -33,7 +34,6 @@ import org.eclipse.microprofile.faulttolerance.Retry; import org.eclipse.microprofile.faulttolerance.Timeout; import org.jboss.logging.Logger; -import jakarta.ws.rs.PathParam; /** * A JAX-RS resource that provides information about kinds of coffees we have on store and numbers of packages available. @@ -51,7 +51,7 @@ public class CoffeeResource { @Inject CoffeeRepositoryService coffeeRepository; - private AtomicLong counter = new AtomicLong(0); + private final AtomicLong counter = new AtomicLong(0); private Float failRatio = 0.5f; @@ -171,15 +171,24 @@ private void randomDelay() throws InterruptedException { Thread.sleep(new Random().nextInt(500)); } - void setFailRatio(Float failRatio) { + // The following methods are only used for automated integration testing + + @GET + @Path("/setFailRatio/{failRatio}") + public void setFailRatio(@PathParam("failRatio") Float failRatio) { this.failRatio = failRatio; } - void resetCounter() { - this.counter.set(0); + @GET + @Path("/getCounter") + public Long getCounter() { + return counter.get(); } - Long getCounter() { - return counter.get(); + @GET + @Path("/resetCounter") + public void resetCounter() { + this.counter.set(0); } + } diff --git a/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/RootResource.java b/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/RootResource.java index b2251c49c7..df9230059d 100644 --- a/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/RootResource.java +++ b/microprofile-fault-tolerance/src/main/java/org/wildfly/quickstarts/microprofile/faulttolerance/RootResource.java @@ -1,3 +1,19 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2020, 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. + */ package org.wildfly.quickstarts.microprofile.faulttolerance; import jakarta.ws.rs.GET; diff --git a/microprofile-fault-tolerance/src/main/jkube/route.yml b/microprofile-fault-tolerance/src/main/jkube/route.yml deleted file mode 100644 index 51643e586c..0000000000 --- a/microprofile-fault-tolerance/src/main/jkube/route.yml +++ /dev/null @@ -1,7 +0,0 @@ -spec: - tls: - insecureEdgeTerminationPolicy: Redirect - termination: edge - to: - kind: Service - name: microprofile-fault-tolerance diff --git a/microprofile-fault-tolerance/src/test/java/org/wildfly/quickstarts/microprofile/faulttolerance/MicroProfileFaultToleranceIT.java b/microprofile-fault-tolerance/src/test/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeResourceIT.java similarity index 61% rename from microprofile-fault-tolerance/src/test/java/org/wildfly/quickstarts/microprofile/faulttolerance/MicroProfileFaultToleranceIT.java rename to microprofile-fault-tolerance/src/test/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeResourceIT.java index 313d6da6fb..a8dbe7b3de 100644 --- a/microprofile-fault-tolerance/src/test/java/org/wildfly/quickstarts/microprofile/faulttolerance/MicroProfileFaultToleranceIT.java +++ b/microprofile-fault-tolerance/src/test/java/org/wildfly/quickstarts/microprofile/faulttolerance/CoffeeResourceIT.java @@ -16,42 +16,35 @@ */ package org.wildfly.quickstarts.microprofile.faulttolerance; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import jakarta.inject.Inject; +import java.util.List; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; import jakarta.ws.rs.core.GenericType; +import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; -import java.net.URL; -import java.util.List; -@RunWith(Arquillian.class) -public class MicroProfileFaultToleranceIT { - - private static final String APP_NAME = "microprofile-fault-tolerance"; - - @ArquillianResource - private URL deploymentUrl; +import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider; +import org.jboss.resteasy.spi.ResteasyProviderFactory; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; - @Inject - private CoffeeResource coffeeResource; +/** + * Simple integration test for Coffee resource that is guarded by MicroProfile Fault Tolerance annotations. + * + * @author Radoslav Husar + * @author Eduardo Martins + */ +public class CoffeeResourceIT { private Client client; - @Deployment - public static WebArchive createDeployment() { - return ShrinkWrap.create(WebArchive.class, APP_NAME + ".war") - .addPackage(CoffeeApplication.class.getPackage()); + static { + ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(instance); + instance.registerProvider(ResteasyJackson2Provider.class); } @Before @@ -66,8 +59,8 @@ public void after() { @Test public void testCoffeeList() { - coffeeResource.setFailRatio(0f); - coffeeResource.resetCounter(); + this.setFailRatio(0f); + this.resetCounter(); try (Response response = this.getResponse("/coffee")) { Assert.assertEquals(200, response.getStatus()); @@ -80,18 +73,19 @@ public void testCoffeeList() { @Test public void testCoffeeListFailure() { - coffeeResource.setFailRatio(1f); - coffeeResource.resetCounter(); + this.setFailRatio(1f); + this.resetCounter(); try (Response response = this.getResponse("/coffee")) { Assert.assertEquals(500, response.getStatus()); - Assert.assertEquals(5, coffeeResource.getCounter().longValue()); } + + Assert.assertEquals(5, this.getCounter()); } @Test public void testCoffeeDetail() { - coffeeResource.setFailRatio(0f); + this.setFailRatio(0f); try (Response response = this.getResponse("/coffee/1")) { Assert.assertEquals(200, response.getStatus()); @@ -104,17 +98,36 @@ public void testCoffeeDetail() { @Test public void testCoffeeDetailFailure() { - coffeeResource.setFailRatio(1f); + this.setFailRatio(1f); try (Response response = this.getResponse("/coffee/1")) { Assert.assertEquals(500, response.getStatus()); } } + private long getCounter() { + try (Response response = this.getResponse("/coffee/getCounter")) { + Assert.assertEquals(200, response.getStatus()); + return response.readEntity(Long.class); + } + } + + private void setFailRatio(float failRatio) { + try (Response response = this.getResponse("/coffee/setFailRatio/" + failRatio)) { + Assert.assertEquals(204, response.getStatus()); + } + } + + private void resetCounter() { + try (Response response = this.getResponse("/coffee/resetCounter")) { + Assert.assertEquals(204, response.getStatus()); + } + } + private Response getResponse(String path) { - return client.target(deploymentUrl.toString()) + return client.target(TestUtils.getServerHost()) .path(path) - .request() + .request(MediaType.APPLICATION_JSON_TYPE) .get(); } } diff --git a/microprofile-fault-tolerance/src/test/java/org/wildfly/quickstarts/microprofile/faulttolerance/TestUtils.java b/microprofile-fault-tolerance/src/test/java/org/wildfly/quickstarts/microprofile/faulttolerance/TestUtils.java new file mode 100644 index 0000000000..a6c65f0515 --- /dev/null +++ b/microprofile-fault-tolerance/src/test/java/org/wildfly/quickstarts/microprofile/faulttolerance/TestUtils.java @@ -0,0 +1,33 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2023, 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. + */ +package org.wildfly.quickstarts.microprofile.faulttolerance; + +public class TestUtils { + + static final String DEFAULT_SERVER_HOST = "http://localhost:8080/microprofile-fault-tolerance"; + + static String getServerHost() { + String serverHost = System.getenv("SERVER_HOST"); + if (serverHost == null) { + serverHost = System.getProperty("server.host"); + } + if (serverHost == null) { + serverHost = DEFAULT_SERVER_HOST; + } + return serverHost; + } +} diff --git a/microprofile-fault-tolerance/src/test/resources/arquillian.xml b/microprofile-fault-tolerance/src/test/resources/arquillian.xml deleted file mode 100644 index bd46e69a49..0000000000 --- a/microprofile-fault-tolerance/src/test/resources/arquillian.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - -