-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(module): support databend #9148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eddumelendez
merged 22 commits into
testcontainers:main
from
hantmac:feat/support-databend
Sep 17, 2024
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
301b6e8
feat: support databend
hantmac ee556a9
update docs
hantmac 6523e36
Merge remote-tracking branch 'container-up/main' into feat/support-da…
hantmac 9e16e8a
fix jdbc dsn
hantmac 7d4d20d
fix comment
hantmac 7340f7a
fix
hantmac d970ddb
use databend stable version docker image
hantmac f4b94c2
fix compile
hantmac d6ca8c9
fix
hantmac 5a1e600
Merge remote-tracking branch 'container-up/main' into feat/support-da…
hantmac 8202f54
fix compile
hantmac 2c2fef9
fix
hantmac df77b48
fix ci complile
hantmac d7811ee
fix tests
hantmac 5cefcb1
fix getJdbcUrl
hantmac eb66ccf
fix compile
hantmac dd718b0
make spotlessApply
hantmac 8bc41de
fix databend build.gradle
hantmac 9a13de0
fix pass tests
hantmac 440f7b4
Polish
eddumelendez 0ab0362
Merge branch 'main' into feat/support-databend
eddumelendez 955b7f9
Remove withDatabaseName
eddumelendez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ body: | |
- Consul | ||
- Couchbase | ||
- CrateDB | ||
- Databend | ||
- DB2 | ||
- Dynalite | ||
- Elasticsearch | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ body: | |
- Consul | ||
- Couchbase | ||
- CrateDB | ||
- Databend | ||
- DB2 | ||
- Dynalite | ||
- Elasticsearch | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ body: | |
- CrateDB | ||
- Consul | ||
- Couchbase | ||
- Databend | ||
- DB2 | ||
- Dynalite | ||
- Elasticsearch | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
112 changes: 112 additions & 0 deletions
112
modules/databend/src/main/java/org/testcontainers/databend/DatabendContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
modules/databend/src/main/java/org/testcontainers/databend/DatabendContainerProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...n/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.testcontainers.databend.DatabendContainerProvider |
41 changes: 41 additions & 0 deletions
41
modules/databend/src/test/java/org/testcontainers/databend/DatabendContainerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
modules/databend/src/test/java/org/testcontainers/databend/DatabendJDBCDriverTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }, | ||
} | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.