You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/12/17 10:06:17 UTC
[camel-kafka-connector] branch master updated: Align JDBC tests
with test infra from Camel 3.7
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector.git
The following commit(s) were added to refs/heads/master by this push:
new 5eab2cb Align JDBC tests with test infra from Camel 3.7
5eab2cb is described below
commit 5eab2cb7ca578dab95ba2e8e5fa8f075acf421eb
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Thu Dec 17 10:27:28 2020 +0100
Align JDBC tests with test infra from Camel 3.7
---
tests/itests-jdbc/pom.xml | 17 +++++++
.../jdbc/services/JDBCLocalContainerService.java | 58 ----------------------
.../jdbc/services/JDBCRemoteService.java | 41 ---------------
.../kafkaconnector/jdbc/services/JDBCService.java | 47 ------------------
.../jdbc/services/JDBCServiceFactory.java | 43 ----------------
.../jdbc/services/TestDataSource.java | 3 +-
.../jdbc/sink/CamelSinkJDBCITCase.java | 28 +++++++++--
7 files changed, 42 insertions(+), 195 deletions(-)
diff --git a/tests/itests-jdbc/pom.xml b/tests/itests-jdbc/pom.xml
index 8e55756..8378f27 100644
--- a/tests/itests-jdbc/pom.xml
+++ b/tests/itests-jdbc/pom.xml
@@ -42,6 +42,23 @@
<artifactId>camel-jdbc</artifactId>
</dependency>
+ <!-- test infra -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-common</artifactId>
+ <version>${camel.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-jdbc</artifactId>
+ <version>${camel.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.testcontainers</groupId>
diff --git a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCLocalContainerService.java b/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCLocalContainerService.java
deleted file mode 100644
index 98ac948..0000000
--- a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCLocalContainerService.java
+++ /dev/null
@@ -1,58 +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.kafkaconnector.jdbc.services;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.JdbcDatabaseContainer;
-import org.testcontainers.containers.PostgreSQLContainer;
-
-public class JDBCLocalContainerService implements JDBCService {
- private static final Logger LOG = LoggerFactory.getLogger(JDBCLocalContainerService.class);
-
- private static JdbcDatabaseContainer container;
-
- public JDBCLocalContainerService() {
- container = new PostgreSQLContainer()
- .withDatabaseName("camel")
- .withUsername("ckc")
- .withPassword("ckcDevel123")
- .withInitScript("schema.sql")
- .withStartupTimeoutSeconds(60);
-
- container.start();
-
- System.setProperty("jdbc.url", container.getJdbcUrl());
- }
-
- @Override
- public String jdbcUrl() {
- return container.getJdbcUrl();
- }
-
- @Override
- public void initialize() {
- LOG.info("Database instance available via JDBC url {}", container.getJdbcUrl());
- }
-
- @Override
- public void shutdown() {
- LOG.info("Stopping the database instance");
- container.stop();
- }
-}
diff --git a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCRemoteService.java b/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCRemoteService.java
deleted file mode 100644
index f351010..0000000
--- a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCRemoteService.java
+++ /dev/null
@@ -1,41 +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.kafkaconnector.jdbc.services;
-
-public class JDBCRemoteService implements JDBCService {
- private static final String CONNECTION_URL;
-
- static {
- CONNECTION_URL = System.getProperty("jdbc.connection.url");
- }
-
- @Override
- public String jdbcUrl() {
- return CONNECTION_URL;
- }
-
- @Override
- public void initialize() {
- // NO-OP
- }
-
- @Override
- public void shutdown() {
- // NO-OP
- }
-}
diff --git a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCService.java b/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCService.java
deleted file mode 100644
index 4ee5996..0000000
--- a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCService.java
+++ /dev/null
@@ -1,47 +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.kafkaconnector.jdbc.services;
-
-import org.junit.jupiter.api.extension.AfterAllCallback;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-public interface JDBCService extends BeforeAllCallback, AfterAllCallback {
- /**
- * Perform any initialization necessary
- */
- void initialize();
-
- /**
- * Shuts down the service after the test has completed
- */
- void shutdown();
-
- String jdbcUrl();
-
-
- @Override
- default void beforeAll(ExtensionContext extensionContext) throws Exception {
- initialize();
- }
-
- @Override
- default void afterAll(ExtensionContext extensionContext) throws Exception {
- shutdown();
- }
-}
diff --git a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCServiceFactory.java b/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCServiceFactory.java
deleted file mode 100644
index ff7ef02..0000000
--- a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/JDBCServiceFactory.java
+++ /dev/null
@@ -1,43 +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.kafkaconnector.jdbc.services;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class JDBCServiceFactory {
- private static final Logger LOG = LoggerFactory.getLogger(JDBCServiceFactory.class);
-
- private JDBCServiceFactory() {
- }
-
- public static JDBCService createService() {
- String instanceType = System.getProperty("jdbc.instance.type");
-
- if (instanceType == null || instanceType.equals("local-jdbc-container")) {
- return new JDBCLocalContainerService();
- }
-
- if (instanceType.equals("remote")) {
- return new JDBCRemoteService();
- }
-
- LOG.error("JDBC instance must be one of 'local-jdbc-container' or 'remote");
- throw new UnsupportedOperationException("Invalid JDBC instance type: " + instanceType);
- }
-}
diff --git a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/TestDataSource.java b/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/TestDataSource.java
index 114bd67..351ab4d 100644
--- a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/TestDataSource.java
+++ b/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/services/TestDataSource.java
@@ -17,6 +17,7 @@
package org.apache.camel.kafkaconnector.jdbc.services;
+import org.apache.camel.test.infra.jdbc.common.JDBCProperties;
import org.postgresql.ds.PGSimpleDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,7 +28,7 @@ public class TestDataSource extends PGSimpleDataSource {
private static final String URL;
static {
- URL = System.getProperty("jdbc.url");
+ URL = System.getProperty(JDBCProperties.JDBC_CONNECTION_URL);
}
public TestDataSource() {
diff --git a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/sink/CamelSinkJDBCITCase.java b/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/sink/CamelSinkJDBCITCase.java
index 7066ff3..0ad4a10 100644
--- a/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/sink/CamelSinkJDBCITCase.java
+++ b/tests/itests-jdbc/src/test/java/org/apache/camel/kafkaconnector/jdbc/sink/CamelSinkJDBCITCase.java
@@ -33,13 +33,15 @@ import org.apache.camel.kafkaconnector.common.ConnectorPropertyFactory;
import org.apache.camel.kafkaconnector.common.clients.kafka.KafkaClient;
import org.apache.camel.kafkaconnector.common.utils.TestUtils;
import org.apache.camel.kafkaconnector.jdbc.client.DatabaseClient;
-import org.apache.camel.kafkaconnector.jdbc.services.JDBCService;
-import org.apache.camel.kafkaconnector.jdbc.services.JDBCServiceFactory;
import org.apache.camel.kafkaconnector.jdbc.services.TestDataSource;
+import org.apache.camel.test.infra.jdbc.services.JDBCService;
+import org.apache.camel.test.infra.jdbc.services.JDBCServiceBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.JdbcDatabaseContainer;
+import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Testcontainers;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -48,14 +50,30 @@ import static org.junit.jupiter.api.Assertions.fail;
@Testcontainers
public class CamelSinkJDBCITCase extends AbstractKafkaTest {
- private static final Logger LOG = LoggerFactory.getLogger(CamelSinkJDBCITCase.class);
-
@RegisterExtension
- public JDBCService jdbcService = JDBCServiceFactory.createService();
+ static JDBCService jdbcService;
+
+ private static final Logger LOG = LoggerFactory.getLogger(CamelSinkJDBCITCase.class);
private final int expect = 10;
private int received;
+ static {
+ final String postgresImage = "postgres:9.6.2";
+
+ JdbcDatabaseContainer container = new PostgreSQLContainer(postgresImage)
+ .withDatabaseName("camel")
+ .withUsername("ckc")
+ .withPassword("ckcDevel123")
+ .withInitScript("schema.sql")
+ .withStartupTimeoutSeconds(60);
+
+ // Let the JDBC Service handle container lifecycle
+ jdbcService = JDBCServiceBuilder.newBuilder()
+ .withContainer(container)
+ .build();
+ }
+
@Override
protected String[] getConnectorsInTest() {
return new String[] {"camel-jdbc-kafka-connector"};