-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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> |