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 2021/11/24 15:50:08 UTC

[camel-quarkus] branch main updated: Sql test using derby doesn't start dev service and shows class loading issue if stored procedure is called #3260

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 73211f2  Sql test using derby doesn't start dev service and shows class loading issue if stored procedure is called #3260
73211f2 is described below

commit 73211f2d0fc44d7517440380e94e551934bbc189
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Mon Nov 22 15:27:38 2021 +0100

    Sql test using derby doesn't start dev service and shows class loading issue if stored procedure is called #3260
---
 integration-tests/sql/pom.xml                      | 17 ++++++++++++
 .../quarkus/component/sql/it/SqlResource.java      | 28 ++++++++++++++++---
 .../storedproc/DerbyNumberAddStoredProcedure.java  | 32 ++++++++++++++++++++++
 .../sql/src/main/resources/sql/derby/initDb.sql    |  2 ++
 .../camel/quarkus/component/sql/it/SqlTest.java    |  8 ++++--
 5 files changed, 81 insertions(+), 6 deletions(-)

diff --git a/integration-tests/sql/pom.xml b/integration-tests/sql/pom.xml
index 936b76b..3f7d486 100644
--- a/integration-tests/sql/pom.xml
+++ b/integration-tests/sql/pom.xml
@@ -156,5 +156,22 @@
                 </dependency>
             </dependencies>
         </profile>
+        <profile>
+            <id>derbyDevServiceWorkaround</id>
+            <activation>
+                <property>
+                    <name>cq.sqlJdbcKind</name>
+                    <value>derby</value>
+                </property>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.derby</groupId>
+                    <artifactId>derbynet</artifactId>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+
+        </profile>
     </profiles>
 </project>
diff --git a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlResource.java b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlResource.java
index 464ac63..ca57274 100644
--- a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlResource.java
+++ b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlResource.java
@@ -16,7 +16,11 @@
  */
 package org.apache.camel.quarkus.component.sql.it;
 
+import java.io.File;
 import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -153,14 +157,28 @@ public class SqlResource {
     @Path("/storedproc")
     @GET
     @Produces(MediaType.TEXT_PLAIN)
-    public String callStoredProcedure(@QueryParam("numA") int numA, @QueryParam("numB") int numB) {
+    public String callStoredProcedure(@QueryParam("numA") int numA, @QueryParam("numB") int numB) throws Exception {
         Map<String, Object> args = new HashMap<>();
         args.put("num1", numA);
         args.put("num2", numB);
 
-        Map<String, List<LinkedCaseInsensitiveMap>> results = producerTemplate
-                .requestBodyAndHeaders("sql-stored:ADD_NUMS(INTEGER ${headers.num1},INTEGER ${headers.num2})", null, args,
-                        Map.class);
+        String fileName = null;
+        String url;
+        if ("derby".equals(dbKind)) {
+
+            File f = File.createTempFile("storedProcedureDerby", ".txt", Paths.get("target").toFile());
+            f.deleteOnExit();
+            fileName = f.getName();
+
+            args.put("fileName", fileName);
+
+            url = "sql-stored:ADD_NUMS(INTEGER ${headers.num1},INTEGER ${headers.num2}, CHAR ${headers.fileName})";
+        } else {
+            url = "sql-stored:ADD_NUMS(INTEGER ${headers.num1},INTEGER ${headers.num2})";
+        }
+
+        Map<String, List<LinkedCaseInsensitiveMap>> results = producerTemplate.requestBodyAndHeaders(url, null, args,
+                Map.class);
 
         //different db types behaves differently
         switch (dbKind) {
@@ -175,6 +193,8 @@ public class SqlResource {
                     List.class);
 
             return String.valueOf(addNumsResults.get(0).get("value"));
+        case "derby":
+            return Files.readString(Paths.get("target", fileName), StandardCharsets.UTF_8);
         default:
             return results.get("#result-set-1").get(0).values().iterator().next().toString();
         }
diff --git a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/storedproc/DerbyNumberAddStoredProcedure.java b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/storedproc/DerbyNumberAddStoredProcedure.java
new file mode 100644
index 0000000..932aa09
--- /dev/null
+++ b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/storedproc/DerbyNumberAddStoredProcedure.java
@@ -0,0 +1,32 @@
+/*
+ * 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.sql.it.storedproc;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class DerbyNumberAddStoredProcedure {
+
+    public static void testProc(int a, int b, String fileName) throws Exception {
+        Path path = Paths.get("target", fileName);
+        byte[] strToBytes = String.valueOf(a + b).getBytes(StandardCharsets.UTF_8);
+
+        Files.write(path, strToBytes);
+    }
+}
diff --git a/integration-tests/sql/src/main/resources/sql/derby/initDb.sql b/integration-tests/sql/src/main/resources/sql/derby/initDb.sql
index 9782095..d0f633e 100644
--- a/integration-tests/sql/src/main/resources/sql/derby/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/derby/initDb.sql
@@ -35,3 +35,5 @@ DROP TABLE aggregation
 CREATE TABLE aggregation (id VARCHAR(255) NOT NULL, exchange BLOB NOT NULL, version BIGINT NOT NULL, constraint aggregation_pk PRIMARY KEY (id))
 DROP TABLE aggregation_completed
 CREATE TABLE aggregation_completed (id VARCHAR(255) NOT NULL, exchange BLOB NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY KEY (id))
+
+CREATE PROCEDURE ADD_NUMS(IN a INTEGER, IN b INTEGER, IN fileName VARCHAR(50)) PARAMETER STYLE JAVA READS SQL DATA LANGUAGE JAVA EXTERNAL NAME 'org.apache.camel.quarkus.component.sql.it.storedproc.DerbyNumberAddStoredProcedure.testProc'
diff --git a/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/SqlTest.java b/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/SqlTest.java
index c696896..70a8767 100644
--- a/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/SqlTest.java
+++ b/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/SqlTest.java
@@ -31,7 +31,7 @@ import org.hamcrest.Matcher;
 import org.hamcrest.collection.IsMapContaining;
 import org.hamcrest.text.IsEqualIgnoringCase;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+import org.junit.jupiter.api.condition.DisabledIf;
 
 import static io.restassured.RestAssured.given;
 import static org.awaitility.Awaitility.await;
@@ -70,8 +70,12 @@ class SqlTest {
                 .body(is("Dromedarius 1"));
     }
 
+    public boolean storedProcedureDisabled() {
+        return "derby".equals(System.getProperty("cq.sqlJdbcKind")) && System.getenv().containsKey("SQL_JDBC_URL");
+    }
+
     @Test
-    @DisabledIfSystemProperty(named = "cq.sqlJdbcKind", matches = "derby", disabledReason = "https://github.com/apache/camel-quarkus/issues/3260")
+    @DisabledIf("storedProcedureDisabled")
     public void testSqlStoredComponent() {
         // Invoke ADD_NUMS stored procedure
         RestAssured.given()