-
-
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.
Co-authored-by: Eddú Meléndez <[email protected]>
- Loading branch information
1 parent
a692602
commit b221f3f
Showing
18 changed files
with
326 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 |
---|---|---|
|
@@ -20,6 +20,7 @@ body: | |
- CockroachDB | ||
- Consul | ||
- Couchbase | ||
- CrateDB | ||
- 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 |
---|---|---|
|
@@ -20,6 +20,7 @@ body: | |
- CockroachDB | ||
- Consul | ||
- Couchbase | ||
- CrateDB | ||
- 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 |
---|---|---|
|
@@ -18,6 +18,7 @@ body: | |
- Cassandra | ||
- Clickhouse | ||
- CockroachDB | ||
- CrateDB | ||
- Consul | ||
- Couchbase | ||
- DB2 | ||
|
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,25 @@ | ||
# CrateDB Module | ||
|
||
See [Database containers](./index.md) for documentation and usage that is common to all relational database container types. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Add the following dependency to your `pom.xml`/`build.gradle` file: | ||
|
||
=== "Gradle" | ||
```groovy | ||
testImplementation "org.testcontainers:cratedb:{{latest_version}}" | ||
``` | ||
=== "Maven" | ||
```xml | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>cratedb</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
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,13 @@ | ||
description = "Testcontainers :: JDBC :: CrateDB" | ||
|
||
dependencies { | ||
annotationProcessor 'com.google.auto.service:auto-service:1.0.1' | ||
compileOnly 'com.google.auto.service:auto-service:1.0.1' | ||
|
||
api project(':jdbc') | ||
|
||
testImplementation project(':jdbc-test') | ||
testImplementation 'org.postgresql:postgresql:42.5.4' | ||
|
||
compileOnly 'org.jetbrains:annotations:24.0.0' | ||
} |
116 changes: 116 additions & 0 deletions
116
modules/cratedb/src/main/java/org/testcontainers/cratedb/CrateDBContainer.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,116 @@ | ||
package org.testcontainers.cratedb; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.testcontainers.containers.JdbcDatabaseContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.util.Set; | ||
|
||
public class CrateDBContainer extends JdbcDatabaseContainer<CrateDBContainer> { | ||
|
||
static final String NAME = "cratedb"; | ||
|
||
static final String IMAGE = "crate"; | ||
|
||
static final String DEFAULT_TAG = "5.2.5"; | ||
|
||
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("crate"); | ||
|
||
static final Integer CRATEDB_PG_PORT = 5432; | ||
|
||
static final Integer CRATEDB_HTTP_PORT = 4200; | ||
|
||
private String databaseName = "crate"; | ||
|
||
private String username = "crate"; | ||
|
||
private String password = "crate"; | ||
|
||
public CrateDBContainer(final String dockerImageName) { | ||
this(DockerImageName.parse(dockerImageName)); | ||
} | ||
|
||
public CrateDBContainer(final DockerImageName dockerImageName) { | ||
super(dockerImageName); | ||
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
|
||
this.waitStrategy = Wait.forHttp("/").forPort(CRATEDB_HTTP_PORT).forStatusCode(200); | ||
|
||
addExposedPort(CRATEDB_PG_PORT); | ||
addExposedPort(CRATEDB_HTTP_PORT); | ||
} | ||
|
||
/** | ||
* @return the ports on which to check if the container is ready | ||
* @deprecated use {@link #getLivenessCheckPortNumbers()} instead | ||
*/ | ||
@NotNull | ||
@Override | ||
@Deprecated | ||
protected Set<Integer> getLivenessCheckPorts() { | ||
return super.getLivenessCheckPorts(); | ||
} | ||
|
||
@Override | ||
public String getDriverClassName() { | ||
return "org.postgresql.Driver"; | ||
} | ||
|
||
@Override | ||
public String getJdbcUrl() { | ||
String additionalUrlParams = constructUrlParameters("?", "&"); | ||
return ( | ||
"jdbc:postgresql://" + | ||
getHost() + | ||
":" + | ||
getMappedPort(CRATEDB_PG_PORT) + | ||
"/" + | ||
databaseName + | ||
additionalUrlParams | ||
); | ||
} | ||
|
||
@Override | ||
public String getDatabaseName() { | ||
return databaseName; | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
@Override | ||
public String getTestQueryString() { | ||
return "SELECT 1"; | ||
} | ||
|
||
@Override | ||
public CrateDBContainer withDatabaseName(final String databaseName) { | ||
this.databaseName = databaseName; | ||
return self(); | ||
} | ||
|
||
@Override | ||
public CrateDBContainer withUsername(final String username) { | ||
this.username = username; | ||
return self(); | ||
} | ||
|
||
@Override | ||
public CrateDBContainer withPassword(final String password) { | ||
this.password = password; | ||
return self(); | ||
} | ||
|
||
@Override | ||
protected void waitUntilContainerStarted() { | ||
getWaitStrategy().waitUntilReady(this); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
modules/cratedb/src/main/java/org/testcontainers/cratedb/CrateDBContainerProvider.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,36 @@ | ||
package org.testcontainers.cratedb; | ||
|
||
import org.testcontainers.containers.JdbcDatabaseContainer; | ||
import org.testcontainers.containers.JdbcDatabaseContainerProvider; | ||
import org.testcontainers.jdbc.ConnectionUrl; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
/** | ||
* Factory for CrateDB containers using PostgreSQL JDBC driver. | ||
*/ | ||
public class CrateDBContainerProvider extends JdbcDatabaseContainerProvider { | ||
|
||
public static final String USER_PARAM = "user"; | ||
|
||
public static final String PASSWORD_PARAM = "password"; | ||
|
||
@Override | ||
public boolean supports(String databaseType) { | ||
return databaseType.equals(CrateDBContainer.NAME); | ||
} | ||
|
||
@Override | ||
public JdbcDatabaseContainer newInstance() { | ||
return newInstance(CrateDBContainer.DEFAULT_TAG); | ||
} | ||
|
||
@Override | ||
public JdbcDatabaseContainer newInstance(String tag) { | ||
return new CrateDBContainer(DockerImageName.parse(CrateDBContainer.IMAGE).withTag(tag)); | ||
} | ||
|
||
@Override | ||
public JdbcDatabaseContainer newInstance(ConnectionUrl connectionUrl) { | ||
return newInstanceFromConnectionUrl(connectionUrl, USER_PARAM, PASSWORD_PARAM); | ||
} | ||
} |
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.cratedb.CrateDBContainerProvider |
7 changes: 7 additions & 0 deletions
7
modules/cratedb/src/test/java/org/testcontainers/CrateDBTestImages.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,7 @@ | ||
package org.testcontainers; | ||
|
||
import org.testcontainers.utility.DockerImageName; | ||
|
||
public interface CrateDBTestImages { | ||
DockerImageName CRATEDB_TEST_IMAGE = DockerImageName.parse("crate:5.2.5"); | ||
} |
21 changes: 21 additions & 0 deletions
21
modules/cratedb/src/test/java/org/testcontainers/jdbc/cratedb/CrateDBJDBCDriverTest.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.jdbc.cratedb; | ||
|
||
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 CrateDBJDBCDriverTest extends AbstractJDBCDriverTest { | ||
|
||
@Parameterized.Parameters(name = "{index} - {0}") | ||
public static Iterable<Object[]> data() { | ||
return Arrays.asList( | ||
new Object[][] { | ||
{ "jdbc:tc:cratedb:5.2.3://hostname/crate?user=crate&password=somepwd", EnumSet.noneOf(Options.class) }, | ||
} | ||
); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
modules/cratedb/src/test/java/org/testcontainers/junit/cratedb/SimpleCrateDBTest.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,67 @@ | ||
package org.testcontainers.junit.cratedb; | ||
|
||
import org.junit.Test; | ||
import org.testcontainers.CrateDBTestImages; | ||
import org.testcontainers.cratedb.CrateDBContainer; | ||
import org.testcontainers.db.AbstractContainerDatabaseTest; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.logging.Level; | ||
import java.util.logging.LogManager; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SimpleCrateDBTest extends AbstractContainerDatabaseTest { | ||
static { | ||
// Postgres JDBC driver uses JUL; disable it to avoid annoying, irrelevant, stderr logs during connection testing | ||
LogManager.getLogManager().getLogger("").setLevel(Level.OFF); | ||
} | ||
|
||
@Test | ||
public void testSimple() throws SQLException { | ||
try (CrateDBContainer cratedb = new CrateDBContainer(CrateDBTestImages.CRATEDB_TEST_IMAGE)) { | ||
cratedb.start(); | ||
|
||
ResultSet resultSet = performQuery(cratedb, "SELECT 1"); | ||
int resultSetInt = resultSet.getInt(1); | ||
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1); | ||
assertHasCorrectExposedAndLivenessCheckPorts(cratedb); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCommandOverride() throws SQLException { | ||
try ( | ||
CrateDBContainer cratedb = new CrateDBContainer(CrateDBTestImages.CRATEDB_TEST_IMAGE) | ||
.withCommand("crate -C cluster.name=testcontainers") | ||
) { | ||
cratedb.start(); | ||
|
||
ResultSet resultSet = performQuery(cratedb, "select name from sys.cluster"); | ||
String result = resultSet.getString(1); | ||
assertThat(result).as("cluster name should be overriden").isEqualTo("testcontainers"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testExplicitInitScript() throws SQLException { | ||
try ( | ||
CrateDBContainer cratedb = new CrateDBContainer(CrateDBTestImages.CRATEDB_TEST_IMAGE) | ||
.withInitScript("somepath/init_cratedb.sql") | ||
) { | ||
cratedb.start(); | ||
|
||
ResultSet resultSet = performQuery(cratedb, "SELECT foo FROM bar"); | ||
|
||
String firstColumnValue = resultSet.getString(1); | ||
assertThat(firstColumnValue).as("Value from init script should equal real value").isEqualTo("hello world"); | ||
} | ||
} | ||
|
||
private void assertHasCorrectExposedAndLivenessCheckPorts(CrateDBContainer cratedb) { | ||
assertThat(cratedb.getExposedPorts()).containsExactly(5432, 4200); | ||
assertThat(cratedb.getLivenessCheckPortNumbers()) | ||
.containsExactlyInAnyOrder(cratedb.getMappedPort(5432), cratedb.getMappedPort(4200)); | ||
} | ||
} |
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> |
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,6 @@ | ||
CREATE TABLE bar ( | ||
foo STRING | ||
); | ||
|
||
INSERT INTO bar (foo) VALUES ('hello world'); | ||
REFRESH TABLE bar; |