Repository navigation
Implement QuestDB Test container module #5995
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 14 commits into
testcontainers:main
from
Vangreen:feautre/implement-questdb-module
Oct 21, 2022
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a100446
Implement QuestDB module
323cb65
Add md file for QuestDB
b1d88ee
Add quest db to required .yaml files
55aa396
Fix wrong md file title
d7ed013
Cleanup QuestDBContainer, add getHttpUrl and return ilp url instead o…
2160463
Add default commit lag env
5ea3f6d
Add more tests for questDB
de78c2e
Add more tests for questDB
4b045e8
Add dependency info to questdb.md
d832648
Use assertj
1c75cab
Cleanup questdb module classes
b892e2f
Remove add commit lag from api
Vangreen 5bf6541
Override waitUntilContainerStarted in QuestDBContainer
Vangreen 86b4d0f
Add authors in QuestDBContainer
Vangreen 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 |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ body: | |
| - PostgreSQL | ||
| - Presto | ||
| - Pulsar | ||
| - QuestDB | ||
| - RabbitMQ | ||
| - Redpanda | ||
| - Selenium | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ body: | |
| - PostgreSQL | ||
| - Presto | ||
| - Pulsar | ||
| - QuestDB | ||
| - RabbitMQ | ||
| - Redpanda | ||
| - Selenium | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ body: | |
| - Oracle-XE | ||
| - OrientDB | ||
| - PostgreSQL | ||
| - QuestDB | ||
| - Presto | ||
| - Pulsar | ||
| - RabbitMQ | ||
|
|
||
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,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 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,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 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,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; | ||
| } | ||
|
kiview marked this conversation as resolved.
|
||
|
|
||
| @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 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,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 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.containers.QuestDBProvider |
7 changes: 7 additions & 0 deletions
7
modules/questdb/src/test/java/org/testcontainers/QuestDBTestImages.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,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 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,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 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,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(); | ||
| } | ||
| } | ||
| } | ||
| } |
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.