diff --git a/docs/modules/databases/influxdb.md b/docs/modules/databases/influxdb.md
index 3f5fe0654db..8055f6aed57 100644
--- a/docs/modules/databases/influxdb.md
+++ b/docs/modules/databases/influxdb.md
@@ -1,40 +1,109 @@
# InfluxDB Module
-Testcontainers module for InfluxData [InfluxDB](https://github.com/influxdata/influxdb).
+Testcontainers module for InfluxData [InfluxDB](https://www.influxdata.com/products/influxdb/).
-## Usage example
+## Important note
-Running influxDbContainer as a stand-in for InfluxDB in a test:
+There are breaking changes in InfluxDB 2.x.
+For more information refer to the main [documentation](https://docs.influxdata.com/influxdb/v2.0/upgrade/v1-to-v2/).
+You can find more information about the official InfluxDB image on [Docker Hub](https://hub.docker.com/_/influxdb).
-```java
-public class SomeTest {
+## InfluxDB 2.x usage example
- @Rule
- public InfluxDBContainer influxDbContainer = new InfluxDBContainer();
-
- @Test
- public void someTestMethod() {
- InfluxDB influxDB = influxDbContainer.getNewInfluxDB();
- ...
-```
+Running a `InfluxDBContainer` as a stand-in for InfluxDB in a test:
+
+
+[Create an InfluxDB container](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java) inside_block:constructorWithDefaultVariables
+
+
+
+The InfluxDB instance will be setup with the following data:
+
+| Property | Default Value |
+|--------------|:-------------:|
+| username | test-user |
+| password | test-password |
+| organization | test-org |
+| bucket | test-bucket |
+| retention | 0 (infinite) |
+| adminToken | - |
+
+For more details about the InfluxDB setup, please visit the official [InfluxDB documentation](https://docs.influxdata.com/influxdb/v2.0/upgrade/v1-to-v2/docker/#influxdb-2x-initialization-credentials).
+
+It is possible to overwrite the default property values. Create a container with InfluxDB admin token:
+
+[Create an InfluxDB container with admin token](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java) inside_block:constructorWithAdminToken
+
+
+Or create a container with custom username, password, bucket, organization, and retention time:
+
+[Create an InfluxDB container with custom settings](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java) inside_block:constructorWithCustomVariables
+
+
+The following code snippet shows how you can create an InfluxDB Java client:
+
+
+[Create an InfluxDB Java client](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java) inside_block:createInfluxDBClient
+
+
+!!! hint
+ You can find the latest documentation about the InfluxDB 2.x Java client [here](https://github.com/influxdata/influxdb-client-java).
+
+## InfluxDB 1.x usage example
+
+Running a `InfluxDBContainer` as a stand-in for InfluxDB in a test with default env variables:
+
+
+[Create an InfluxDB container](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java) inside_block:constructorWithDefaultVariables
+
+
+The InfluxDB instance will be setup with the following data:
+
+| Property | Default Value |
+|---------------|:-------------:|
+| username | test-user |
+| password | test-password |
+| authEnabled | true |
+| admin | admin |
+| adminPassword | password |
+| database | - |
+
+It is possible to overwrite the default values.
+For instance, creating an InfluxDB container with a custom username, password, and database name:
+
+[Create an InfluxDB container with custom settings](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java) inside_block:constructorWithUserPassword
+
+
+In the following example you will find a snippet to create an InfluxDB client using the official Java client:
+
+
+[Create an InfluxDB Java client](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java) inside_block:createInfluxDBClient
+
+
+!!! hint
+ You can find the latest documentation about the InfluxDB 1.x Java client [here](https://github.com/influxdata/influxdb-java).
## Adding this module to your project dependencies
Add the following dependency to your `pom.xml`/`build.gradle` file:
=== "Gradle"
- ```groovy
- testImplementation "org.testcontainers:influxdb:{{latest_version}}"
- ```
+
+```groovy
+testImplementation "org.testcontainers:influxdb:{{latest_version}}"
+```
+
=== "Maven"
- ```xml
-
- org.testcontainers
- influxdb
- {{latest_version}}
- test
-
- ```
+
+```xml
+
+
+ org.testcontainers
+ influxdb
+ {{latest_version}}
+ test
+
+```
!!! 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.
diff --git a/modules/influxdb/build.gradle b/modules/influxdb/build.gradle
index 2a75c343653..c412d837d76 100644
--- a/modules/influxdb/build.gradle
+++ b/modules/influxdb/build.gradle
@@ -4,6 +4,8 @@ dependencies {
api project(':testcontainers')
compileOnly 'org.influxdb:influxdb-java:2.23'
- testImplementation 'org.influxdb:influxdb-java:2.23'
+
testImplementation 'org.assertj:assertj-core:3.23.1'
+ testImplementation 'org.influxdb:influxdb-java:2.23'
+ testImplementation "com.influxdb:influxdb-client-java:6.4.0"
}
diff --git a/modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainer.java b/modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainer.java
index 40eea721b57..2af4ed1254d 100644
--- a/modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainer.java
+++ b/modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainer.java
@@ -1,16 +1,18 @@
package org.testcontainers.containers;
+import lombok.Getter;
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
-import org.testcontainers.containers.wait.strategy.Wait;
-import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
+import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
+import org.testcontainers.utility.ComparableVersion;
import org.testcontainers.utility.DockerImageName;
import java.util.Collections;
+import java.util.Optional;
import java.util.Set;
/**
- * See https://store.docker.com/images/influxdb
+ * Testcontainers implementation for InfluxDB.
*/
public class InfluxDBContainer> extends GenericContainer {
@@ -23,17 +25,42 @@ public class InfluxDBContainer> extends Gen
@Deprecated
public static final String VERSION = DEFAULT_TAG;
+ private static final int NO_CONTENT_STATUS_CODE = 204;
+
+ @Getter
+ private String username = "test-user";
+
+ @Getter
+ private String password = "test-password";
+
+ /**
+ * Properties of InfluxDB 1.x
+ */
private boolean authEnabled = true;
private String admin = "admin";
private String adminPassword = "password";
+ @Getter
private String database;
- private String username = "any";
+ /**
+ * Properties of InfluxDB 2.x
+ */
+ @Getter
+ private String bucket = "test-bucket";
+
+ @Getter
+ private String organization = "test-org";
+
+ @Getter
+ private Optional retention = Optional.empty();
- private String password = "any";
+ @Getter
+ private Optional adminToken = Optional.empty();
+
+ private final boolean isAtLeastMajorVersion2;
/**
* @deprecated use {@link InfluxDBContainer(DockerImageName)} instead
@@ -55,24 +82,61 @@ public InfluxDBContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
- waitStrategy =
- new WaitAllStrategy()
- .withStrategy(Wait.forHttp("/ping").withBasicCredentials(username, password).forStatusCode(204))
- .withStrategy(Wait.forListeningPort());
+ this.waitStrategy =
+ new HttpWaitStrategy()
+ .forPath("/ping")
+ .withBasicCredentials(this.username, this.password)
+ .forStatusCode(NO_CONTENT_STATUS_CODE);
+ this.isAtLeastMajorVersion2 =
+ new ComparableVersion(dockerImageName.getVersionPart()).isGreaterThanOrEqualTo("2.0.0");
addExposedPort(INFLUXDB_PORT);
}
+ /**
+ * Sets the InfluxDB environment variables based on the version
+ */
@Override
protected void configure() {
- addEnv("INFLUXDB_ADMIN_USER", admin);
- addEnv("INFLUXDB_ADMIN_PASSWORD", adminPassword);
+ if (this.isAtLeastMajorVersion2) {
+ configureInfluxDBV2();
+ } else {
+ configureInfluxDBV1();
+ }
+ }
- addEnv("INFLUXDB_HTTP_AUTH_ENABLED", String.valueOf(authEnabled));
+ /**
+ * Sets the InfluxDB 2.x environment variables
+ *
+ * @see InfluxDB Dockerhub for full documentation on InfluxDB's
+ * envrinoment variables
+ */
+ private void configureInfluxDBV2() {
+ addEnv("DOCKER_INFLUXDB_INIT_MODE", "setup");
+
+ addEnv("DOCKER_INFLUXDB_INIT_USERNAME", this.username);
+ addEnv("DOCKER_INFLUXDB_INIT_PASSWORD", this.password);
+
+ addEnv("DOCKER_INFLUXDB_INIT_ORG", this.organization);
+ addEnv("DOCKER_INFLUXDB_INIT_BUCKET", this.bucket);
- addEnv("INFLUXDB_DB", database);
- addEnv("INFLUXDB_USER", username);
- addEnv("INFLUXDB_USER_PASSWORD", password);
+ this.retention.ifPresent(ret -> addEnv("DOCKER_INFLUXDB_INIT_RETENTION", ret));
+ this.adminToken.ifPresent(token -> addEnv("DOCKER_INFLUXDB_INIT_ADMIN_TOKEN", token));
+ }
+
+ /**
+ * Sets the InfluxDB 1.x environment variables
+ */
+ private void configureInfluxDBV1() {
+ addEnv("INFLUXDB_USER", this.username);
+ addEnv("INFLUXDB_USER_PASSWORD", this.password);
+
+ addEnv("INFLUXDB_HTTP_AUTH_ENABLED", String.valueOf(this.authEnabled));
+
+ addEnv("INFLUXDB_ADMIN_USER", this.admin);
+ addEnv("INFLUXDB_ADMIN_PASSWORD", this.adminPassword);
+
+ addEnv("INFLUXDB_DB", this.database);
}
@Override
@@ -81,87 +145,131 @@ public Set getLivenessCheckPortNumbers() {
}
/**
- * Set env variable `INFLUXDB_HTTP_AUTH_ENABLED`.
+ * Set user for InfluxDB
+ *
+ * @param username The username to set for the system's initial super-user
+ * @return a reference to this container instance
+ */
+ public InfluxDBContainer withUsername(final String username) {
+ this.username = username;
+ return this;
+ }
+
+ /**
+ * Set password for InfluxDB
+ *
+ * @param password The password to set for the system's initial super-user
+ * @return a reference to this container instance
+ */
+ public InfluxDBContainer withPassword(final String password) {
+ this.password = password;
+ return this;
+ }
+
+ /**
+ * Determines if authentication should be enabled or not
*
* @param authEnabled Enables authentication.
* @return a reference to this container instance
*/
- public SELF withAuthEnabled(final boolean authEnabled) {
+ public InfluxDBContainer withAuthEnabled(final boolean authEnabled) {
this.authEnabled = authEnabled;
- return self();
+ return this.self();
}
/**
- * Set env variable `INFLUXDB_ADMIN_USER`.
+ * Sets the admin user
*
* @param admin The name of the admin user to be created. If this is unset, no admin user is created.
* @return a reference to this container instance
*/
- public SELF withAdmin(final String admin) {
+ public InfluxDBContainer withAdmin(final String admin) {
this.admin = admin;
- return self();
+ return this.self();
}
/**
- * Set env variable `INFLUXDB_ADMIN_PASSWORD`.
+ * Sets the admin password
*
- * @param adminPassword TThe password for the admin user configured with `INFLUXDB_ADMIN_USER`. If this is unset, a
- * random password is generated and printed to standard out.
+ * @param adminPassword The password for the admin user. If this is unset, a random password is generated and
+ * printed to standard out.
* @return a reference to this container instance
*/
- public SELF withAdminPassword(final String adminPassword) {
+ public InfluxDBContainer withAdminPassword(final String adminPassword) {
this.adminPassword = adminPassword;
- return self();
+ return this.self();
}
/**
- * Set env variable `INFLUXDB_DB`.
+ * Initializes database with given name
*
- * @param database Automatically initializes a database with the name of this environment variable.
+ * @param database name of the database.
* @return a reference to this container instance
*/
- public SELF withDatabase(final String database) {
+ public InfluxDBContainer withDatabase(final String database) {
this.database = database;
- return self();
+ return this.self();
}
/**
- * Set env variable `INFLUXDB_USER`.
+ * Sets the organization name
*
- * @param username The name of a user to be created with no privileges. If `INFLUXDB_DB` is set, this user will
- * be granted read and write permissions for that database.
+ * @param organization The organization for the initial setup of influxDB.
* @return a reference to this container instance
*/
- public SELF withUsername(final String username) {
- this.username = username;
- return self();
+ public InfluxDBContainer withOrganization(final String organization) {
+ this.organization = organization;
+ return this;
}
/**
- * Set env variable `INFLUXDB_USER_PASSWORD`.
+ * Initializes bucket with given name
*
- * @param password The password for the user configured with `INFLUXDB_USER`. If this is unset, a random password
- * is generated and printed to standard out.
+ * @param bucket name of the bucket.
* @return a reference to this container instance
*/
- public SELF withPassword(final String password) {
- this.password = password;
- return self();
+ public InfluxDBContainer withBucket(final String bucket) {
+ this.bucket = bucket;
+ return this;
}
/**
- * @return a url to influxDb
+ * Sets the retention in days
+ *
+ * @param retention days bucket will retain data (0 is infinite, default is 0).
+ * @return a reference to this container instance
+ */
+ public InfluxDBContainer withRetention(final String retention) {
+ this.retention = Optional.of(retention);
+ return this;
+ }
+
+ /**
+ * Sets the admin token
+ *
+ * @param adminToken Authentication token to associate with the admin user.
+ * @return a reference to this container instance
+ */
+ public InfluxDBContainer withAdminToken(final String adminToken) {
+ this.adminToken = Optional.of(adminToken);
+ return this;
+ }
+
+ /**
+ * @return a url to InfluxDB
*/
public String getUrl() {
- return "http://" + getHost() + ":" + getLivenessCheckPort();
+ return "http://" + getHost() + ":" + getMappedPort(INFLUXDB_PORT);
}
/**
- * @return a influxDb client
+ * @return a InfluxDB client for InfluxDB 1.x.
+ * @deprecated Use the new InfluxDB client library.
*/
+ @Deprecated
public InfluxDB getNewInfluxDB() {
- InfluxDB influxDB = InfluxDBFactory.connect(getUrl(), username, password);
- influxDB.setDatabase(database);
+ final InfluxDB influxDB = InfluxDBFactory.connect(getUrl(), this.username, this.password);
+ influxDB.setDatabase(this.database);
return influxDB;
}
}
diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java
index bcf3d21f25b..fc80e41ff09 100644
--- a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java
+++ b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java
@@ -1,44 +1,166 @@
package org.testcontainers.containers;
-import org.influxdb.InfluxDB;
-import org.junit.ClassRule;
+import com.influxdb.client.InfluxDBClient;
+import com.influxdb.client.InfluxDBClientFactory;
+import com.influxdb.client.InfluxDBClientOptions;
+import com.influxdb.client.QueryApi;
+import com.influxdb.client.WriteApi;
+import com.influxdb.client.domain.Bucket;
+import com.influxdb.client.domain.BucketRetentionRules;
+import com.influxdb.client.domain.WritePrecision;
+import com.influxdb.client.write.Point;
+import com.influxdb.query.FluxRecord;
+import com.influxdb.query.FluxTable;
+import org.assertj.core.api.Assertions;
import org.junit.Test;
+import org.testcontainers.utility.DockerImageName;
-import static org.assertj.core.api.Assertions.assertThat;
+import java.time.Instant;
+import java.util.List;
+import java.util.Optional;
public class InfluxDBContainerTest {
- @ClassRule
- public static InfluxDBContainer> influxDBContainer = new InfluxDBContainer<>(
- InfluxDBTestImages.INFLUXDB_TEST_IMAGE
- );
+ private static final String USERNAME = "new-test-user";
+
+ private static final String PASSWORD = "new-test-password";
+
+ private static final String ORG = "new-test-org";
+
+ private static final String BUCKET = "new-test-bucket";
+
+ private static final String RETENTION = "1w";
+
+ private static final String ADMIN_TOKEN = "super-secret-token";
+
+ private static final int SECONDS_IN_WEEK = 604800;
@Test
- public void getUrl() {
- String actual = influxDBContainer.getUrl();
+ public void getInfluxDBClient() {
+ try (
+ // constructorWithDefaultVariables {
+ final InfluxDBContainer> influxDBContainer = new InfluxDBContainer<>(
+ DockerImageName.parse("influxdb:2.0.7")
+ )
+ // }
+ ) {
+ influxDBContainer.start();
- assertThat(actual).isNotNull();
+ try (final InfluxDBClient influxDBClient = createClient(influxDBContainer)) {
+ Assertions.assertThat(influxDBClient).isNotNull();
+ Assertions.assertThat(influxDBClient.ping()).isTrue();
+ }
+ }
}
@Test
- public void getNewInfluxDB() {
- InfluxDB actual = influxDBContainer.getNewInfluxDB();
+ public void getInfluxDBClientWithAdminToken() {
+ try (
+ // constructorWithAdminToken {
+ final InfluxDBContainer> influxDBContainer = new InfluxDBContainer<>(
+ DockerImageName.parse("influxdb:2.0.7")
+ )
+ .withAdminToken(ADMIN_TOKEN)
+ // }
+ ) {
+ influxDBContainer.start();
+ final Optional adminToken = influxDBContainer.getAdminToken();
+ Assertions.assertThat(adminToken).isNotEmpty();
- assertThat(actual).isNotNull();
- assertThat(actual.ping()).isNotNull();
+ try (
+ final InfluxDBClient influxDBClient = createClientWithToken(
+ influxDBContainer.getUrl(),
+ adminToken.get()
+ )
+ ) {
+ Assertions.assertThat(influxDBClient).isNotNull();
+ Assertions.assertThat(influxDBClient.ping()).isTrue();
+ }
+ }
}
@Test
- public void getLivenessCheckPort() {
- Integer actual = influxDBContainer.getLivenessCheckPort();
+ public void getBucket() {
+ try (
+ // constructorWithCustomVariables {
+ final InfluxDBContainer> influxDBContainer = new InfluxDBContainer<>(
+ DockerImageName.parse("influxdb:2.0.7")
+ )
+ .withUsername(USERNAME)
+ .withPassword(PASSWORD)
+ .withOrganization(ORG)
+ .withBucket(BUCKET)
+ .withRetention(RETENTION);
+ // }
+ ) {
+ influxDBContainer.start();
- assertThat(actual).isNotNull();
+ try (final InfluxDBClient influxDBClient = createClient(influxDBContainer)) {
+ final Bucket bucket = influxDBClient.getBucketsApi().findBucketByName(BUCKET);
+ Assertions.assertThat(bucket).isNotNull();
+
+ Assertions.assertThat(bucket.getName()).isEqualTo(BUCKET);
+ Assertions
+ .assertThat(bucket.getRetentionRules())
+ .hasSize(1)
+ .first()
+ .extracting(BucketRetentionRules::getEverySeconds)
+ .isEqualTo(SECONDS_IN_WEEK);
+ }
+ }
}
@Test
- public void isRunning() {
- boolean actual = influxDBContainer.isRunning();
+ public void queryForWriteAndRead() {
+ try (
+ final InfluxDBContainer> influxDBContainer = new InfluxDBContainer<>(
+ InfluxDBTestUtils.INFLUXDB_V2_TEST_IMAGE
+ )
+ .withUsername(USERNAME)
+ .withPassword(PASSWORD)
+ .withOrganization(ORG)
+ .withBucket(BUCKET)
+ .withRetention(RETENTION)
+ ) {
+ influxDBContainer.start();
+
+ try (final InfluxDBClient influxDBClient = createClient(influxDBContainer)) {
+ try (final WriteApi writeApi = influxDBClient.makeWriteApi()) {
+ final Point point = Point
+ .measurement("temperature")
+ .addTag("location", "west")
+ .addField("value", 55.0D)
+ .time(Instant.now().toEpochMilli(), WritePrecision.MS);
+
+ writeApi.writePoint(point);
+ }
+
+ final String flux = String.format("from(bucket:\"%s\") |> range(start: 0)", BUCKET);
+
+ final QueryApi queryApi = influxDBClient.getQueryApi();
+
+ final FluxTable fluxTable = queryApi.query(flux).get(0);
+ final List records = fluxTable.getRecords();
+ Assertions.assertThat(records).hasSize(1);
+ }
+ }
+ }
+
+ // createInfluxDBClient {
+ public static InfluxDBClient createClient(final InfluxDBContainer> influxDBContainer) {
+ final InfluxDBClientOptions influxDBClientOptions = InfluxDBClientOptions
+ .builder()
+ .url(influxDBContainer.getUrl())
+ .authenticate(influxDBContainer.getUsername(), influxDBContainer.getPassword().toCharArray())
+ .bucket(influxDBContainer.getBucket())
+ .org(influxDBContainer.getOrganization())
+ .build();
+ return InfluxDBClientFactory.create(influxDBClientOptions);
+ }
+
+ // }
- assertThat(actual).isTrue();
+ public static InfluxDBClient createClientWithToken(final String url, final String token) {
+ return InfluxDBClientFactory.create(url, token.toCharArray());
}
}
diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java
new file mode 100644
index 00000000000..c9e292c5675
--- /dev/null
+++ b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java
@@ -0,0 +1,129 @@
+package org.testcontainers.containers;
+
+import org.influxdb.InfluxDB;
+import org.influxdb.InfluxDBFactory;
+import org.influxdb.dto.Point;
+import org.influxdb.dto.Query;
+import org.influxdb.dto.QueryResult;
+import org.junit.Test;
+import org.testcontainers.utility.DockerImageName;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class InfluxDBContainerV1Test {
+
+ private static final String TEST_VERSION = InfluxDBTestUtils.INFLUXDB_V1_TEST_IMAGE.getVersionPart();
+
+ private static final String DATABASE = "test";
+
+ private static final String USER = "new-test-user";
+
+ private static final String PASSWORD = "new-test-password";
+
+ @Test
+ public void createInfluxDBOnlyWithUrlAndCorrectVersion() {
+ try (
+ // constructorWithDefaultVariables {
+ final InfluxDBContainer> influxDBContainer = new InfluxDBContainer<>(
+ DockerImageName.parse("influxdb:1.4.3")
+ )
+ // }
+ ) {
+ // Start the container. This step might take some time...
+ influxDBContainer.start();
+
+ try (final InfluxDB influxDBClient = createInfluxDBWithUrl(influxDBContainer)) {
+ assertThat(influxDBClient).isNotNull();
+ assertThat(influxDBClient.ping().isGood()).isTrue();
+ assertThat(influxDBClient.version()).isEqualTo(TEST_VERSION);
+ }
+ }
+ }
+
+ @Test
+ public void getNewInfluxDBWithCorrectVersion() {
+ try (
+ final InfluxDBContainer> influxDBContainer = new InfluxDBContainer<>(
+ InfluxDBTestUtils.INFLUXDB_V1_TEST_IMAGE
+ )
+ ) {
+ // Start the container. This step might take some time...
+ influxDBContainer.start();
+
+ try (final InfluxDB influxDBClient = createInfluxDBWithUrl(influxDBContainer)) {
+ assertThat(influxDBClient).isNotNull();
+ assertThat(influxDBClient.ping().isGood()).isTrue();
+ assertThat(influxDBClient.version()).isEqualTo(TEST_VERSION);
+ }
+ }
+ }
+
+ @Test
+ public void describeDatabases() {
+ try (
+ // constructorWithUserPassword {
+ final InfluxDBContainer> influxDBContainer = new InfluxDBContainer<>(
+ DockerImageName.parse("influxdb:1.4.3")
+ )
+ .withDatabase(DATABASE)
+ .withUsername(USER)
+ .withPassword(PASSWORD)
+ // }
+ ) {
+ // Start the container. This step might take some time...
+ influxDBContainer.start();
+
+ try (final InfluxDB influxDBClient = createInfluxDBWithUrl(influxDBContainer)) {
+ assertThat(influxDBClient.describeDatabases()).contains(DATABASE);
+ }
+ }
+ }
+
+ @Test
+ public void queryForWriteAndRead() {
+ try (
+ final InfluxDBContainer> influxDBContainer = new InfluxDBContainer<>(
+ InfluxDBTestUtils.INFLUXDB_V1_TEST_IMAGE
+ )
+ .withDatabase(DATABASE)
+ .withUsername(USER)
+ .withPassword(PASSWORD)
+ ) {
+ // Start the container. This step might take some time...
+ influxDBContainer.start();
+
+ try (final InfluxDB influxDBClient = createInfluxDBWithUrl(influxDBContainer)) {
+ final Point point = Point
+ .measurement("cpu")
+ .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
+ .addField("idle", 90L)
+ .addField("user", 9L)
+ .addField("system", 1L)
+ .build();
+ influxDBClient.write(point);
+
+ final Query query = new Query("SELECT idle FROM cpu", DATABASE);
+ final QueryResult actual = influxDBClient.query(query);
+
+ assertThat(actual).isNotNull();
+ assertThat(actual.getError()).isNull();
+ assertThat(actual.getResults()).isNotNull();
+ assertThat(actual.getResults()).hasSize(1);
+ }
+ }
+ }
+
+ // createInfluxDBClient {
+ public static InfluxDB createInfluxDBWithUrl(final InfluxDBContainer> container) {
+ InfluxDB influxDB = InfluxDBFactory.connect(
+ container.getUrl(),
+ container.getUsername(),
+ container.getPassword()
+ );
+ influxDB.setDatabase(container.getDatabase());
+ return influxDB;
+ }
+ // }
+}
diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerWithUserTest.java b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerWithUserTest.java
deleted file mode 100644
index 7a34bbb4fd6..00000000000
--- a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerWithUserTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package org.testcontainers.containers;
-
-import org.influxdb.InfluxDB;
-import org.influxdb.dto.Point;
-import org.influxdb.dto.Query;
-import org.influxdb.dto.QueryResult;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.util.concurrent.TimeUnit;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class InfluxDBContainerWithUserTest {
-
- private static final String TEST_VERSION = InfluxDBTestImages.INFLUXDB_TEST_IMAGE.getVersionPart();
-
- private static final String DATABASE = "test";
-
- private static final String USER = "test-user";
-
- private static final String PASSWORD = "test-password";
-
- @Rule
- public InfluxDBContainer> influxDBContainer = new InfluxDBContainer<>(InfluxDBTestImages.INFLUXDB_TEST_IMAGE)
- .withDatabase(DATABASE)
- .withUsername(USER)
- .withPassword(PASSWORD);
-
- @Test
- public void describeDatabases() {
- InfluxDB actual = influxDBContainer.getNewInfluxDB();
-
- assertThat(actual).isNotNull();
- assertThat(actual.describeDatabases()).contains(DATABASE);
- }
-
- @Test
- public void checkVersion() {
- InfluxDB actual = influxDBContainer.getNewInfluxDB();
-
- assertThat(actual).isNotNull();
-
- assertThat(actual.ping()).isNotNull();
- assertThat(actual.ping().getVersion()).isEqualTo(TEST_VERSION);
-
- assertThat(actual.version()).isEqualTo(TEST_VERSION);
- }
-
- @Test
- public void queryForWriteAndRead() {
- InfluxDB influxDB = influxDBContainer.getNewInfluxDB();
-
- Point point = Point
- .measurement("cpu")
- .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
- .addField("idle", 90L)
- .addField("user", 9L)
- .addField("system", 1L)
- .build();
- influxDB.write(point);
-
- Query query = new Query("SELECT idle FROM cpu", DATABASE);
- QueryResult actual = influxDB.query(query);
-
- assertThat(actual).isNotNull();
- assertThat(actual.getError()).isNull();
- assertThat(actual.getResults()).isNotNull();
- assertThat(actual.getResults()).hasSize(1);
- }
-}
diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestImages.java b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestImages.java
deleted file mode 100644
index a0e2d31bbdf..00000000000
--- a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestImages.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.testcontainers.containers;
-
-import org.testcontainers.utility.DockerImageName;
-
-public interface InfluxDBTestImages {
- DockerImageName INFLUXDB_TEST_IMAGE = DockerImageName.parse("influxdb:1.4.3");
-}
diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java
new file mode 100644
index 00000000000..db9ae2bf79f
--- /dev/null
+++ b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java
@@ -0,0 +1,10 @@
+package org.testcontainers.containers;
+
+import org.testcontainers.utility.DockerImageName;
+
+public final class InfluxDBTestUtils {
+
+ static final DockerImageName INFLUXDB_V1_TEST_IMAGE = DockerImageName.parse("influxdb:1.4.3");
+
+ static final DockerImageName INFLUXDB_V2_TEST_IMAGE = DockerImageName.parse("influxdb:2.0.7");
+}