forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
385 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-tck-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-tck-microprofile-lra</artifactId> | ||
<name>Quarkus - TCK - MicroProfile LRA</name> | ||
|
||
<properties> | ||
<microprofile-lra-tck.version>1.0</microprofile-lra-tck.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skip>false</skip> | ||
<systemPropertyVariables> | ||
<!-- Disable quarkus optimization --> | ||
<quarkus.arc.remove-unused-beans>false</quarkus.arc.remove-unused-beans> | ||
</systemPropertyVariables> | ||
<!-- This workaround allows us to run a single test using | ||
the "test" system property --> | ||
<!-- https://issues.apache.org/jira/browse/SUREFIRE-569 --> | ||
<dependenciesToScan> | ||
<dependency>org.eclipse.microprofile.lra:microprofile-lra-tck</dependency> | ||
</dependenciesToScan> | ||
<reuseForks>false</reuseForks> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arquillian</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-narayana-lra</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.microprofile.lra</groupId> | ||
<artifactId>microprofile-lra-tck</artifactId> | ||
<version>${microprofile-lra-tck.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.logging</groupId> | ||
<artifactId>commons-logging-jboss-logging</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>testcontainers</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
|
||
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-narayana-lra-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-jackson-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
16 changes: 16 additions & 0 deletions
16
tcks/microprofile-lra/src/main/java/io/quarkus/tck/lra/ArquillianExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkus.tck.lra; | ||
|
||
import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; | ||
import org.jboss.arquillian.core.spi.LoadableExtension; | ||
import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider; | ||
|
||
public class ArquillianExtension implements LoadableExtension { | ||
|
||
@Override | ||
public void register(ExtensionBuilder extensionBuilder) { | ||
extensionBuilder.service(ApplicationArchiveProcessor.class, DeploymentProcessor.class); | ||
extensionBuilder.service(ResourceProvider.class, BaseURLProvider.class); | ||
// works but restarts coordinator with every test class | ||
extensionBuilder.observer(LRACoordinatorManager.class); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tcks/microprofile-lra/src/main/java/io/quarkus/tck/lra/BaseURLProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkus.tck.lra; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URL; | ||
|
||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider; | ||
|
||
public class BaseURLProvider implements ResourceProvider { | ||
@Override | ||
public boolean canProvide(Class<?> aClass) { | ||
return aClass.isAssignableFrom(URL.class); | ||
} | ||
|
||
@Override | ||
public Object lookup(ArquillianResource arquillianResource, Annotation... annotations) { | ||
String testHost = ConfigProvider.getConfig().getOptionalValue("quarkus.http.host", String.class).orElse("localhost"); | ||
Integer testPort = ConfigProvider.getConfig().getOptionalValue("quarkus.http.test-port", Integer.class).orElse(8081); | ||
|
||
try { | ||
return URI.create(String.format("http://%s:%d", testHost, testPort)).toURL(); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tcks/microprofile-lra/src/main/java/io/quarkus/tck/lra/DeploymentProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.tck.lra; | ||
|
||
import org.eclipse.microprofile.lra.tck.TckTestBase; | ||
import org.eclipse.microprofile.lra.tck.participant.api.NonParticipatingTckResource; | ||
import org.eclipse.microprofile.lra.tck.participant.api.ResourceParent; | ||
import org.eclipse.microprofile.lra.tck.service.spi.LRARecoveryService; | ||
import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; | ||
import org.jboss.arquillian.test.spi.TestClass; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
|
||
public class DeploymentProcessor implements ApplicationArchiveProcessor { | ||
|
||
@Override | ||
public void process(Archive<?> archive, TestClass testClass) { | ||
if (archive instanceof WebArchive) { | ||
WebArchive war = (WebArchive) archive; | ||
|
||
war.addAsServiceProvider(LRARecoveryService.class, | ||
NarayanaLRARecovery.class); | ||
war.addPackages(false, | ||
"org.eclipse.microprofile.lra"); | ||
war.addClasses(TckTestBase.class, NarayanaLRARecovery.class, NonParticipatingTckResource.class, | ||
ResourceParent.class); | ||
} | ||
|
||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tcks/microprofile-lra/src/main/java/io/quarkus/tck/lra/LRACoordinatorManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.quarkus.tck.lra; | ||
|
||
import java.io.IOException; | ||
import java.net.ServerSocket; | ||
|
||
import org.jboss.arquillian.core.api.annotation.Observes; | ||
import org.jboss.logging.Logger; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
public class LRACoordinatorManager { | ||
|
||
private static final int DEFAULT_PRECEDENCE = -100; | ||
private static final Logger LOGGER = Logger.getLogger(LRACoordinatorManager.class); | ||
private final int coordinatorPort = getFreePort(50000, 60000); | ||
|
||
private GenericContainer coordinatorContainer; | ||
|
||
public void beforeClass( | ||
@Observes(precedence = DEFAULT_PRECEDENCE) org.jboss.arquillian.test.spi.event.suite.BeforeSuite event) { | ||
LOGGER.debug("Starting LRA coordinator on port " + coordinatorPort); | ||
coordinatorContainer = new GenericContainer<>(DockerImageName.parse("jbosstm/lra-coordinator:latest")) | ||
// lra-coordinator is a Quarkus service | ||
.withEnv("QUARKUS_HTTP_PORT", String.valueOf(coordinatorPort)) | ||
// need to run with host network because coordinator calls the TCK services from the container | ||
.withNetworkMode("host"); | ||
|
||
coordinatorContainer.start(); | ||
|
||
System.setProperty("lra.coordinator.url", String.format("http://localhost:%d/lra-coordinator", coordinatorPort)); | ||
} | ||
|
||
public void afterClass( | ||
@Observes(precedence = DEFAULT_PRECEDENCE) org.jboss.arquillian.test.spi.event.suite.AfterSuite event) { | ||
if (coordinatorContainer != null && coordinatorContainer.isRunning()) { | ||
coordinatorContainer.stop(); | ||
} | ||
} | ||
|
||
public int getFreePort(int from, int to) { | ||
int currentPort = from; | ||
while (currentPort <= to) { | ||
if (isLocalPortFree(currentPort)) { | ||
return currentPort; | ||
} else { | ||
currentPort++; | ||
} | ||
} | ||
|
||
throw new RuntimeException( | ||
String.format("Unable to find a free port for the LRA coordinator in range [%d, %d]", from, to)); | ||
} | ||
|
||
private boolean isLocalPortFree(int port) { | ||
try { | ||
new ServerSocket(port).close(); | ||
return true; | ||
} catch (IOException e) { | ||
return false; | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
tcks/microprofile-lra/src/main/java/io/quarkus/tck/lra/NarayanaLRARecovery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2022, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package io.quarkus.tck.lra; | ||
|
||
import static io.narayana.lra.LRAConstants.RECOVERY_COORDINATOR_PATH_NAME; | ||
|
||
import java.net.URI; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.UriBuilder; | ||
|
||
import org.eclipse.microprofile.lra.tck.service.spi.LRARecoveryService; | ||
import org.jboss.logging.Logger; | ||
|
||
import io.narayana.lra.LRAConstants; | ||
|
||
public class NarayanaLRARecovery implements LRARecoveryService { | ||
private static final Logger log = Logger.getLogger(NarayanaLRARecovery.class); | ||
|
||
@Override | ||
public void waitForCallbacks(URI lraId) { | ||
// no action needed | ||
} | ||
|
||
@Override | ||
public boolean waitForEndPhaseReplay(URI lraId) { | ||
log.info("waitForEndPhaseReplay for: " + lraId.toASCIIString()); | ||
if (!recoverLRAs(lraId)) { | ||
// first recovery scan probably collided with periodic recovery which started | ||
// before the test execution so try once more | ||
return recoverLRAs(lraId); | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Invokes LRA coordinator recovery REST endpoint and returns whether the recovery of intended LRAs happened | ||
* | ||
* @param lraId the LRA id of the LRA that is intended to be recovered | ||
* @return true the intended LRA recovered, false otherwise | ||
*/ | ||
private boolean recoverLRAs(URI lraId) { | ||
// trigger a recovery scan | ||
Client recoveryCoordinatorClient = ClientBuilder.newClient(); | ||
|
||
try { | ||
URI lraCoordinatorUri = LRAConstants.getLRACoordinatorUrl(lraId); | ||
URI recoveryCoordinatorUri = UriBuilder.fromUri(lraCoordinatorUri) | ||
.path(RECOVERY_COORDINATOR_PATH_NAME).build(); | ||
WebTarget recoveryTarget = recoveryCoordinatorClient.target(recoveryCoordinatorUri); | ||
|
||
// send the request to the recovery coordinator | ||
Response response = recoveryTarget.request().get(); | ||
String json = response.readEntity(String.class); | ||
response.close(); | ||
|
||
// intended LRA didn't recover | ||
return !json.contains(lraId.toASCIIString()); | ||
} finally { | ||
recoveryCoordinatorClient.close(); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
tcks/microprofile-lra/src/test/java/io/quarkus/tck/lra/Dummy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.quarkus.tck.lra; | ||
|
||
// We need this class so that target/test-classes is added to the class path? | ||
public class Dummy { | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...sources/META-INF/services/org.eclipse.microprofile.lra.tck.service.spi.LRARecoveryService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.tck.lra.NarayanaLRARecovery |
1 change: 1 addition & 0 deletions
1
...-lra/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.tck.lra.ArquillianExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.