From 61232e9ee046b471cd27853ce079450cd1a28226 Mon Sep 17 00:00:00 2001 From: James Netherton Date: Thu, 4 Jan 2024 09:31:58 +0000 Subject: [PATCH] Use Quarkus Derby DevServices for SQL integration test Fixes #5633 --- integration-tests-support/pom.xml | 1 - .../sql-derby-support/README.adoc | 3 - .../sql-derby-support/pom.xml | 42 -------- integration-tests/sql/.gitignore | 1 + integration-tests/sql/pom.xml | 24 ----- .../component/sql/it/SqlDbInitializer.java | 6 -- .../derby/NumberAddStoredProcedure.java | 10 +- .../src/main/resources/sql/derby/initDb.sql | 2 +- .../resources/sql/derby/initDb_docker.sql | 20 ---- .../component/sql/it/DerbyTestResource.java | 96 ------------------- .../quarkus/component/sql/it/SqlTest.java | 3 - pom.xml | 1 - poms/bom-test/pom.xml | 5 - 13 files changed, 6 insertions(+), 208 deletions(-) delete mode 100644 integration-tests-support/sql-derby-support/README.adoc delete mode 100644 integration-tests-support/sql-derby-support/pom.xml create mode 100644 integration-tests/sql/.gitignore rename integration-tests-support/sql-derby-support/src/main/java/test/AddNumsProcedure.java => integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/storedproc/derby/NumberAddStoredProcedure.java (82%) delete mode 100644 integration-tests/sql/src/main/resources/sql/derby/initDb_docker.sql delete mode 100644 integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/DerbyTestResource.java diff --git a/integration-tests-support/pom.xml b/integration-tests-support/pom.xml index 3860e58fb3ed..b4a30c3ff65f 100644 --- a/integration-tests-support/pom.xml +++ b/integration-tests-support/pom.xml @@ -51,7 +51,6 @@ kafka mongodb process-executor-support - sql-derby-support test-support mock-backend wiremock diff --git a/integration-tests-support/sql-derby-support/README.adoc b/integration-tests-support/sql-derby-support/README.adoc deleted file mode 100644 index 5b0da368d760..000000000000 --- a/integration-tests-support/sql-derby-support/README.adoc +++ /dev/null @@ -1,3 +0,0 @@ -== SQL integration tests - -This module creates jar with stored procedure used in test from `sql` module (for derby database). \ No newline at end of file diff --git a/integration-tests-support/sql-derby-support/pom.xml b/integration-tests-support/sql-derby-support/pom.xml deleted file mode 100644 index 6e104dda6148..000000000000 --- a/integration-tests-support/sql-derby-support/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - org.apache.camel.quarkus - camel-quarkus-integration-tests-support - 3.7.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - camel-quarkus-integration-tests-support-sql-derby - Camel Quarkus :: Integration Tests :: Support :: Sql Derby - - - h2 - - - - - org.apache.camel.quarkus - camel-quarkus-sql - - - diff --git a/integration-tests/sql/.gitignore b/integration-tests/sql/.gitignore new file mode 100644 index 000000000000..1298c5f0fe33 --- /dev/null +++ b/integration-tests/sql/.gitignore @@ -0,0 +1 @@ +derby.log diff --git a/integration-tests/sql/pom.xml b/integration-tests/sql/pom.xml index 01ec2d33ce85..a89176655f9f 100644 --- a/integration-tests/sql/pom.xml +++ b/integration-tests/sql/pom.xml @@ -75,11 +75,6 @@ awaitility test - - org.apache.camel.quarkus - camel-quarkus-integration-tests-support-sql-derby - test - org.testcontainers testcontainers @@ -195,25 +190,6 @@ derby - - - - maven-dependency-plugin - - - process-sources - - copy-dependencies - - - camel-quarkus-integration-tests-support-sql-derby - target/test-classes/derby/ - - - - - - io.quarkus diff --git a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlDbInitializer.java b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlDbInitializer.java index f71172773656..fa2b9c24eaf4 100644 --- a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlDbInitializer.java +++ b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlDbInitializer.java @@ -43,13 +43,7 @@ public class SqlDbInitializer { String dbKind; public void initDb() throws SQLException, IOException { - runScripts("initDb.sql"); - - if (SqlHelper.useDocker()) { - //docker execution may require more sql scripts - runScripts("initDb_docker.sql"); - } } private void runScripts(String fileName) throws SQLException, IOException { diff --git a/integration-tests-support/sql-derby-support/src/main/java/test/AddNumsProcedure.java b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/storedproc/derby/NumberAddStoredProcedure.java similarity index 82% rename from integration-tests-support/sql-derby-support/src/main/java/test/AddNumsProcedure.java rename to integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/storedproc/derby/NumberAddStoredProcedure.java index efbfaa2d5085..9c454c96424a 100644 --- a/integration-tests-support/sql-derby-support/src/main/java/test/AddNumsProcedure.java +++ b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/storedproc/derby/NumberAddStoredProcedure.java @@ -14,18 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package test; +package org.apache.camel.quarkus.component.sql.it.storedproc.derby; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; -public class AddNumsProcedure { - - public static void testProc(int a, int b) throws SQLException { - String sql = "insert into ADD_NUMS_RESULTS (id, value) VALUES (1, " + (a + b) + ")"; - +public class NumberAddStoredProcedure { + public static void addNumbers(int a, int b) throws SQLException { + String sql = "INSERT INTO ADD_NUMS_RESULTS (id, value) VALUES (1, " + (a + b) + ")"; try (Connection con = DriverManager.getConnection("jdbc:default:connection"); PreparedStatement ps = con.prepareStatement(sql)) { ps.execute(); 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 11712b6f08b6..40f4617e9b04 100644 --- a/integration-tests/sql/src/main/resources/sql/derby/initDb.sql +++ b/integration-tests/sql/src/main/resources/sql/derby/initDb.sql @@ -40,4 +40,4 @@ CREATE TABLE aggregation_completed (id VARCHAR(255) NOT NULL, exchange BLOB NOT DROP TABLE ADD_NUMS_RESULTS CREATE TABLE ADD_NUMS_RESULTS (id INT PRIMARY KEY, value INT NOT NULL) -CREATE PROCEDURE ADD_NUMS(IN a INTEGER, IN b INTEGER) PARAMETER STYLE JAVA LANGUAGE JAVA EXTERNAL NAME 'test.AddNumsProcedure.testProc' +CREATE PROCEDURE ADD_NUMS(IN a INTEGER, IN b INTEGER) PARAMETER STYLE JAVA LANGUAGE JAVA EXTERNAL NAME 'org.apache.camel.quarkus.component.sql.it.storedproc.derby.NumberAddStoredProcedure.addNumbers' diff --git a/integration-tests/sql/src/main/resources/sql/derby/initDb_docker.sql b/integration-tests/sql/src/main/resources/sql/derby/initDb_docker.sql deleted file mode 100644 index a0d87ad3c18c..000000000000 --- a/integration-tests/sql/src/main/resources/sql/derby/initDb_docker.sql +++ /dev/null @@ -1,20 +0,0 @@ --- --- 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. --- - -CALL sqlj.install_jar('/dbs/storedProcedure.jar', 'AddNumsProcedure' , 0) - -CALL syscs_util.syscs_set_database_property('derby.database.classpath', 'APP.ADDNUMSPROCEDURE') diff --git a/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/DerbyTestResource.java b/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/DerbyTestResource.java deleted file mode 100644 index 256f7364642d..000000000000 --- a/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/DerbyTestResource.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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; - -import java.io.File; -import java.net.URL; -import java.util.Collections; -import java.util.Map; - -import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; -import org.apache.camel.util.CollectionHelper; -import org.eclipse.microprofile.config.ConfigProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.utility.MountableFile; -import org.testcontainers.utility.TestcontainersConfiguration; - -/** - * Derby test resource starts derby container in case that SQL_USE_DERBY_DOCKER is set to true. - * It uses fixed port number obtained from SQL_USE_DERBY_PORT. - */ -public class DerbyTestResource implements QuarkusTestResourceLifecycleManager { - private static final Logger LOGGER = LoggerFactory.getLogger(DerbyTestResource.class); - private static final String DERBY_IMAGE_NAME = ConfigProvider.getConfig().getValue("derby.container.image", String.class); - private GenericContainer container; - - @Override - public Map start() { - //should be started only for derby in docker - // derby dev service does not work - it is still in process, see https://quarkus.io/guides/databases-dev-services - if (!SqlHelper.useDocker()) { - return Collections.emptyMap(); - } - - LOGGER.info(TestcontainersConfiguration.getInstance().toString()); - - try { - URL derby = Thread.currentThread().getContextClassLoader().getResource("derby"); - File[] jars = new File(derby.toURI()) - .listFiles((d, n) -> n.startsWith("camel-quarkus-integration-tests-support-sql-derby")); - if (jars.length != 1) { - String msg = "There has to be one jar in target/test-classes with the name \"camel-quarkus-integration-test-sql-derby-stored-procedure-*.jar\", which contains stored procedure for the derby db."; - LOGGER.error(msg); - throw new IllegalStateException(msg); - } - - container = new GenericContainer("az82/docker-derby") - .withExposedPorts(1527) - .withCopyFileToContainer( - MountableFile.forClasspathResource("derby/" + jars[0].getName()), - "/dbs/storedProcedure.jar") - .waitingFor(Wait.forListeningPort()); - - container.start(); - - return CollectionHelper.mapOf("quarkus.datasource.jdbc.url", - "jdbc:derby://localhost:" + container.getMappedPort(1527) + "/DOCKERDB;create=true"); - - } catch (Exception e) { - LOGGER.error("Container does not start", e); - throw new RuntimeException(e); - } - } - - protected void startContainer() throws Exception { - container.start(); - } - - @Override - public void stop() { - try { - if (container != null) { - container.stop(); - } - } catch (Exception e) { - // ignored - } - } -} 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 9db910560de9..2f624425635a 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 @@ -20,7 +20,6 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -33,12 +32,10 @@ import org.hamcrest.text.IsEqualIgnoringCase; import org.junit.jupiter.api.Test; -import static io.restassured.RestAssured.given; import static org.awaitility.Awaitility.await; import static org.hamcrest.Matchers.*; @QuarkusTest -@QuarkusTestResource(DerbyTestResource.class) class SqlTest { @Test diff --git a/pom.xml b/pom.xml index fedecb5f15d4..5beebad2cbc8 100644 --- a/pom.xml +++ b/pom.xml @@ -218,7 +218,6 @@ docker.io/hashicorp/consul:1.16 docker.io/couchbase/server:7.2.0 docker.io/couchdb:2.3.1 - docker.io/az82/docker-derby:10.16 docker.io/eclipse-mosquitto:1.6.15 eclipse-temurin:17-ubi9-minimal docker.io/elasticsearch:8.8.1 diff --git a/poms/bom-test/pom.xml b/poms/bom-test/pom.xml index 9e4a72b51591..a3e9dbccea27 100644 --- a/poms/bom-test/pom.xml +++ b/poms/bom-test/pom.xml @@ -208,11 +208,6 @@ camel-quarkus-integration-tests-support-mongodb ${camel-quarkus.version} - - org.apache.camel.quarkus - camel-quarkus-integration-tests-support-sql-derby - ${camel-quarkus.version} - org.apache.camel.quarkus camel-quarkus-integration-wiremock-support