Skip to content

Commit bd0b75f

Browse files
authored
Add module for Databend (#9148)
1 parent f2ed9e0 commit bd0b75f

File tree

15 files changed

+267
-0
lines changed

15 files changed

+267
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ body:
2323
- Consul
2424
- Couchbase
2525
- CrateDB
26+
- Databend
2627
- DB2
2728
- Dynalite
2829
- Elasticsearch

.github/ISSUE_TEMPLATE/enhancement.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ body:
2323
- Consul
2424
- Couchbase
2525
- CrateDB
26+
- Databend
2627
- DB2
2728
- Dynalite
2829
- Elasticsearch

.github/ISSUE_TEMPLATE/feature.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ body:
2323
- CrateDB
2424
- Consul
2525
- Couchbase
26+
- Databend
2627
- DB2
2728
- Dynalite
2829
- Elasticsearch

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ updates:
9090
directory: "/modules/database-commons"
9191
schedule:
9292
interval: "weekly"
93+
- package-ecosystem: "gradle"
94+
directory: "/modules/databend"
95+
schedule:
96+
interval: "weekly"
9397
open-pull-requests-limit: 10
9498
- package-ecosystem: "gradle"
9599
directory: "/modules/db2"

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
- changed-files:
5656
- any-glob-to-any-file:
5757
- modules/cratedb/**/*
58+
"modules/databend":
59+
- changed-files:
60+
- any-glob-to-any-file:
61+
- modules/databend/**/*
5862
"modules/db2":
5963
- changed-files:
6064
- any-glob-to-any-file:

.github/settings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ labels:
271271
- name: modules/yugabytedb
272272
color: '#006b75'
273273

274+
- name: modules/databend
275+
color: '#006b75'
276+
274277
- name: os/linux
275278
color: '#1d76db'
276279

docs/modules/databases/databend.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Databend Module
2+
3+
## Adding this module to your project dependencies
4+
5+
Add the following dependency to your `pom.xml`/`build.gradle` file:
6+
7+
=== "Gradle"
8+
```groovy
9+
testImplementation "org.testcontainers:databend:{{latest_version}}"
10+
```
11+
12+
=== "Maven"
13+
```xml
14+
<dependency>
15+
<groupId>org.testcontainers</groupId>
16+
<artifactId>databend</artifactId>
17+
<version>{{latest_version}}</version>
18+
<scope>test</scope>
19+
</dependency>
20+
```
21+
22+
!!! hint
23+
Adding this Testcontainers library JAR will not automatically add a database driver JAR to your project. You should ensure that your project also has a suitable database driver as a dependency.
24+

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ nav:
5656
- modules/databases/couchbase.md
5757
- modules/databases/clickhouse.md
5858
- modules/databases/cratedb.md
59+
- modules/databases/databend.md
5960
- modules/databases/db2.md
6061
- modules/databases/dynalite.md
6162
- modules/databases/influxdb.md

modules/databend/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
description = "Testcontainers :: JDBC :: Databend"
2+
3+
dependencies {
4+
api project(':jdbc')
5+
6+
testImplementation project(':jdbc-test')
7+
testRuntimeOnly 'com.databend:databend-jdbc:0.2.9'
8+
testImplementation 'org.assertj:assertj-core:3.26.3'
9+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package org.testcontainers.databend;
2+
3+
import org.testcontainers.containers.JdbcDatabaseContainer;
4+
import org.testcontainers.containers.wait.strategy.Wait;
5+
import org.testcontainers.utility.DockerImageName;
6+
7+
import java.util.HashSet;
8+
import java.util.Set;
9+
10+
/**
11+
* Testcontainers implementation for Databend.
12+
* <p>
13+
* Supported image: {@code datafuselabs/databend}
14+
* <p>
15+
* Exposed ports:
16+
* <ul>
17+
* <li>Database: 8000</li>
18+
* </ul>
19+
*/
20+
public class DatabendContainer extends JdbcDatabaseContainer<DatabendContainer> {
21+
22+
static final String NAME = "databend";
23+
24+
static final DockerImageName DOCKER_IMAGE_NAME = DockerImageName.parse("datafuselabs/databend");
25+
26+
private static final Integer HTTP_PORT = 8000;
27+
28+
private static final String DRIVER_CLASS_NAME = "com.databend.jdbc.DatabendDriver";
29+
30+
private static final String JDBC_URL_PREFIX = "jdbc:" + NAME + "://";
31+
32+
private static final String TEST_QUERY = "SELECT 1";
33+
34+
private String databaseName = "default";
35+
36+
private String username = "databend";
37+
38+
private String password = "databend";
39+
40+
public DatabendContainer(String dockerImageName) {
41+
this(DockerImageName.parse(dockerImageName));
42+
}
43+
44+
public DatabendContainer(final DockerImageName dockerImageName) {
45+
super(dockerImageName);
46+
dockerImageName.assertCompatibleWith(DOCKER_IMAGE_NAME);
47+
48+
addExposedPorts(HTTP_PORT);
49+
waitingFor(Wait.forHttp("/").forResponsePredicate(response -> response.equals("Ok.")));
50+
}
51+
52+
@Override
53+
protected void configure() {
54+
withEnv("QUERY_DEFAULT_USER", this.username);
55+
withEnv("QUERY_DEFAULT_PASSWORD", this.password);
56+
}
57+
58+
@Override
59+
public Set<Integer> getLivenessCheckPortNumbers() {
60+
return new HashSet<>(getMappedPort(HTTP_PORT));
61+
}
62+
63+
@Override
64+
public String getDriverClassName() {
65+
return DRIVER_CLASS_NAME;
66+
}
67+
68+
@Override
69+
public String getJdbcUrl() {
70+
return (
71+
JDBC_URL_PREFIX +
72+
getHost() +
73+
":" +
74+
getMappedPort(HTTP_PORT) +
75+
"/" +
76+
this.databaseName +
77+
constructUrlParameters("?", "&")
78+
);
79+
}
80+
81+
@Override
82+
public String getUsername() {
83+
return this.username;
84+
}
85+
86+
@Override
87+
public String getPassword() {
88+
return this.password;
89+
}
90+
91+
@Override
92+
public String getDatabaseName() {
93+
return this.databaseName;
94+
}
95+
96+
@Override
97+
public String getTestQueryString() {
98+
return TEST_QUERY;
99+
}
100+
101+
@Override
102+
public DatabendContainer withUsername(String username) {
103+
this.username = username;
104+
return this;
105+
}
106+
107+
@Override
108+
public DatabendContainer withPassword(String password) {
109+
this.password = password;
110+
return this;
111+
}
112+
}

0 commit comments

Comments
 (0)