Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Testcontainers implementation for `QuestDB`, `QuestDBContainer`.
- Loading branch information
Showing
14 changed files
with
253 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 |
---|---|---|
|
@@ -41,6 +41,7 @@ body: | |
- PostgreSQL | ||
- Presto | ||
- Pulsar | ||
- QuestDB | ||
- RabbitMQ | ||
- Redpanda | ||
- Selenium | ||
|
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 |
---|---|---|
|
@@ -41,6 +41,7 @@ body: | |
- PostgreSQL | ||
- Presto | ||
- Pulsar | ||
- QuestDB | ||
- RabbitMQ | ||
- Redpanda | ||
- Selenium | ||
|
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 |
---|---|---|
|
@@ -39,6 +39,7 @@ body: | |
- Oracle-XE | ||
- OrientDB | ||
- PostgreSQL | ||
- QuestDB | ||
- Presto | ||
- Pulsar | ||
- RabbitMQ | ||
|
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,29 @@ | ||
# QuestDB Module | ||
|
||
Testcontainers module for [QuestDB](https://github.com/questdb/questdb). QuestDB is a high-performance, open-source SQL | ||
database for applications in financial services, IoT, machine learning, DevOps and observability. | ||
|
||
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:questdb:{{latest_version}}" | ||
``` | ||
|
||
=== "Maven" | ||
|
||
```xml | ||
|
||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>questdb</artifactId> | ||
<version>{{latest_version}}</version> | ||
<scope>test</scope> | ||
</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,13 @@ | ||
description = "Testcontainers :: QuestDB" | ||
|
||
dependencies { | ||
api project(':testcontainers') | ||
api project(':jdbc') | ||
|
||
testImplementation 'org.postgresql:postgresql:42.5.0' | ||
testImplementation project(':jdbc-test') | ||
testImplementation 'org.assertj:assertj-core:3.23.1' | ||
testImplementation 'org.questdb:questdb:6.4.3-jdk8' | ||
testImplementation 'org.awaitility:awaitility:4.2.0' | ||
testImplementation 'org.apache.httpcomponents:httpclient:4.5.13' | ||
} |
88 changes: 88 additions & 0 deletions
88
modules/questdb/src/main/java/org/testcontainers/containers/QuestDBContainer.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,88 @@ | ||
package org.testcontainers.containers; | ||
|
||
import lombok.NonNull; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
/** | ||
* Testcontainers implementation for QuestDB. | ||
* | ||
* @author vangreen | ||
* @author jerrinot | ||
*/ | ||
public class QuestDBContainer extends JdbcDatabaseContainer<QuestDBContainer> { | ||
|
||
static final String DATABASE_PROVIDER = "postgresql"; | ||
|
||
private static final String DEFAULT_DATABASE_NAME = "qdb"; | ||
|
||
private static final int DEFAULT_COMMIT_LAG_MS = 1000; | ||
|
||
private static final String DEFAULT_USERNAME = "admin"; | ||
|
||
private static final String DEFAULT_PASSWORD = "quest"; | ||
|
||
private static final Integer POSTGRES_PORT = 8812; | ||
|
||
private static final Integer REST_PORT = 9000; | ||
|
||
private static final Integer ILP_PORT = 9009; | ||
|
||
static final String TEST_QUERY = "SELECT 1"; | ||
|
||
static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("questdb/questdb"); | ||
|
||
public QuestDBContainer(@NonNull String dockerImageName) { | ||
this(DockerImageName.parse(dockerImageName)); | ||
} | ||
|
||
public QuestDBContainer(DockerImageName dockerImageName) { | ||
super(dockerImageName); | ||
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
withExposedPorts(POSTGRES_PORT, REST_PORT, ILP_PORT); | ||
addEnv("QDB_CAIRO_COMMIT_LAG", String.valueOf(DEFAULT_COMMIT_LAG_MS)); | ||
waitingFor(Wait.forLogMessage("(?i).*A server-main enjoy.*", 1)); | ||
} | ||
|
||
@Override | ||
public String getDriverClassName() { | ||
return "org.postgresql.Driver"; | ||
} | ||
|
||
@Override | ||
public String getJdbcUrl() { | ||
return String.format("jdbc:postgresql://%s:%d/%s", getHost(), getMappedPort(8812), getDefaultDatabaseName()); | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return DEFAULT_USERNAME; | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return DEFAULT_PASSWORD; | ||
} | ||
|
||
@Override | ||
public String getTestQueryString() { | ||
return TEST_QUERY; | ||
} | ||
|
||
@Override | ||
protected void waitUntilContainerStarted() { | ||
getWaitStrategy().waitUntilReady(this); | ||
} | ||
|
||
public String getDefaultDatabaseName() { | ||
return DEFAULT_DATABASE_NAME; | ||
} | ||
|
||
public String getIlpUrl() { | ||
return getHost() + ":" + getMappedPort(ILP_PORT); | ||
} | ||
|
||
public String getHttpUrl() { | ||
return "http://" + getHost() + ":" + getMappedPort(REST_PORT); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
modules/questdb/src/main/java/org/testcontainers/containers/QuestDBProvider.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,14 @@ | ||
package org.testcontainers.containers; | ||
|
||
public class QuestDBProvider extends JdbcDatabaseContainerProvider { | ||
|
||
@Override | ||
public boolean supports(String databaseType) { | ||
return databaseType.equals(QuestDBContainer.DATABASE_PROVIDER); | ||
} | ||
|
||
@Override | ||
public JdbcDatabaseContainer newInstance(String tag) { | ||
return new QuestDBContainer(QuestDBContainer.DEFAULT_IMAGE_NAME.withTag(tag)); | ||
} | ||
} |
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.containers.QuestDBProvider |
7 changes: 7 additions & 0 deletions
7
modules/questdb/src/test/java/org/testcontainers/QuestDBTestImages.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 QuestDBTestImages { | ||
DockerImageName QUESTDB_IMAGE = DockerImageName.parse("questdb/questdb:6.5.3"); | ||
} |
19 changes: 19 additions & 0 deletions
19
modules/questdb/src/test/java/org/testcontainers/jdbc/questdb/QuestDBJDBCDriverTest.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,19 @@ | ||
package org.testcontainers.jdbc.questdb; | ||
|
||
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 QuestDBJDBCDriverTest extends AbstractJDBCDriverTest { | ||
|
||
@Parameterized.Parameters(name = "{index} - {0}") | ||
public static Iterable<Object[]> data() { | ||
return Arrays.asList( | ||
new Object[][] { { "jdbc:tc:postgresql://hostname/databasename", EnumSet.of(Options.PmdKnownBroken) } } | ||
); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
modules/questdb/src/test/java/org/testcontainers/junit/questdb/SimpleQuestDBTest.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,71 @@ | ||
package org.testcontainers.junit.questdb; | ||
|
||
import io.questdb.client.Sender; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.util.EntityUtils; | ||
import org.junit.Test; | ||
import org.testcontainers.QuestDBTestImages; | ||
import org.testcontainers.containers.QuestDBContainer; | ||
import org.testcontainers.db.AbstractContainerDatabaseTest; | ||
|
||
import java.io.IOException; | ||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
public class SimpleQuestDBTest extends AbstractContainerDatabaseTest { | ||
|
||
private static final String TABLE_NAME = "mytable"; | ||
|
||
@Test | ||
public void testSimple() throws SQLException { | ||
try (QuestDBContainer questDB = new QuestDBContainer(QuestDBTestImages.QUESTDB_IMAGE)) { | ||
questDB.start(); | ||
|
||
ResultSet resultSet = performQuery(questDB, questDB.getTestQueryString()); | ||
|
||
int resultSetInt = resultSet.getInt(1); | ||
assertThat(resultSetInt).as("A basic SELECT query succeeds").isEqualTo(1); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRest() throws IOException { | ||
try (QuestDBContainer questdb = new QuestDBContainer(QuestDBTestImages.QUESTDB_IMAGE)) { | ||
questdb.start(); | ||
populateByInfluxLineProtocol(questdb, 1_000); | ||
try (CloseableHttpClient client = HttpClientBuilder.create().build()) { | ||
String encodedSql = URLEncoder.encode("select * from " + TABLE_NAME, "UTF-8"); | ||
HttpGet httpGet = new HttpGet(questdb.getHttpUrl() + "/exec?query=" + encodedSql); | ||
await() | ||
.untilAsserted(() -> { | ||
try (CloseableHttpResponse response = client.execute(httpGet)) { | ||
assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); | ||
String json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); | ||
assertThat(json.contains("\"count\":1000")).isTrue(); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
private static void populateByInfluxLineProtocol(QuestDBContainer questdb, int rowCount) { | ||
try (Sender sender = Sender.builder().address(questdb.getIlpUrl()).build()) { | ||
for (int i = 0; i < rowCount; i++) { | ||
sender | ||
.table(TABLE_NAME) | ||
.symbol("sym", "sym1" + i) | ||
.stringColumn("str", "str1" + i) | ||
.longColumn("long", i) | ||
.atNow(); | ||
} | ||
} | ||
} | ||
} |