You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2020/12/17 12:00:51 UTC
[camel-kafka-connector] branch master updated: Align SQL tests with
test infra from Camel 3.7
This is an automated email from the ASF dual-hosted git repository.
orpiske 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 827a5ee Align SQL tests with test infra from Camel 3.7
827a5ee is described below
commit 827a5ee9806fbcef3120e57f6f646e465deb2ea6
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Thu Dec 17 11:42:01 2020 +0100
Align SQL tests with test infra from Camel 3.7
---
tests/itests-sql/pom.xml | 17 +++++++
.../sql/services/SQLLocalContainerService.java | 55 ----------------------
.../sql/services/SQLRemoteService.java | 41 ----------------
.../kafkaconnector/sql/services/SQLService.java | 46 ------------------
.../sql/services/SQLServiceFactory.java | 43 -----------------
.../sql/services/TestDataSource.java | 7 +--
.../sql/sink/CamelSinkSQLITCase.java | 25 ++++++++--
.../sql/source/CamelSourceSQLITCase.java | 25 ++++++++--
8 files changed, 61 insertions(+), 198 deletions(-)
diff --git a/tests/itests-sql/pom.xml b/tests/itests-sql/pom.xml
index dbcf4af..b3b5ddd 100644
--- a/tests/itests-sql/pom.xml
+++ b/tests/itests-sql/pom.xml
@@ -37,6 +37,23 @@
<scope>test</scope>
</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.apache.camel</groupId>
<artifactId>camel-sql</artifactId>
diff --git a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLLocalContainerService.java b/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLLocalContainerService.java
deleted file mode 100644
index e94805d..0000000
--- a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLLocalContainerService.java
+++ /dev/null
@@ -1,55 +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.sql.services;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.JdbcDatabaseContainer;
-import org.testcontainers.containers.PostgreSQLContainer;
-
-public class SQLLocalContainerService implements SQLService {
- private static final Logger LOG = LoggerFactory.getLogger(SQLLocalContainerService.class);
-
- private static JdbcDatabaseContainer container;
-
- public SQLLocalContainerService() {
- container = new PostgreSQLContainer().withDatabaseName("camel").withUsername("ckc").withPassword("ckcDevel123").withInitScript("schema.sql").withStartupTimeoutSeconds(60);
-
- container.start();
-
- System.setProperty("sql.url", container.getJdbcUrl());
- }
-
- @Override
- public String sqlUrl() {
- return container.getJdbcUrl();
- }
-
- @Override
- public void initialize() {
- LOG.info("Database instance available via JDBC url {}", container.getJdbcUrl());
- }
-
- @Override
- public void shutdown() {
- System.err.println("Shutdown");
- LOG.info("Stopping the database instance");
- container.stop();
- }
-
-}
diff --git a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLRemoteService.java b/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLRemoteService.java
deleted file mode 100644
index 47fd863..0000000
--- a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLRemoteService.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.sql.services;
-
-public class SQLRemoteService implements SQLService {
- private static final String CONNECTION_URL;
-
- static {
- CONNECTION_URL = System.getProperty("sql.connection.url");
- }
-
- @Override
- public String sqlUrl() {
- return CONNECTION_URL;
- }
-
- @Override
- public void initialize() {
- // NO-OP
- }
-
- @Override
- public void shutdown() {
- // NO-OP
- }
-}
diff --git a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLService.java b/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLService.java
deleted file mode 100644
index 44d48fb..0000000
--- a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLService.java
+++ /dev/null
@@ -1,46 +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.sql.services;
-
-import org.junit.jupiter.api.extension.AfterAllCallback;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-public interface SQLService extends BeforeAllCallback, AfterAllCallback {
- /**
- * Perform any initialization necessary
- */
- void initialize();
-
- /**
- * Shuts down the service after the test has completed
- */
- void shutdown();
-
- String sqlUrl();
-
- @Override
- default void beforeAll(ExtensionContext extensionContext) throws Exception {
- initialize();
- }
-
- @Override
- default void afterAll(ExtensionContext extensionContext) throws Exception {
- shutdown();
- }
-}
diff --git a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLServiceFactory.java b/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLServiceFactory.java
deleted file mode 100644
index 90bd411..0000000
--- a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/SQLServiceFactory.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.sql.services;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class SQLServiceFactory {
- private static final Logger LOG = LoggerFactory.getLogger(SQLServiceFactory.class);
-
- private SQLServiceFactory() {
- }
-
- public static SQLService createService() {
- String instanceType = System.getProperty("sql.instance.type");
-
- if (instanceType == null || instanceType.equals("local-sql-container")) {
- return new SQLLocalContainerService();
- }
-
- if (instanceType.equals("remote")) {
- return new SQLRemoteService();
- }
-
- LOG.error("SQL instance must be one of 'local-sql-container' or 'remote");
- throw new UnsupportedOperationException("Invalid SQL instance type: " + instanceType);
- }
-}
diff --git a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/TestDataSource.java b/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/TestDataSource.java
index 13eee72..a1bad09 100644
--- a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/TestDataSource.java
+++ b/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/services/TestDataSource.java
@@ -17,17 +17,14 @@
package org.apache.camel.kafkaconnector.sql.services;
+import org.apache.camel.test.infra.jdbc.common.JDBCProperties;
import org.postgresql.ds.PGSimpleDataSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class TestDataSource extends PGSimpleDataSource {
- private static final Logger LOG = LoggerFactory.getLogger(TestDataSource.class);
-
private static final String URL;
static {
- URL = System.getProperty("sql.url");
+ URL = System.getProperty(JDBCProperties.JDBC_CONNECTION_URL);
}
public TestDataSource() {
diff --git a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/sink/CamelSinkSQLITCase.java b/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/sink/CamelSinkSQLITCase.java
index 9cd1ff3..1d75fa2 100644
--- a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/sink/CamelSinkSQLITCase.java
+++ b/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/sink/CamelSinkSQLITCase.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.sql.client.DatabaseClient;
-import org.apache.camel.kafkaconnector.sql.services.SQLService;
-import org.apache.camel.kafkaconnector.sql.services.SQLServiceFactory;
import org.apache.camel.kafkaconnector.sql.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;
@@ -51,11 +53,26 @@ public class CamelSinkSQLITCase extends AbstractKafkaTest {
private static final Logger LOG = LoggerFactory.getLogger(CamelSinkSQLITCase.class);
@RegisterExtension
- public SQLService sqlService = SQLServiceFactory.createService();
+ public JDBCService sqlService;
private final int expect = 1;
private int received;
+ public CamelSinkSQLITCase() {
+ JdbcDatabaseContainer container = new PostgreSQLContainer("postgres:9.6.2")
+ .withDatabaseName("camel")
+ .withUsername("ckc")
+ .withPassword("ckcDevel123")
+ .withInitScript("schema.sql")
+ .withStartupTimeoutSeconds(60);
+
+ sqlService = JDBCServiceBuilder.newBuilder()
+ .withContainer(container)
+ .build();
+
+ sqlService.initialize();
+ }
+
@Override
protected String[] getConnectorsInTest() {
return new String[] {"camel-sql-kafka-connector"};
@@ -115,7 +132,7 @@ public class CamelSinkSQLITCase extends AbstractKafkaTest {
LOG.debug("Waiting for indices");
try {
- DatabaseClient client = new DatabaseClient(sqlService.sqlUrl());
+ DatabaseClient client = new DatabaseClient(sqlService.jdbcUrl());
TestUtils.waitFor(() -> {
try {
diff --git a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/source/CamelSourceSQLITCase.java b/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/source/CamelSourceSQLITCase.java
index 4dc4b16..5e2298c 100644
--- a/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/source/CamelSourceSQLITCase.java
+++ b/tests/itests-sql/src/test/java/org/apache/camel/kafkaconnector/sql/source/CamelSourceSQLITCase.java
@@ -23,15 +23,17 @@ import org.apache.camel.kafkaconnector.common.AbstractKafkaTest;
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.sql.services.SQLService;
-import org.apache.camel.kafkaconnector.sql.services.SQLServiceFactory;
import org.apache.camel.kafkaconnector.sql.services.TestDataSource;
+import org.apache.camel.test.infra.jdbc.services.JDBCService;
+import org.apache.camel.test.infra.jdbc.services.JDBCServiceBuilder;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
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;
@@ -41,11 +43,26 @@ public class CamelSourceSQLITCase extends AbstractKafkaTest {
private static final Logger LOG = LoggerFactory.getLogger(CamelSourceSQLITCase.class);
@RegisterExtension
- public SQLService sqlService = SQLServiceFactory.createService();
+ public JDBCService sqlService;
private final int expect = 1;
private int received;
+ public CamelSourceSQLITCase() {
+ JdbcDatabaseContainer container = new PostgreSQLContainer("postgres:9.6.2")
+ .withDatabaseName("camel")
+ .withUsername("ckc")
+ .withPassword("ckcDevel123")
+ .withInitScript("schema.sql")
+ .withStartupTimeoutSeconds(60);
+
+ sqlService = JDBCServiceBuilder.newBuilder()
+ .withContainer(container)
+ .build();
+
+ sqlService.initialize();
+ }
+
@Override
protected String[] getConnectorsInTest() {
return new String[] {"camel-sql-kafka-connector"};
@@ -72,7 +89,7 @@ public class CamelSourceSQLITCase extends AbstractKafkaTest {
assertEquals(received, expect, "Didn't process the expected amount of messages");
}
- @Timeout(10)
+ @Timeout(30)
@Test
public void testDBFetch() throws ExecutionException, InterruptedException {
CamelSqlPropertyFactory factory = CamelSqlPropertyFactory.basic().withDataSource(CamelSqlPropertyFactory.classRef(TestDataSource.class.getName()))