-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make TimescaleDB available with JDBC syntax #3891
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
07d5d3b
Make TimescaleDB available with JDBC syntax #3890
raynigon 5fcff70
Merge branch 'master' into feature/timescaledb
raynigon ffe2987
Fix Docker Image and JavaDoc
raynigon 0fb5d3c
Fix Docker Image and JavaDoc
raynigon 5bf7660
Fix Test Case form TimescaleDB
raynigon 5fdc4e6
Merge branch 'master' into feature/timescaledb
raynigon cac2e8a
Merge branch 'master' into feature/timescaledb
raynigon 4befc78
Merge branch 'master' into feature/timescaledb
raynigon c3471a7
Merge branch 'master' into feature/timescaledb
raynigon ded632f
Merge branch 'master' into feature/timescaledb
raynigon 27033e9
Merge branch 'master' into feature/timescaledb
raynigon 89ebeec
Merge branch 'master' into feature/timescaledb
raynigon 8d78d74
Merge branch 'master' into feature/timescaledb
raynigon c0693da
Merge branch 'master' into feature/timescaledb
raynigon 9607968
Merge branch 'master' into feature/timescaledb
raynigon 6917145
Merge branch 'master' into feature/timescaledb
raynigon 8506f25
Merge branch 'master' into feature/timescaledb
raynigon 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 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
39 changes: 39 additions & 0 deletions
39
.../postgresql/src/main/java/org/testcontainers/containers/TimescaleDBContainerProvider.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,39 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.testcontainers.jdbc.ConnectionUrl; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
/** | ||
* Factory for TimescaleDB containers, which are a special flavour of PostgreSQL. | ||
* | ||
* @see <a href="https://docs.timescale.com/latest/introduction">https://docs.timescale.com/latest/introduction</a> | ||
*/ | ||
public class TimescaleDBContainerProvider extends JdbcDatabaseContainerProvider { | ||
|
||
private static final String NAME = "timescaledb"; | ||
private static final String DEFAULT_TAG = "2.1.0-pg11"; | ||
private static final DockerImageName DEFAULT_IMAGE = DockerImageName.parse("timescale/timescaledb").asCompatibleSubstituteFor("postgres"); | ||
public static final String USER_PARAM = "user"; | ||
public static final String PASSWORD_PARAM = "password"; | ||
|
||
|
||
@Override | ||
public boolean supports(String databaseType) { | ||
return databaseType.equals(NAME); | ||
} | ||
|
||
@Override | ||
public JdbcDatabaseContainer newInstance() { | ||
return newInstance(DEFAULT_TAG); | ||
} | ||
|
||
@Override | ||
public JdbcDatabaseContainer newInstance(String tag) { | ||
return new PostgreSQLContainer(DEFAULT_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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
org.testcontainers.containers.PostgreSQLContainerProvider | ||
org.testcontainers.containers.PostgisContainerProvider | ||
org.testcontainers.containers.TimescaleDBContainerProvider |
58 changes: 58 additions & 0 deletions
58
modules/postgresql/src/test/java/org/testcontainers/containers/TimescaleDBContainerTest.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,58 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.junit.Test; | ||
import org.testcontainers.db.AbstractContainerDatabaseTest; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals; | ||
import static org.rnorth.visibleassertions.VisibleAssertions.assertNotEquals; | ||
|
||
public class TimescaleDBContainerTest extends AbstractContainerDatabaseTest { | ||
|
||
@Test | ||
public void testSimple() throws SQLException { | ||
try (JdbcDatabaseContainer<?> postgres = new TimescaleDBContainerProvider().newInstance()) { | ||
postgres.start(); | ||
|
||
ResultSet resultSet = performQuery(postgres, "SELECT 1"); | ||
int resultSetInt = resultSet.getInt(1); | ||
assertEquals("A basic SELECT query succeeds", 1, resultSetInt); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCommandOverride() throws SQLException { | ||
try (GenericContainer<?> postgres = new TimescaleDBContainerProvider().newInstance().withCommand("postgres -c max_connections=42")) { | ||
postgres.start(); | ||
|
||
ResultSet resultSet = performQuery((JdbcDatabaseContainer<?>) postgres, "SELECT current_setting('max_connections')"); | ||
String result = resultSet.getString(1); | ||
assertEquals("max_connections should be overriden", "42", result); | ||
} | ||
} | ||
|
||
@Test | ||
public void testUnsetCommand() throws SQLException { | ||
try (GenericContainer<?> postgres = new TimescaleDBContainerProvider().newInstance().withCommand("postgres -c max_connections=42").withCommand()) { | ||
postgres.start(); | ||
|
||
ResultSet resultSet = performQuery((JdbcDatabaseContainer<?>) postgres, "SELECT current_setting('max_connections')"); | ||
String result = resultSet.getString(1); | ||
assertNotEquals("max_connections should not be overriden", "42", result); | ||
} | ||
} | ||
|
||
@Test | ||
public void testExplicitInitScript() throws SQLException { | ||
try (JdbcDatabaseContainer<?> postgres = new TimescaleDBContainerProvider().newInstance().withInitScript("somepath/init_timescaledb.sql")) { | ||
postgres.start(); | ||
|
||
ResultSet resultSet = performQuery(postgres, "SELECT foo FROM bar"); | ||
|
||
String firstColumnValue = resultSet.getString(1); | ||
assertEquals("Value from init script should equal real value", "hello world", firstColumnValue); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...stgresql/src/test/java/org/testcontainers/jdbc/timescaledb/TimescaleDBJDBCDriverTest.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,22 @@ | ||
package org.testcontainers.jdbc.timescaledb; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.testcontainers.jdbc.AbstractJDBCDriverTest; | ||
|
||
import java.util.EnumSet; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
@RunWith(Parameterized.class) | ||
public class TimescaleDBJDBCDriverTest extends AbstractJDBCDriverTest { | ||
|
||
@Parameterized.Parameters(name = "{index} - {0}") | ||
public static Iterable<Object[]> data() { | ||
return asList( | ||
new Object[][]{ | ||
{"jdbc:tc:timescaledb://hostname/databasename?user=someuser&password=somepwd", EnumSet.of(Options.JDBCParams)}, | ||
{"jdbc:tc:timescaledb:2.1.0-pg13://hostname/databasename?user=someuser&password=somepwd", EnumSet.of(Options.JDBCParams)}, | ||
}); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
modules/postgresql/src/test/resources/somepath/init_timescaledb.sql
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 @@ | ||
-- Extend the database with TimescaleDB | ||
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; | ||
|
||
CREATE TABLE bar | ||
( | ||
foo VARCHAR(255), | ||
time TIMESTAMPTZ NOT NULL | ||
); | ||
|
||
SELECT create_hypertable('bar', 'time'); | ||
|
||
INSERT INTO bar (time, foo) | ||
VALUES (CURRENT_TIMESTAMP, 'hello world'); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty ugly and should be made more generic, but that would be a different PR.