This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push: new bd760b3 Fix #2604 to add a camel-sql case in jta integration tests bd760b3 is described below commit bd760b38f985cd85962ffd1687db22841f65835c Author: Amos Feng <zf...@redhat.com> AuthorDate: Tue May 25 00:18:50 2021 +0800 Fix #2604 to add a camel-sql case in jta integration tests --- integration-tests/jta/pom.xml | 4 +++ .../quarkus/component/jta/it/JtaResource.java | 30 +++++++++++++++++----- .../camel/quarkus/component/jta/it/JtaRoutes.java | 17 +++++++++++- .../camel/quarkus/component/jta/it/JtaTest.java | 13 ++++++++-- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/integration-tests/jta/pom.xml b/integration-tests/jta/pom.xml index a6c0db7..813f7b9 100644 --- a/integration-tests/jta/pom.xml +++ b/integration-tests/jta/pom.xml @@ -64,6 +64,10 @@ <artifactId>camel-quarkus-jdbc</artifactId> </dependency> <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-sql</artifactId> + </dependency> + <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy</artifactId> </dependency> diff --git a/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaResource.java b/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaResource.java index e73a658..7fc6035 100644 --- a/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaResource.java +++ b/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaResource.java @@ -100,6 +100,28 @@ public class JtaResource { @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public Response jdbc(String message) throws Exception { + String response = request("direct:jdbc", message); + LOG.infof("Got response from jdbc: %s", response); + return Response + .created(new URI("https://camel.apache.org/")) + .entity(response) + .build(); + } + + @Path("/sqltx") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Response sqltx(String message) throws Exception { + String response = request("direct:sqltx", message); + LOG.infof("Got response from sqltx: %s", response); + return Response + .created(new URI("https://camel.apache.org/")) + .entity(response) + .build(); + } + + private String request(String endpoint, String message) throws Exception { LOG.infof("message is %s", message); MockEndpoint mockEndpoint = context.getEndpoint("mock:txResult", MockEndpoint.class); mockEndpoint.reset(); @@ -107,14 +129,10 @@ public class JtaResource { mockEndpoint.expectedMessageCount(1); mockEndpoint.message(0).body().isEqualTo(message); } - final String response = producerTemplate.requestBody("direct:transaction", message, String.class); + final String response = producerTemplate.requestBody(endpoint, message, String.class); mockEndpoint.assertIsSatisfied(15000); - LOG.infof("Got response from jta: %s", response); - return Response - .created(new URI("https://camel.apache.org/")) - .entity(response) - .build(); + return response; } @Path("/mock") diff --git a/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaRoutes.java b/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaRoutes.java index bb6b277..a39d446 100644 --- a/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaRoutes.java +++ b/integration-tests/jta/src/main/java/org/apache/camel/quarkus/component/jta/it/JtaRoutes.java @@ -48,7 +48,7 @@ public class JtaRoutes extends RouteBuilder { from("direct:not_supported") .transacted("PROPAGATION_NOT_SUPPORTED").transform().constant("not_supported"); - from("direct:transaction") + from("direct:jdbc") .transacted() .setHeader("message", body()) .to("jms:queue:txTest?connectionFactory=#xaConnectionFactory&disableReplyTo=true") @@ -64,6 +64,21 @@ public class JtaRoutes extends RouteBuilder { .transform().simple("${header.message} added") .endChoice(); + from("direct:sqltx") + .transacted() + .setHeader("message", body()) + .to("jms:queue:txTest?connectionFactory=#xaConnectionFactory&disableReplyTo=true") + .to("sql:insert into example(message) values (:#message)") + .choice() + .when(header("message").startsWith("fail")) + .log("Failing forever with exception") + .process(x -> { + throw new RuntimeException("Fail"); + }) + .otherwise() + .transform().simple("${header.message} added") + .endChoice(); + from("jms:queue:txTest?connectionFactory=#xaConnectionFactory") .to("mock:txResult"); } diff --git a/integration-tests/jta/src/test/java/org/apache/camel/quarkus/component/jta/it/JtaTest.java b/integration-tests/jta/src/test/java/org/apache/camel/quarkus/component/jta/it/JtaTest.java index 95dcd1c..b518438 100644 --- a/integration-tests/jta/src/test/java/org/apache/camel/quarkus/component/jta/it/JtaTest.java +++ b/integration-tests/jta/src/test/java/org/apache/camel/quarkus/component/jta/it/JtaTest.java @@ -138,12 +138,21 @@ class JtaTest { @Test public void testJdbcInTx() { + testTx("/jta/jdbc"); + } + + @Test + public void testSqlInTx() { + testTx("/jta/sqltx"); + } + + private void testTx(String url) { final String msg = java.util.UUID.randomUUID().toString().replace("-", ""); RestAssured.given() .contentType(ContentType.TEXT) .body(msg) - .post("/jta/jdbc") + .post(url) .then() .statusCode(201) .body(is(msg + " added")); @@ -151,7 +160,7 @@ class JtaTest { RestAssured.given() .contentType(ContentType.TEXT) .body("fail") - .post("/jta/jdbc") + .post(url) .then() .statusCode(500);