Skip to content

Commit

Permalink
Add module for Databend (#9148)
Browse files Browse the repository at this point in the history
  • Loading branch information
hantmac authored Sep 17, 2024
1 parent f2ed9e0 commit bd0b75f
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ body:
- Consul
- Couchbase
- CrateDB
- Databend
- DB2
- Dynalite
- Elasticsearch
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/enhancement.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ body:
- Consul
- Couchbase
- CrateDB
- Databend
- DB2
- Dynalite
- Elasticsearch
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ body:
- CrateDB
- Consul
- Couchbase
- Databend
- DB2
- Dynalite
- Elasticsearch
Expand Down
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ updates:
directory: "/modules/database-commons"
schedule:
interval: "weekly"
- package-ecosystem: "gradle"
directory: "/modules/databend"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
- package-ecosystem: "gradle"
directory: "/modules/db2"
Expand Down
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
- changed-files:
- any-glob-to-any-file:
- modules/cratedb/**/*
"modules/databend":
- changed-files:
- any-glob-to-any-file:
- modules/databend/**/*
"modules/db2":
- changed-files:
- any-glob-to-any-file:
Expand Down
3 changes: 3 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ labels:
- name: modules/yugabytedb
color: '#006b75'

- name: modules/databend
color: '#006b75'

- name: os/linux
color: '#1d76db'

Expand Down
24 changes: 24 additions & 0 deletions docs/modules/databases/databend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Databend Module

## Adding this module to your project dependencies

Add the following dependency to your `pom.xml`/`build.gradle` file:

=== "Gradle"
```groovy
testImplementation "org.testcontainers:databend:{{latest_version}}"
```

=== "Maven"
```xml
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>databend</artifactId>
<version>{{latest_version}}</version>
<scope>test</scope>
</dependency>
```

!!! hint
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.

1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ nav:
- modules/databases/couchbase.md
- modules/databases/clickhouse.md
- modules/databases/cratedb.md
- modules/databases/databend.md
- modules/databases/db2.md
- modules/databases/dynalite.md
- modules/databases/influxdb.md
Expand Down
9 changes: 9 additions & 0 deletions modules/databend/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
description = "Testcontainers :: JDBC :: Databend"

dependencies {
api project(':jdbc')

testImplementation project(':jdbc-test')
testRuntimeOnly 'com.databend:databend-jdbc:0.2.9'
testImplementation 'org.assertj:assertj-core:3.26.3'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.testcontainers.databend;

import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

import java.util.HashSet;
import java.util.Set;

/**
* Testcontainers implementation for Databend.
* <p>
* Supported image: {@code datafuselabs/databend}
* <p>
* Exposed ports:
* <ul>
* <li>Database: 8000</li>
* </ul>
*/
public class DatabendContainer extends JdbcDatabaseContainer<DatabendContainer> {

static final String NAME = "databend";

static final DockerImageName DOCKER_IMAGE_NAME = DockerImageName.parse("datafuselabs/databend");

private static final Integer HTTP_PORT = 8000;

private static final String DRIVER_CLASS_NAME = "com.databend.jdbc.DatabendDriver";

private static final String JDBC_URL_PREFIX = "jdbc:" + NAME + "://";

private static final String TEST_QUERY = "SELECT 1";

private String databaseName = "default";

private String username = "databend";

private String password = "databend";

public DatabendContainer(String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}

public DatabendContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DOCKER_IMAGE_NAME);

addExposedPorts(HTTP_PORT);
waitingFor(Wait.forHttp("/").forResponsePredicate(response -> response.equals("Ok.")));
}

@Override
protected void configure() {
withEnv("QUERY_DEFAULT_USER", this.username);
withEnv("QUERY_DEFAULT_PASSWORD", this.password);
}

@Override
public Set<Integer> getLivenessCheckPortNumbers() {
return new HashSet<>(getMappedPort(HTTP_PORT));
}

@Override
public String getDriverClassName() {
return DRIVER_CLASS_NAME;
}

@Override
public String getJdbcUrl() {
return (
JDBC_URL_PREFIX +
getHost() +
":" +
getMappedPort(HTTP_PORT) +
"/" +
this.databaseName +
constructUrlParameters("?", "&")
);
}

@Override
public String getUsername() {
return this.username;
}

@Override
public String getPassword() {
return this.password;
}

@Override
public String getDatabaseName() {
return this.databaseName;
}

@Override
public String getTestQueryString() {
return TEST_QUERY;
}

@Override
public DatabendContainer withUsername(String username) {
this.username = username;
return this;
}

@Override
public DatabendContainer withPassword(String password) {
this.password = password;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.testcontainers.databend;

import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.JdbcDatabaseContainerProvider;

public class DatabendContainerProvider extends JdbcDatabaseContainerProvider {

private static final String DEFAULT_TAG = "v1.2.615";

@Override
public boolean supports(String databaseType) {
return databaseType.equals(DatabendContainer.NAME);
}

@Override
public JdbcDatabaseContainer newInstance() {
return newInstance(DEFAULT_TAG);
}

@Override
public JdbcDatabaseContainer newInstance(String tag) {
if (tag != null) {
return new DatabendContainer(DatabendContainer.DOCKER_IMAGE_NAME.withTag(tag));
} else {
return newInstance();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.testcontainers.databend.DatabendContainerProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.testcontainers.databend;

import org.junit.Test;
import org.testcontainers.db.AbstractContainerDatabaseTest;

import java.sql.ResultSet;
import java.sql.SQLException;

import static org.assertj.core.api.Assertions.assertThat;

public class DatabendContainerTest extends AbstractContainerDatabaseTest {

@Test
public void testSimple() throws SQLException {
try (DatabendContainer databend = new DatabendContainer("datafuselabs/databend:v1.2.615")) {
databend.start();

ResultSet resultSet = performQuery(databend, "SELECT 1");

int resultSetInt = resultSet.getInt(1);
assertThat(resultSetInt).isEqualTo(1);
}
}

@Test
public void customCredentialsWithUrlParams() throws SQLException {
try (
DatabendContainer databend = new DatabendContainer("datafuselabs/databend:v1.2.615")
.withUsername("test")
.withPassword("test")
.withUrlParam("ssl", "false")
) {
databend.start();

ResultSet resultSet = performQuery(databend, "SELECT 1;");

int resultSetInt = resultSet.getInt(1);
assertThat(resultSetInt).isEqualTo(1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.testcontainers.databend;

import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.testcontainers.jdbc.AbstractJDBCDriverTest;

import java.util.Arrays;
import java.util.EnumSet;

@RunWith(Parameterized.class)
public class DatabendJDBCDriverTest extends AbstractJDBCDriverTest {

@Parameterized.Parameters(name = "{index} - {0}")
public static Iterable<Object[]> data() {
return Arrays.asList(
new Object[][] { //
{ "jdbc:tc:databend://hostname/databasename", EnumSet.of(Options.PmdKnownBroken) },
}
);
}
}
16 changes: 16 additions & 0 deletions modules/databend/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>

<logger name="org.testcontainers" level="INFO"/>
</configuration>

0 comments on commit bd0b75f

Please sign in to comment.