You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2020/10/29 10:15:14 UTC
[camel-quarkus] branch master updated: Fix #819 saga native support
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new 8d82f59 Fix #819 saga native support
8d82f59 is described below
commit 8d82f593e2c16068ede48cf415074ec958674b13
Author: Amos Feng <zf...@redhat.com>
AuthorDate: Fri Oct 9 09:43:45 2020 +0800
Fix #819 saga native support
---
.../ROOT/pages/reference/extensions/saga.adoc | 8 +-
.../ROOT/partials/reference/components/saga.adoc | 6 +-
extensions-jvm/pom.xml | 1 -
extensions-jvm/saga/integration-test/pom.xml | 83 -----------
extensions/pom.xml | 1 +
.../saga/deployment/pom.xml | 0
.../component/saga/deployment/SagaProcessor.java | 14 --
{extensions-jvm => extensions}/saga/pom.xml | 1 -
.../saga/runtime/pom.xml | 1 +
.../main/resources/META-INF/quarkus-extension.yaml | 3 +-
integration-tests/pom.xml | 1 +
integration-tests/saga/pom.xml | 164 +++++++++++++++++++++
.../quarkus/component/saga/it/CreditService.java | 49 +++---
.../component/saga/it/OrderManagerService.java | 36 +++--
.../quarkus/component/saga/it/SagaResource.java | 47 ++++++
.../camel/quarkus/component/saga/it/SagaRoute.java | 68 +++++++++
.../camel/quarkus/component/saga/it/SagaTest.java | 7 +
.../quarkus/component/saga/it/SagaTestIT.java | 16 +-
tooling/scripts/test-categories.yaml | 1 +
19 files changed, 350 insertions(+), 157 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/saga.adoc b/docs/modules/ROOT/pages/reference/extensions/saga.adoc
index 560ffb0..8262613 100644
--- a/docs/modules/ROOT/pages/reference/extensions/saga.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/saga.adoc
@@ -2,15 +2,15 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
= Saga
:cq-artifact-id: camel-quarkus-saga
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
:cq-description: Execute custom actions within a route using the Saga EIP.
:cq-deprecated: false
:cq-jvm-since: 1.1.0
-:cq-native-since: n/a
+:cq-native-since: 1.4.0
[.badges]
-[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
+[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##1.4.0##
Execute custom actions within a route using the Saga EIP.
diff --git a/docs/modules/ROOT/partials/reference/components/saga.adoc b/docs/modules/ROOT/partials/reference/components/saga.adoc
index d7243a5..9d1767b 100644
--- a/docs/modules/ROOT/partials/reference/components/saga.adoc
+++ b/docs/modules/ROOT/partials/reference/components/saga.adoc
@@ -2,11 +2,11 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-saga
:cq-artifact-id-base: saga
-:cq-native-supported: false
-:cq-status: Preview
+:cq-native-supported: true
+:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.1.0
-:cq-native-since: n/a
+:cq-native-since: 1.4.0
:cq-camel-part-name: saga
:cq-camel-part-title: Saga
:cq-camel-part-description: Execute custom actions within a route using the Saga EIP.
diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml
index 782c646..0723b11 100644
--- a/extensions-jvm/pom.xml
+++ b/extensions-jvm/pom.xml
@@ -119,7 +119,6 @@
<module>quickfix</module>
<module>ribbon</module>
<module>robotframework</module>
- <module>saga</module>
<module>saxon</module>
<module>schematron</module>
<module>sip</module>
diff --git a/extensions-jvm/saga/integration-test/pom.xml b/extensions-jvm/saga/integration-test/pom.xml
deleted file mode 100644
index 5e7ae66..0000000
--- a/extensions-jvm/saga/integration-test/pom.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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.
-
--->
-<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-build-parent-it</artifactId>
- <version>1.4.0-SNAPSHOT</version>
- <relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
- </parent>
-
- <artifactId>camel-quarkus-saga-integration-test</artifactId>
- <name>Camel Quarkus :: Saga :: Integration Test</name>
- <description>Integration tests for Camel Quarkus Saga extension</description>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-bom-test</artifactId>
- <version>${project.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-saga</artifactId>
- </dependency>
- <dependency>
- <groupId>io.quarkus</groupId>
- <artifactId>quarkus-resteasy</artifactId>
- </dependency>
-
- <!-- test dependencies -->
- <dependency>
- <groupId>io.quarkus</groupId>
- <artifactId>quarkus-junit5</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>io.rest-assured</groupId>
- <artifactId>rest-assured</artifactId>
- <scope>test</scope>
- </dependency>
-
- <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
- <dependency>
- <groupId>org.apache.camel.quarkus</groupId>
- <artifactId>camel-quarkus-saga-deployment</artifactId>
- <version>${project.version}</version>
- <type>pom</type>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>*</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- </dependencies>
-
-</project>
diff --git a/extensions/pom.xml b/extensions/pom.xml
index 49e7935..d6acf35 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -172,6 +172,7 @@
<module>rest</module>
<module>rest-openapi</module>
<module>rss</module>
+ <module>saga</module>
<module>salesforce</module>
<module>sap-netweaver</module>
<module>scheduler</module>
diff --git a/extensions-jvm/saga/deployment/pom.xml b/extensions/saga/deployment/pom.xml
similarity index 100%
rename from extensions-jvm/saga/deployment/pom.xml
rename to extensions/saga/deployment/pom.xml
diff --git a/extensions-jvm/saga/deployment/src/main/java/org/apache/camel/quarkus/component/saga/deployment/SagaProcessor.java b/extensions/saga/deployment/src/main/java/org/apache/camel/quarkus/component/saga/deployment/SagaProcessor.java
similarity index 68%
rename from extensions-jvm/saga/deployment/src/main/java/org/apache/camel/quarkus/component/saga/deployment/SagaProcessor.java
rename to extensions/saga/deployment/src/main/java/org/apache/camel/quarkus/component/saga/deployment/SagaProcessor.java
index 993323e..05e0383 100644
--- a/extensions-jvm/saga/deployment/src/main/java/org/apache/camel/quarkus/component/saga/deployment/SagaProcessor.java
+++ b/extensions/saga/deployment/src/main/java/org/apache/camel/quarkus/component/saga/deployment/SagaProcessor.java
@@ -17,11 +17,7 @@
package org.apache.camel.quarkus.component.saga.deployment;
import io.quarkus.deployment.annotations.BuildStep;
-import io.quarkus.deployment.annotations.ExecutionTime;
-import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
-import io.quarkus.deployment.pkg.steps.NativeBuild;
-import org.apache.camel.quarkus.core.JvmOnlyRecorder;
import org.jboss.logging.Logger;
class SagaProcessor {
@@ -33,14 +29,4 @@ class SagaProcessor {
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
-
- /**
- * Remove this once this extension starts supporting the native mode.
- */
- @BuildStep(onlyIf = NativeBuild.class)
- @Record(value = ExecutionTime.RUNTIME_INIT)
- void warnJvmInNative(JvmOnlyRecorder recorder) {
- JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
- recorder.warnJvmInNative(FEATURE); // warn at runtime
- }
}
diff --git a/extensions-jvm/saga/pom.xml b/extensions/saga/pom.xml
similarity index 97%
rename from extensions-jvm/saga/pom.xml
rename to extensions/saga/pom.xml
index e125efe..ceb76b3 100644
--- a/extensions-jvm/saga/pom.xml
+++ b/extensions/saga/pom.xml
@@ -33,6 +33,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
- <module>integration-test</module>
</modules>
</project>
diff --git a/extensions-jvm/saga/runtime/pom.xml b/extensions/saga/runtime/pom.xml
similarity index 98%
rename from extensions-jvm/saga/runtime/pom.xml
rename to extensions/saga/runtime/pom.xml
index 50f7d23..6fc5614 100644
--- a/extensions-jvm/saga/runtime/pom.xml
+++ b/extensions/saga/runtime/pom.xml
@@ -32,6 +32,7 @@
<properties>
<camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince>
+ <camel.quarkus.nativeSince>1.4.0</camel.quarkus.nativeSince>
</properties>
<dependencyManagement>
diff --git a/extensions-jvm/saga/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/saga/runtime/src/main/resources/META-INF/quarkus-extension.yaml
similarity index 97%
rename from extensions-jvm/saga/runtime/src/main/resources/META-INF/quarkus-extension.yaml
rename to extensions/saga/runtime/src/main/resources/META-INF/quarkus-extension.yaml
index 289c236..a73187f 100644
--- a/extensions-jvm/saga/runtime/src/main/resources/META-INF/quarkus-extension.yaml
+++ b/extensions/saga/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -24,9 +24,8 @@
name: "Camel Saga"
description: "Execute custom actions within a route using the Saga EIP"
metadata:
- unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/saga.html"
categories:
- "integration"
status:
- - "preview"
+ - "stable"
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 9a90095..c9672b0 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -145,6 +145,7 @@
<module>rest</module>
<module>rest-binding-mode-xml</module>
<module>rest-openapi</module>
+ <module>saga</module>
<module>salesforce</module>
<module>sap-netweaver</module>
<module>send-dynamic-http</module>
diff --git a/integration-tests/saga/pom.xml b/integration-tests/saga/pom.xml
new file mode 100644
index 0000000..01a550a
--- /dev/null
+++ b/integration-tests/saga/pom.xml
@@ -0,0 +1,164 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-integration-tests</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-quarkus-integration-test-saga</artifactId>
+ <name>Camel Quarkus :: Integration Test :: Saga</name>
+ <description>Integration tests for Camel Quarkus Saga extension</description>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bom-test</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-saga</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-direct</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bean</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy</artifactId>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.rest-assured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bean-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-direct-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-saga-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <quarkus.package.type>native</quarkus.package.type>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
diff --git a/extensions-jvm/saga/integration-test/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaResource.java b/integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/CreditService.java
similarity index 50%
copy from extensions-jvm/saga/integration-test/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaResource.java
copy to integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/CreditService.java
index 7d6fcf1..24b4670 100644
--- a/extensions-jvm/saga/integration-test/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaResource.java
+++ b/integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/CreditService.java
@@ -16,36 +16,39 @@
*/
package org.apache.camel.quarkus.component.saga.it;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.camel.CamelContext;
-import org.jboss.logging.Logger;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import org.apache.camel.Header;
-@Path("/saga")
@ApplicationScoped
-public class SagaResource {
+@RegisterForReflection
+public class CreditService {
+
+ private int totalCredit;
- private static final Logger LOG = Logger.getLogger(SagaResource.class);
+ private Map<String, Integer> reservations = new HashMap<>();
- private static final String COMPONENT_SAGA = "saga";
- @Inject
- CamelContext context;
+ public CreditService() {
+ this.totalCredit = 100;
+ }
- @Path("/load/component/saga")
- @GET
- @Produces(MediaType.TEXT_PLAIN)
- public Response loadComponentSaga() throws Exception {
- /* This is an autogenerated test */
- if (context.getComponent(COMPONENT_SAGA) != null) {
- return Response.ok().build();
+ public synchronized void reserveCredit(String id, @Header("amount") int amount) {
+ int credit = getCredit();
+ if (amount > credit) {
+ throw new IllegalStateException("Insufficient credit");
}
- LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_SAGA);
- return Response.status(500, COMPONENT_SAGA + " could not be loaded from the Camel context").build();
+ reservations.put(id, amount);
+ }
+
+ public synchronized void refundCredit(String id) {
+ reservations.remove(id);
+ }
+
+ public synchronized int getCredit() {
+ return totalCredit - reservations.values().stream().reduce(0, (a, b) -> a + b);
}
}
diff --git a/extensions-jvm/saga/integration-test/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java b/integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/OrderManagerService.java
similarity index 60%
copy from extensions-jvm/saga/integration-test/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java
copy to integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/OrderManagerService.java
index 55dd404..627da7b 100644
--- a/extensions-jvm/saga/integration-test/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java
+++ b/integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/OrderManagerService.java
@@ -16,19 +16,29 @@
*/
package org.apache.camel.quarkus.component.saga.it;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
-
-@QuarkusTest
-class SagaTest {
-
- @Test
- public void loadComponentSaga() {
- /* A simple autogenerated test */
- RestAssured.get("/saga/load/component/saga")
- .then()
- .statusCode(200);
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@ApplicationScoped
+@RegisterForReflection
+public class OrderManagerService {
+
+ private Set<String> orders = new HashSet<>();
+
+ public synchronized void newOrder(String id) {
+ orders.add(id);
+ }
+
+ public synchronized void cancelOrder(String id) {
+ orders.remove(id);
}
+ public synchronized Set<String> getOrders() {
+ return new TreeSet<>(orders);
+ }
}
diff --git a/extensions-jvm/saga/integration-test/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaResource.java b/integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaResource.java
similarity index 56%
rename from extensions-jvm/saga/integration-test/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaResource.java
rename to integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaResource.java
index 7d6fcf1..802ed52 100644
--- a/extensions-jvm/saga/integration-test/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaResource.java
+++ b/integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaResource.java
@@ -34,9 +34,16 @@ public class SagaResource {
private static final Logger LOG = Logger.getLogger(SagaResource.class);
private static final String COMPONENT_SAGA = "saga";
+
@Inject
CamelContext context;
+ @Inject
+ OrderManagerService orderManagerService;
+
+ @Inject
+ CreditService creditService;
+
@Path("/load/component/saga")
@GET
@Produces(MediaType.TEXT_PLAIN)
@@ -48,4 +55,44 @@ public class SagaResource {
LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_SAGA);
return Response.status(500, COMPONENT_SAGA + " could not be loaded from the Camel context").build();
}
+
+ @Path("/test")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public Response buy() {
+ try {
+ // total credit is 100
+ buy(20, false, false);
+ buy(70, false, false);
+ buy(20, false, true); // fail
+ buy(5, false, false);
+ buy(1, true, true); // fail
+
+ // wait for the orders being cancelled
+ Thread.sleep(500);
+
+ if (orderManagerService.getOrders().size() == 3 && creditService.getCredit() == 5) {
+ return Response.ok().build();
+ } else {
+ return Response.status(500, "not equal").build();
+ }
+ } catch (Exception e) {
+ return Response.status(500, COMPONENT_SAGA + " is failed with " + e).build();
+ }
+ }
+
+ private void buy(int amount, boolean failAtTheEnd, boolean shouldFail) throws RuntimeException {
+ try {
+ context.createFluentProducerTemplate().to("direct:saga").withHeader("amount", amount)
+ .withHeader("fail", failAtTheEnd).request();
+
+ if (shouldFail) {
+ throw new RuntimeException("Exception not thrown");
+ }
+ } catch (Exception ex) {
+ if (!shouldFail) {
+ throw new RuntimeException("Unexpected exception");
+ }
+ }
+ }
}
diff --git a/integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaRoute.java b/integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaRoute.java
new file mode 100644
index 0000000..32dc3cb
--- /dev/null
+++ b/integration-tests/saga/src/main/java/org/apache/camel/quarkus/component/saga/it/SagaRoute.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.quarkus.component.saga.it;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.saga.InMemorySagaService;
+import org.apache.camel.model.SagaPropagation;
+import org.apache.camel.saga.CamelSagaService;
+
+@ApplicationScoped
+public class SagaRoute extends RouteBuilder {
+ @Inject
+ OrderManagerService orderManagerService;
+
+ @Inject
+ CreditService creditService;
+
+ @Override
+ public void configure() throws Exception {
+ CamelSagaService sagaService = new InMemorySagaService();
+ getContext().addService(sagaService);
+
+ from("direct:saga").saga().propagation(SagaPropagation.REQUIRES_NEW).log("Creating a new order")
+ .to("direct:newOrder").log("Taking the credit")
+ .to("direct:reserveCredit").log("Finalizing").to("direct:finalize").log("Done!");
+
+ // Order service
+
+ from("direct:newOrder").saga().propagation(SagaPropagation.MANDATORY).compensation("direct:cancelOrder")
+ .transform().header(Exchange.SAGA_LONG_RUNNING_ACTION)
+ .bean(orderManagerService, "newOrder").log("Order ${body} created");
+
+ from("direct:cancelOrder").transform().header(Exchange.SAGA_LONG_RUNNING_ACTION)
+ .bean(orderManagerService, "cancelOrder").log("Order ${body} cancelled");
+
+ // Credit service
+
+ from("direct:reserveCredit").saga().propagation(SagaPropagation.MANDATORY).compensation("direct:refundCredit")
+ .transform().header(Exchange.SAGA_LONG_RUNNING_ACTION)
+ .bean(creditService, "reserveCredit").log("Credit ${header.amount} reserved in action ${body}");
+
+ from("direct:refundCredit").transform().header(Exchange.SAGA_LONG_RUNNING_ACTION)
+ .bean(creditService, "refundCredit").log("Credit for action ${body} refunded");
+
+ // Final actions
+ from("direct:finalize").saga().propagation(SagaPropagation.MANDATORY).choice()
+ .when(header("fail").isEqualTo(true)).to("saga:COMPENSATE").end();
+
+ }
+}
diff --git a/extensions-jvm/saga/integration-test/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java b/integration-tests/saga/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java
similarity index 88%
copy from extensions-jvm/saga/integration-test/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java
copy to integration-tests/saga/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java
index 55dd404..9a382d9 100644
--- a/extensions-jvm/saga/integration-test/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java
+++ b/integration-tests/saga/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java
@@ -31,4 +31,11 @@ class SagaTest {
.statusCode(200);
}
+ @Test
+ public void testCreditExhausted() {
+ RestAssured.get("/saga/test")
+ .then()
+ .statusCode(200);
+ }
+
}
diff --git a/extensions-jvm/saga/integration-test/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java b/integration-tests/saga/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTestIT.java
similarity index 71%
rename from extensions-jvm/saga/integration-test/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java
rename to integration-tests/saga/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTestIT.java
index 55dd404..a27bbe1 100644
--- a/extensions-jvm/saga/integration-test/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTest.java
+++ b/integration-tests/saga/src/test/java/org/apache/camel/quarkus/component/saga/it/SagaTestIT.java
@@ -16,19 +16,9 @@
*/
package org.apache.camel.quarkus.component.saga.it;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+import io.quarkus.test.junit.NativeImageTest;
-@QuarkusTest
-class SagaTest {
-
- @Test
- public void loadComponentSaga() {
- /* A simple autogenerated test */
- RestAssured.get("/saga/load/component/saga")
- .then()
- .statusCode(200);
- }
+@NativeImageTest
+class SagaTestIT extends SagaTest {
}
diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml
index 7d9695a..b3328a3 100644
--- a/tooling/scripts/test-categories.yaml
+++ b/tooling/scripts/test-categories.yaml
@@ -73,6 +73,7 @@ foundation:
- jta
- jsonpath
- quartz
+ - saga
xml-json-olingo4:
- rest-binding-mode-xml
- xml