This is an automated email from the ASF dual-hosted git repository.
bowenliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new acdd74d5c [KYUUBI #5862] Use TestContainerForAll for testing JDBC
engine with testcontainers
acdd74d5c is described below
commit acdd74d5cafe6cc76b679a0e37cae0d8ce05659f
Author: Bowen Liang <[email protected]>
AuthorDate: Mon Dec 18 21:20:41 2023 +0800
[KYUUBI #5862] Use TestContainerForAll for testing JDBC engine with
testcontainers
# :mag: Description
## Issue References ๐
As described.
## Describe Your Solution ๐ง
- replacing the usage of `ForAllTestContainer` with `TestContainerForAll`,
simplifying the lifecycle for starting / stopping the containers and fetching
the configs from the containers
- use `testcontainers-scala-postgresql` for testing with PostgreSQL
containers
- add version 16 for PostgreSQL image tag
## Types of changes :bookmark:
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
## Test Plan ๐งช
#### Behavior Without This Pull Request :coffin:
No behaviour changes.
#### Behavior With This Pull Request :tada:
No behaviour changes.
#### Related Unit Tests
JDBC Engine IT.
---
# Checklists
## ๐ Author Self Checklist
- [x] My code follows the [style
guidelines](https://kyuubi.readthedocs.io/en/master/contributing/code/style.html)
of this project
- [x] I have performed a self-review
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature
works
- [x] New and existing unit tests pass locally with my changes
- [x] This patch was not authored or co-authored using [Generative
Tooling](https://www.apache.org/legal/generative-tooling.html)
## ๐ Committer Pre-Merge Checklist
- [ ] Pull request title is okay.
- [ ] No license issues.
- [ ] Milestone correctly set?
- [ ] Test coverage is ok
- [ ] Assignees are selected.
- [ ] Minimum number of approvals
- [ ] No changes are requested
**Be nice. Be informative.**
Closes #5862 from bowenliang123/jdbc-container.
Closes #5862
29e85121c [Bowen Liang] TestContainerForAll
Authored-by: Bowen Liang <[email protected]>
Signed-off-by: liangbowen <[email protected]>
---
externals/kyuubi-jdbc-engine/pom.xml | 6 ++++
.../engine/jdbc/WithJdbcServerContainer.scala | 4 +--
.../engine/jdbc/doris/WithDorisContainer.scala | 10 ++-----
.../kyuubi/engine/jdbc/mysql/WithMySQLEngine.scala | 6 ++--
.../engine/jdbc/phoenix/WithPhoenixContainer.scala | 12 ++------
.../jdbc/postgresql/WithPostgreSQLContainer.scala | 32 ++++++----------------
.../jdbc/postgresql/WithPostgreSQLEngine.scala | 18 ++++++------
integration-tests/kyuubi-jdbc-it/pom.xml | 6 ++++
pom.xml | 6 ++++
9 files changed, 46 insertions(+), 54 deletions(-)
diff --git a/externals/kyuubi-jdbc-engine/pom.xml
b/externals/kyuubi-jdbc-engine/pom.xml
index 0ec905f20..33f84da15 100644
--- a/externals/kyuubi-jdbc-engine/pom.xml
+++ b/externals/kyuubi-jdbc-engine/pom.xml
@@ -64,6 +64,12 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.dimafeng</groupId>
+
<artifactId>testcontainers-scala-postgresql_${scala.binary.version}</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.kyuubi</groupId>
<artifactId>${hive.jdbc.artifact}</artifactId>
diff --git
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/WithJdbcServerContainer.scala
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/WithJdbcServerContainer.scala
index 18c2316c1..89b5534be 100644
---
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/WithJdbcServerContainer.scala
+++
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/WithJdbcServerContainer.scala
@@ -16,8 +16,8 @@
*/
package org.apache.kyuubi.engine.jdbc
-import com.dimafeng.testcontainers.ForAllTestContainer
+import com.dimafeng.testcontainers.scalatest.TestContainerForAll
import org.apache.kyuubi.KyuubiFunSuite
-trait WithJdbcServerContainer extends KyuubiFunSuite with ForAllTestContainer
{}
+trait WithJdbcServerContainer extends KyuubiFunSuite with TestContainerForAll
{}
diff --git
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/doris/WithDorisContainer.scala
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/doris/WithDorisContainer.scala
index 8092e3299..1d63760ff 100644
---
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/doris/WithDorisContainer.scala
+++
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/doris/WithDorisContainer.scala
@@ -35,7 +35,7 @@ trait WithDorisContainer extends WithJdbcServerContainer {
private val DORIS_BE_SERVICE_NAME = "doris-be"
- override val container: DockerComposeContainer =
+ override val containerDef: DockerComposeContainer.Def =
DockerComposeContainer
.Def(
composeFiles = new File(Utils.getContextOrKyuubiClassLoader
@@ -51,17 +51,11 @@ trait WithDorisContainer extends WithJdbcServerContainer {
DORIS_BE_PORT,
waitStrategy =
new
DockerHealthcheckWaitStrategy().withStartupTimeout(Duration.ofMinutes(5)))))
- .createContainer()
- protected def feUrl: String = {
+ protected def feUrl: String = withContainers { container =>
val feHost: String = container.getServiceHost(DORIS_FE_SERVICE_NAME,
DORIS_FE_PORT)
val fePort: Int = container.getServicePort(DORIS_FE_SERVICE_NAME,
DORIS_FE_PORT)
val url = s"$feHost:$fePort"
url
}
-
- override def afterAll(): Unit = {
- super.afterAll()
- container.close()
- }
}
diff --git
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/mysql/WithMySQLEngine.scala
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/mysql/WithMySQLEngine.scala
index bd79e0a27..39d2e0a59 100644
---
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/mysql/WithMySQLEngine.scala
+++
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/mysql/WithMySQLEngine.scala
@@ -27,7 +27,7 @@ trait WithMySQLEngine extends WithJdbcEngine with
TestContainerForAll {
private val mysqlDockerImage = "mysql:8.0.32"
- override val containerDef = MySQLContainer.Def(
+ override val containerDef: MySQLContainer.Def = MySQLContainer.Def(
dockerImageName = DockerImageName.parse(mysqlDockerImage),
username = "root",
password = "kyuubi")
@@ -36,8 +36,8 @@ trait WithMySQLEngine extends WithJdbcEngine with
TestContainerForAll {
Map(
ENGINE_SHARE_LEVEL.key -> "SERVER",
ENGINE_JDBC_CONNECTION_URL.key -> mysqlContainer.jdbcUrl,
- ENGINE_JDBC_CONNECTION_USER.key -> "root",
- ENGINE_JDBC_CONNECTION_PASSWORD.key -> "kyuubi",
+ ENGINE_JDBC_CONNECTION_USER.key -> mysqlContainer.username,
+ ENGINE_JDBC_CONNECTION_PASSWORD.key -> mysqlContainer.password,
ENGINE_TYPE.key -> "jdbc",
ENGINE_JDBC_SHORT_NAME.key -> "mysql",
ENGINE_JDBC_DRIVER_CLASS.key -> "com.mysql.cj.jdbc.Driver")
diff --git
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/phoenix/WithPhoenixContainer.scala
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/phoenix/WithPhoenixContainer.scala
index 49b4369bc..614261e84 100644
---
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/phoenix/WithPhoenixContainer.scala
+++
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/phoenix/WithPhoenixContainer.scala
@@ -16,7 +16,7 @@
*/
package org.apache.kyuubi.engine.jdbc.phoenix
-import com.dimafeng.testcontainers.{GenericContainer, SingleContainer}
+import com.dimafeng.testcontainers.GenericContainer
import org.testcontainers.containers.wait.strategy.Wait
import org.apache.kyuubi.engine.jdbc.WithJdbcServerContainer
@@ -27,21 +27,15 @@ trait WithPhoenixContainer extends WithJdbcServerContainer {
private val phoenixDockerImage = "iteblog/hbase-phoenix-docker:1.0"
- override val container: SingleContainer[_] = GenericContainer(
+ override val containerDef: GenericContainer.Def[GenericContainer] =
GenericContainer.Def(
dockerImage = phoenixDockerImage,
exposedPorts = Seq(PHOENIX_PORT),
waitStrategy = Wait.forListeningPort)
- protected def queryServerUrl: String = {
+ protected def queryServerUrl: String = withContainers { container =>
val queryServerHost: String = container.host
val queryServerPort: Int = container.mappedPort(PHOENIX_PORT)
val url = s"$queryServerHost:$queryServerPort"
url
}
-
- override def afterAll(): Unit = {
- super.afterAll()
- container.close()
- }
-
}
diff --git
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/postgresql/WithPostgreSQLContainer.scala
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/postgresql/WithPostgreSQLContainer.scala
index 8ae6e9f10..32066946a 100644
---
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/postgresql/WithPostgreSQLContainer.scala
+++
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/postgresql/WithPostgreSQLContainer.scala
@@ -16,34 +16,18 @@
*/
package org.apache.kyuubi.engine.jdbc.postgresql
-import com.dimafeng.testcontainers.{GenericContainer, SingleContainer}
-import org.testcontainers.containers.wait.strategy.Wait
+import com.dimafeng.testcontainers.PostgreSQLContainer
+import org.testcontainers.utility.DockerImageName
import org.apache.kyuubi.engine.jdbc.WithJdbcServerContainer
trait WithPostgreSQLContainer extends WithJdbcServerContainer {
- private val POSTGRESQL_PORT = 5432
-
- private val postgreSQLDockerImage = "postgres"
-
- override val container: SingleContainer[_] = GenericContainer(
- dockerImage = postgreSQLDockerImage,
- exposedPorts = Seq(POSTGRESQL_PORT),
- env = Map[String, String](
- "POSTGRES_PASSWORD" -> "postgres"),
- waitStrategy = Wait.forListeningPort)
-
- protected def queryUrl: String = {
- val queryServerHost: String = container.host
- val queryServerPort: Int = container.mappedPort(POSTGRESQL_PORT)
- val url = s"$queryServerHost:$queryServerPort"
- url
- }
-
- override def afterAll(): Unit = {
- super.afterAll()
- container.close()
- }
+ private val postgreSQLDockerImage = "postgres:16.1"
+ override val containerDef: PostgreSQLContainer.Def = PostgreSQLContainer.Def(
+ dockerImageName = DockerImageName.parse(postgreSQLDockerImage),
+ databaseName = "postgres",
+ username = "kyuubi",
+ password = "postgres")
}
diff --git
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/postgresql/WithPostgreSQLEngine.scala
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/postgresql/WithPostgreSQLEngine.scala
index 7bead1998..6d453934e 100644
---
a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/postgresql/WithPostgreSQLEngine.scala
+++
b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/postgresql/WithPostgreSQLEngine.scala
@@ -21,13 +21,15 @@ import org.apache.kyuubi.engine.jdbc.WithJdbcEngine
trait WithPostgreSQLEngine extends WithJdbcEngine with WithPostgreSQLContainer
{
- override def withKyuubiConf: Map[String, String] = Map(
- ENGINE_SHARE_LEVEL.key -> "SERVER",
- ENGINE_JDBC_CONNECTION_URL.key -> s"jdbc:postgresql://$queryUrl/postgres",
- ENGINE_JDBC_CONNECTION_USER.key -> "postgres",
- ENGINE_JDBC_CONNECTION_PASSWORD.key -> "postgres",
- ENGINE_TYPE.key -> "jdbc",
- ENGINE_JDBC_SHORT_NAME.key -> "postgresql",
- ENGINE_JDBC_DRIVER_CLASS.key -> "org.postgresql.Driver")
+ override def withKyuubiConf: Map[String, String] = withContainers {
container =>
+ Map(
+ ENGINE_SHARE_LEVEL.key -> "SERVER",
+ ENGINE_JDBC_CONNECTION_URL.key -> container.jdbcUrl,
+ ENGINE_JDBC_CONNECTION_USER.key -> container.username,
+ ENGINE_JDBC_CONNECTION_PASSWORD.key -> container.password,
+ ENGINE_TYPE.key -> "jdbc",
+ ENGINE_JDBC_SHORT_NAME.key -> "postgresql",
+ ENGINE_JDBC_DRIVER_CLASS.key -> container.driverClassName)
+ }
}
diff --git a/integration-tests/kyuubi-jdbc-it/pom.xml
b/integration-tests/kyuubi-jdbc-it/pom.xml
index 8734c853b..7921d94e2 100644
--- a/integration-tests/kyuubi-jdbc-it/pom.xml
+++ b/integration-tests/kyuubi-jdbc-it/pom.xml
@@ -90,6 +90,12 @@
<artifactId>mysql-connector-j</artifactId>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>com.dimafeng</groupId>
+
<artifactId>testcontainers-scala-postgresql_${scala.binary.version}</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/pom.xml b/pom.xml
index 36af02763..1d7ae4f86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -574,6 +574,12 @@
<version>${testcontainers-scala.version}</version>
</dependency>
+ <dependency>
+ <groupId>com.dimafeng</groupId>
+
<artifactId>testcontainers-scala-postgresql_${scala.binary.version}</artifactId>
+ <version>${testcontainers-scala.version}</version>
+ </dependency>
+
<dependency>
<groupId>com.dimafeng</groupId>
<artifactId>testcontainers-scala-trino_${scala.binary.version}</artifactId>