From ac59b23e96d8cf5716eb3e0cf4a1d2815ce51b7d Mon Sep 17 00:00:00 2001 From: SBushmelev Date: Sun, 10 Aug 2025 22:15:56 +0400 Subject: [PATCH 1/4] Add Influx db v3 support --- modules/influxdb/build.gradle | 8 + .../containers/InfluxDBContainerV3.java | 172 ++++++++++++++++++ .../containers/InfluxDBContainerV3Test.java | 79 ++++++++ .../containers/InfluxDBTestUtils.java | 2 + 4 files changed, 261 insertions(+) create mode 100644 modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainerV3.java create mode 100644 modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java diff --git a/modules/influxdb/build.gradle b/modules/influxdb/build.gradle index 7a5aa985beb..4f1c7db76bf 100644 --- a/modules/influxdb/build.gradle +++ b/modules/influxdb/build.gradle @@ -8,6 +8,14 @@ dependencies { testImplementation 'org.assertj:assertj-core:3.27.3' testImplementation 'org.influxdb:influxdb-java:2.25' testImplementation "com.influxdb:influxdb-client-java:7.3.0" + testImplementation 'com.influxdb:influxdb3-java:1.2.0' +} + +test { + jvmArgs = [ + "--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED", + "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED" + ] } tasks.japicmp { diff --git a/modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainerV3.java b/modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainerV3.java new file mode 100644 index 00000000000..f00c4366d59 --- /dev/null +++ b/modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainerV3.java @@ -0,0 +1,172 @@ +package org.testcontainers.containers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.HttpResponseException; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.classic.methods.HttpPost; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.HttpClients; +import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.HttpStatus; +import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; +import org.testcontainers.utility.DockerImageName; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.Set; + +import static java.lang.String.format; + +/** + * Testcontainers implementation for InfluxDB 3 (InfluxDB IOx). + *

+ * This container provides a instance of InfluxDB 3.x for integration testing. + * It supports both authenticated and non-authenticated modes. + *

+ * + *

+ * Example usage: + *

{@code
+ * try (InfluxDBContainerV3 influxDB = new InfluxDBContainerV3<>("influxdb:3-core")) {
+ *     influxDB.start();
+ *     String url = influxDB.getUrl();
+ *     String token = influxDB.getToken();
+ *     // Use InfluxDB client with the obtained URL and token
+ * }
+ * }
+ *

+ */ +public class InfluxDBContainerV3> extends GenericContainer { + + /** + * The default port exposed by InfluxDB 3. + */ + public static final Integer INFLUXDB_PORT = 8181; + + private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("influxdb"); + + /** + * The authentication token for InfluxDB 3. Lazily initialized and thread-safe. + */ + private volatile String token; + + /** + * Flag indicating whether authentication is disabled. + */ + private boolean isAuthDisable; + + /** + * Creates a new InfluxDB 3 container using the specified Docker image. + * + * @param dockerImageName the name of the Docker image + */ + public InfluxDBContainerV3(final DockerImageName dockerImageName) { + super(dockerImageName); + dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); + + this.waitStrategy = + new HttpWaitStrategy() + .forPath("/health") + .forStatusCodeMatching(stausCode -> stausCode.equals(200) || stausCode.equals(401)); + + withCommand("influxdb3 serve --node-id local01 --object-store file --data-dir /home/influxdb3/.influxdb3"); + + addExposedPort(INFLUXDB_PORT); + } + + /** + * Creates an admin authentication token by making an HTTP request to the InfluxDB 3 instance. + * + * @return the generated authentication token + * @throws IllegalArgumentException if the token cannot be created due to HTTP or IO errors + * @throws HttpResponseException if the InfluxDB server returns a non-201 status code + */ + private String createToken() { + HttpPost httpPost = new HttpPost(format("%s/api/v3/configure/token/admin", getUrl())); + + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-Type", "application/json"); + + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + return httpClient.execute(httpPost, classicHttpResponse -> { + if (classicHttpResponse.getCode() != HttpStatus.SC_CREATED) { + throw new HttpResponseException( + classicHttpResponse.getCode(), + "Failed to get token" + ); + } + try (InputStream content = classicHttpResponse.getEntity().getContent()) { + return new ObjectMapper().readTree(content).get("token").asText(); + } + }); + } catch (IOException e) { + throw new IllegalArgumentException("Cannot get token", e); + } + } + + /** + * Configures environment variables for the InfluxDB 3 container. + *

+ * This is automatically called by Testcontainers during container startup. + *

+ */ + @Override + protected void configure() { + addEnv("INFLUXDB3_START_WITHOUT_AUTH", Boolean.toString(isAuthDisable)); + } + + /** + * @return a singleton set containing the mapped InfluxDB port + */ + @Override + public Set getLivenessCheckPortNumbers() { + return Collections.singleton(getMappedPort(INFLUXDB_PORT)); + } + + /** + * Disables authentication for this InfluxDB instance. + *

+ * When authentication is disabled, no token is required to access the database. + *

+ * + * @return this container instance for method chaining + */ + public InfluxDBContainerV3 withDisableAuth() { + isAuthDisable = true; + return this; + } + + /** + * Gets the URL for connecting to this InfluxDB instance. + *

+ * The URL includes the host and mapped port (since the actual port may change). + *

+ * + * @return the HTTP URL to access InfluxDB (e.g., "http://localhost:32768") + */ + public String getUrl() { + return "http://" + getHost() + ":" + getMappedPort(INFLUXDB_PORT); + } + + /** + * Gets the authentication token for this InfluxDB instance. + *

+ * The token is lazily initialized on first use and cached for subsequent calls. + * This method is thread-safe. + *

+ * + * @return the authentication token + * @throws IllegalArgumentException if authentication is disabled or token creation fails + */ + public String getToken() { + String localToken = token; + if (localToken == null) { + synchronized (this) { + localToken = token; + if (localToken == null) { + token = localToken = createToken(); + } + } + } + return localToken; + } +} diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java new file mode 100644 index 00000000000..a085182216c --- /dev/null +++ b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java @@ -0,0 +1,79 @@ +package org.testcontainers.containers; + +import com.influxdb.v3.client.InfluxDBClient; +import com.influxdb.v3.client.Point; +import org.junit.Test; + +import java.math.BigInteger; +import java.time.Instant; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.fail; + +public class InfluxDBContainerV3Test { + + @Test + public void createInfluxDBContainerV3WithAuthTokenTest() { + try (InfluxDBContainerV3 container = new InfluxDBContainerV3<>(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE)) { + container.start(); + try (InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), container.getToken().toCharArray(), "test")) { + assertThat(client).isNotNull(); + assertThat(client.getServerVersion()).isEqualTo("3.3.0"); + } catch (Exception e) { + fail("Cannot get instance of influxdb v3", e); + } + } + } + + @Test + public void createInfluxDBContainerV3WithDisableAuthTokenTest() { + try (final InfluxDBContainerV3 container = new InfluxDBContainerV3<>(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE).withDisableAuth()) { + container.start(); + try (InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), null, "test")) { + assertThat(client).isNotNull(); + assertThat(client.getServerVersion()).isEqualTo("3.3.0"); + } catch (Exception e) { + fail("Cannot get instance of influxdb v3", e); + } + } + } + + @Test + public void tryToGetTokenWithAuthDisableTest() { + try (final InfluxDBContainerV3 container = new InfluxDBContainerV3<>(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE).withDisableAuth()) { + container.start(); + assertThatThrownBy(container::getToken).isInstanceOf(IllegalArgumentException.class); + } + } + + @Test + public void writeAndReadResultTest() { + try (InfluxDBContainerV3 container = new InfluxDBContainerV3<>(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE)) { + container.start(); + try (InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), container.getToken().toCharArray(), "test")) { + String location = "west"; + Double value = 55.15; + Point point = Point.measurement("temperature") + .setTag("location", location) + .setField("value", value) + .setTimestamp(Instant.now()); + client.writePoint(point); + String query = "select time,location,value from temperature"; + try (Stream result = client.query(query)) { + List rows = result.collect(Collectors.toList()); + assertThat(rows).hasSize(1); + Object[] row = rows.get(0); + assertThat(row[0]).isNotNull().isInstanceOf(BigInteger.class); + assertThat((String) row[1]).isEqualTo(location); + assertThat((Double) row[2]).isEqualTo(value); + } + } catch (Exception e) { + fail("Cannot write or read data from influxdb v3", e); + } + } + } +} diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java index db9ae2bf79f..e5c19fe949a 100644 --- a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java +++ b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java @@ -7,4 +7,6 @@ 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"); + + static final DockerImageName INFLUXDB_V3_TEST_IMAGE = DockerImageName.parse("influxdb:3-core"); } From fe095081c38e5c372192f6c850cee569fbe1cca7 Mon Sep 17 00:00:00 2001 From: SBushmelev Date: Wed, 13 Aug 2025 19:37:21 +0400 Subject: [PATCH 2/4] Corrected the comments for org.testcontainers.influxdb.InfluxDBContainer --- .../InfluxDBContainer.java} | 65 +++++++------------ .../containers/InfluxDBContainerV3Test.java | 22 +++---- 2 files changed, 33 insertions(+), 54 deletions(-) rename modules/influxdb/src/main/java/org/testcontainers/{containers/InfluxDBContainerV3.java => influxdb/InfluxDBContainer.java} (72%) diff --git a/modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainerV3.java b/modules/influxdb/src/main/java/org/testcontainers/influxdb/InfluxDBContainer.java similarity index 72% rename from modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainerV3.java rename to modules/influxdb/src/main/java/org/testcontainers/influxdb/InfluxDBContainer.java index f00c4366d59..a5d8e79c303 100644 --- a/modules/influxdb/src/main/java/org/testcontainers/containers/InfluxDBContainerV3.java +++ b/modules/influxdb/src/main/java/org/testcontainers/influxdb/InfluxDBContainer.java @@ -1,24 +1,29 @@ -package org.testcontainers.containers; +package org.testcontainers.influxdb; import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dockerjava.api.command.InspectContainerResponse; import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.HttpResponseException; import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.classic.methods.HttpPost; import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.HttpClients; import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.HttpStatus; +import lombok.Getter; +import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; import org.testcontainers.utility.DockerImageName; import java.io.IOException; import java.io.InputStream; -import java.util.Collections; -import java.util.Set; import static java.lang.String.format; /** * Testcontainers implementation for InfluxDB 3 (InfluxDB IOx). *

+ * Supported image: {@code influxdb} + *

+ * Exposed ports: 8181 + *

* This container provides a instance of InfluxDB 3.x for integration testing. * It supports both authenticated and non-authenticated modes. *

@@ -26,7 +31,7 @@ *

* Example usage: *

{@code
- * try (InfluxDBContainerV3 influxDB = new InfluxDBContainerV3<>("influxdb:3-core")) {
+ * try (InfluxDBContainer influxDB = new InfluxDBContainer("influxdb:3-core")) {
  *     influxDB.start();
  *     String url = influxDB.getUrl();
  *     String token = influxDB.getToken();
@@ -35,23 +40,21 @@
  * }
*

*/ -public class InfluxDBContainerV3> extends GenericContainer { +public class InfluxDBContainer extends GenericContainer { /** * The default port exposed by InfluxDB 3. */ - public static final Integer INFLUXDB_PORT = 8181; + private static final Integer INFLUXDB_PORT = 8181; private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("influxdb"); /** - * The authentication token for InfluxDB 3. Lazily initialized and thread-safe. + * The authentication token for InfluxDB 3. */ - private volatile String token; + @Getter + private String token; - /** - * Flag indicating whether authentication is disabled. - */ private boolean isAuthDisable; /** @@ -59,7 +62,7 @@ public class InfluxDBContainerV3> extends * * @param dockerImageName the name of the Docker image */ - public InfluxDBContainerV3(final DockerImageName dockerImageName) { + public InfluxDBContainer(final DockerImageName dockerImageName) { super(dockerImageName); dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); @@ -78,7 +81,7 @@ public InfluxDBContainerV3(final DockerImageName dockerImageName) { * * @return the generated authentication token * @throws IllegalArgumentException if the token cannot be created due to HTTP or IO errors - * @throws HttpResponseException if the InfluxDB server returns a non-201 status code + * @throws HttpResponseException if the InfluxDB server returns a non-201 status code */ private String createToken() { HttpPost httpPost = new HttpPost(format("%s/api/v3/configure/token/admin", getUrl())); @@ -114,14 +117,6 @@ protected void configure() { addEnv("INFLUXDB3_START_WITHOUT_AUTH", Boolean.toString(isAuthDisable)); } - /** - * @return a singleton set containing the mapped InfluxDB port - */ - @Override - public Set getLivenessCheckPortNumbers() { - return Collections.singleton(getMappedPort(INFLUXDB_PORT)); - } - /** * Disables authentication for this InfluxDB instance. *

@@ -130,8 +125,8 @@ public Set getLivenessCheckPortNumbers() { * * @return this container instance for method chaining */ - public InfluxDBContainerV3 withDisableAuth() { - isAuthDisable = true; + public InfluxDBContainer withAuthDisabled() { + this.isAuthDisable = true; return this; } @@ -147,26 +142,10 @@ public String getUrl() { return "http://" + getHost() + ":" + getMappedPort(INFLUXDB_PORT); } - /** - * Gets the authentication token for this InfluxDB instance. - *

- * The token is lazily initialized on first use and cached for subsequent calls. - * This method is thread-safe. - *

- * - * @return the authentication token - * @throws IllegalArgumentException if authentication is disabled or token creation fails - */ - public String getToken() { - String localToken = token; - if (localToken == null) { - synchronized (this) { - localToken = token; - if (localToken == null) { - token = localToken = createToken(); - } - } + @Override + protected void containerIsStarted(InspectContainerResponse containerInfo) { + if (!isAuthDisable) { + this.token = createToken(); } - return localToken; } } diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java index a085182216c..79175fe99b0 100644 --- a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java +++ b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java @@ -3,6 +3,7 @@ import com.influxdb.v3.client.InfluxDBClient; import com.influxdb.v3.client.Point; import org.junit.Test; +import org.testcontainers.influxdb.InfluxDBContainer; import java.math.BigInteger; import java.time.Instant; @@ -11,16 +12,15 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.fail; public class InfluxDBContainerV3Test { @Test public void createInfluxDBContainerV3WithAuthTokenTest() { - try (InfluxDBContainerV3 container = new InfluxDBContainerV3<>(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE)) { + try (final InfluxDBContainer container = new InfluxDBContainer(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE)) { container.start(); - try (InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), container.getToken().toCharArray(), "test")) { + try (final InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), container.getToken().toCharArray(), "test")) { assertThat(client).isNotNull(); assertThat(client.getServerVersion()).isEqualTo("3.3.0"); } catch (Exception e) { @@ -31,9 +31,9 @@ public void createInfluxDBContainerV3WithAuthTokenTest() { @Test public void createInfluxDBContainerV3WithDisableAuthTokenTest() { - try (final InfluxDBContainerV3 container = new InfluxDBContainerV3<>(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE).withDisableAuth()) { + try (final InfluxDBContainer container = new InfluxDBContainer(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE).withAuthDisabled()) { container.start(); - try (InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), null, "test")) { + try (final InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), null, "test")) { assertThat(client).isNotNull(); assertThat(client.getServerVersion()).isEqualTo("3.3.0"); } catch (Exception e) { @@ -43,18 +43,18 @@ public void createInfluxDBContainerV3WithDisableAuthTokenTest() { } @Test - public void tryToGetTokenWithAuthDisableTest() { - try (final InfluxDBContainerV3 container = new InfluxDBContainerV3<>(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE).withDisableAuth()) { + public void getTokenWithAuthDisableTest() { + try (final InfluxDBContainer container = new InfluxDBContainer(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE).withAuthDisabled()) { container.start(); - assertThatThrownBy(container::getToken).isInstanceOf(IllegalArgumentException.class); + assertThat(container.getToken()).isNull(); } } @Test public void writeAndReadResultTest() { - try (InfluxDBContainerV3 container = new InfluxDBContainerV3<>(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE)) { + try (final InfluxDBContainer container = new InfluxDBContainer(InfluxDBTestUtils.INFLUXDB_V3_TEST_IMAGE)) { container.start(); - try (InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), container.getToken().toCharArray(), "test")) { + try (final InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), container.getToken().toCharArray(), "test")) { String location = "west"; Double value = 55.15; Point point = Point.measurement("temperature") @@ -63,7 +63,7 @@ public void writeAndReadResultTest() { .setTimestamp(Instant.now()); client.writePoint(point); String query = "select time,location,value from temperature"; - try (Stream result = client.query(query)) { + try (final Stream result = client.query(query)) { List rows = result.collect(Collectors.toList()); assertThat(rows).hasSize(1); Object[] row = rows.get(0); From 0a5296f646f1fdc78bef4e8400c57c7502b75ecf Mon Sep 17 00:00:00 2001 From: SBushmelev Date: Thu, 14 Aug 2025 20:09:20 +0400 Subject: [PATCH 3/4] Add docs and fix comments --- docs/modules/databases/influxdb.md | 37 ++++++++++++++++++- modules/influxdb/build.gradle | 3 +- .../influxdb/InfluxDBContainer.java | 22 ++--------- .../containers/InfluxDBTestUtils.java | 2 +- .../InfluxDBV3ContainerTest.java} | 6 +-- 5 files changed, 44 insertions(+), 26 deletions(-) rename modules/influxdb/src/test/java/org/testcontainers/{containers/InfluxDBContainerV3Test.java => influxdb/InfluxDBV3ContainerTest.java} (96%) diff --git a/docs/modules/databases/influxdb.md b/docs/modules/databases/influxdb.md index 8055f6aed57..afbf75c4985 100644 --- a/docs/modules/databases/influxdb.md +++ b/docs/modules/databases/influxdb.md @@ -4,10 +4,43 @@ Testcontainers module for InfluxData [InfluxDB](https://www.influxdata.com/produ ## Important note -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/). +There are breaking changes in InfluxDB 2.x. and InfluxDB 3.x. for more information refer to the main documentations: + +InfluxDB 3.x. [documentation](https://www.influxdata.com/blog/influxdb3-open-source-public-alpha/#heading2). + +InfluxDB 2.x. [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). +## InfluxDB 3.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/influxdb/InfluxDBV3ContainerTest.java) inside_block:createInfluxDBContainerV3WithAuthTokenTest + + + +The InfluxDB instance will be setup with the following data:
+ +| Property | Default Value | +|-------------|:-------------:| +| authDisable | false | + +For more details about the InfluxDB setup, please visit the official + +[InfluxDB documentation](https://docs.influxdata.com/influxdb3/core/get-started/) + +[InfluxDB config options](https://docs.influxdata.com/influxdb3/core/reference/config-options/) + +It is possible to overwrite the default property values. Create a container with disabled auth token: + +[Create an InfluxDB container with admin token](../../../modules/influxdb/src/test/java/org/testcontainers/influxdb/InfluxDBV3ContainerTest.java) inside_block:createInfluxDBContainerV3WithDisableAuthTokenTest + + +!!! hint +You can find the latest documentation about the InfluxDB 3.x Java client [here](https://github.com/InfluxCommunity/influxdb3-java). + ## InfluxDB 2.x usage example Running a `InfluxDBContainer` as a stand-in for InfluxDB in a test: diff --git a/modules/influxdb/build.gradle b/modules/influxdb/build.gradle index 4f1c7db76bf..40e44971701 100644 --- a/modules/influxdb/build.gradle +++ b/modules/influxdb/build.gradle @@ -13,8 +13,7 @@ dependencies { test { jvmArgs = [ - "--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED", - "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED" + "--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED" ] } diff --git a/modules/influxdb/src/main/java/org/testcontainers/influxdb/InfluxDBContainer.java b/modules/influxdb/src/main/java/org/testcontainers/influxdb/InfluxDBContainer.java index a5d8e79c303..df646f697ed 100644 --- a/modules/influxdb/src/main/java/org/testcontainers/influxdb/InfluxDBContainer.java +++ b/modules/influxdb/src/main/java/org/testcontainers/influxdb/InfluxDBContainer.java @@ -7,7 +7,6 @@ import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.HttpClients; import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.HttpStatus; -import lombok.Getter; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; import org.testcontainers.utility.DockerImageName; @@ -23,22 +22,6 @@ * Supported image: {@code influxdb} *

* Exposed ports: 8181 - *

- * This container provides a instance of InfluxDB 3.x for integration testing. - * It supports both authenticated and non-authenticated modes. - *

- * - *

- * Example usage: - *

{@code
- * try (InfluxDBContainer influxDB = new InfluxDBContainer("influxdb:3-core")) {
- *     influxDB.start();
- *     String url = influxDB.getUrl();
- *     String token = influxDB.getToken();
- *     // Use InfluxDB client with the obtained URL and token
- * }
- * }
- *

*/ public class InfluxDBContainer extends GenericContainer { @@ -52,7 +35,6 @@ public class InfluxDBContainer extends GenericContainer { /** * The authentication token for InfluxDB 3. */ - @Getter private String token; private boolean isAuthDisable; @@ -148,4 +130,8 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) { this.token = createToken(); } } + + public String getToken() { + return token; + } } diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java index e5c19fe949a..b35c103fd8a 100644 --- a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java +++ b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java @@ -8,5 +8,5 @@ public final class InfluxDBTestUtils { static final DockerImageName INFLUXDB_V2_TEST_IMAGE = DockerImageName.parse("influxdb:2.0.7"); - static final DockerImageName INFLUXDB_V3_TEST_IMAGE = DockerImageName.parse("influxdb:3-core"); + public static final DockerImageName INFLUXDB_V3_TEST_IMAGE = DockerImageName.parse("influxdb:3-core"); } diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java b/modules/influxdb/src/test/java/org/testcontainers/influxdb/InfluxDBV3ContainerTest.java similarity index 96% rename from modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java rename to modules/influxdb/src/test/java/org/testcontainers/influxdb/InfluxDBV3ContainerTest.java index 79175fe99b0..1059e35cd21 100644 --- a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV3Test.java +++ b/modules/influxdb/src/test/java/org/testcontainers/influxdb/InfluxDBV3ContainerTest.java @@ -1,9 +1,9 @@ -package org.testcontainers.containers; +package org.testcontainers.influxdb; import com.influxdb.v3.client.InfluxDBClient; import com.influxdb.v3.client.Point; import org.junit.Test; -import org.testcontainers.influxdb.InfluxDBContainer; +import org.testcontainers.containers.InfluxDBTestUtils; import java.math.BigInteger; import java.time.Instant; @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -public class InfluxDBContainerV3Test { +public class InfluxDBV3ContainerTest { @Test public void createInfluxDBContainerV3WithAuthTokenTest() { From f711917596c5be3f98e1a33e5dacfa3b35aae640 Mon Sep 17 00:00:00 2001 From: SBushmelev Date: Fri, 10 Oct 2025 23:06:50 +0400 Subject: [PATCH 4/4] Change image version, fix tests --- .../org/testcontainers/containers/InfluxDBTestUtils.java | 2 +- .../testcontainers/influxdb/InfluxDBV3ContainerTest.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java index b35c103fd8a..95c1b170736 100644 --- a/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java +++ b/modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBTestUtils.java @@ -8,5 +8,5 @@ public final class InfluxDBTestUtils { static final DockerImageName INFLUXDB_V2_TEST_IMAGE = DockerImageName.parse("influxdb:2.0.7"); - public static final DockerImageName INFLUXDB_V3_TEST_IMAGE = DockerImageName.parse("influxdb:3-core"); + public static final DockerImageName INFLUXDB_V3_TEST_IMAGE = DockerImageName.parse("influxdb:3.5.0-core"); } diff --git a/modules/influxdb/src/test/java/org/testcontainers/influxdb/InfluxDBV3ContainerTest.java b/modules/influxdb/src/test/java/org/testcontainers/influxdb/InfluxDBV3ContainerTest.java index 1059e35cd21..4ab9cb8e66a 100644 --- a/modules/influxdb/src/test/java/org/testcontainers/influxdb/InfluxDBV3ContainerTest.java +++ b/modules/influxdb/src/test/java/org/testcontainers/influxdb/InfluxDBV3ContainerTest.java @@ -2,7 +2,7 @@ import com.influxdb.v3.client.InfluxDBClient; import com.influxdb.v3.client.Point; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.testcontainers.containers.InfluxDBTestUtils; import java.math.BigInteger; @@ -22,7 +22,7 @@ public void createInfluxDBContainerV3WithAuthTokenTest() { container.start(); try (final InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), container.getToken().toCharArray(), "test")) { assertThat(client).isNotNull(); - assertThat(client.getServerVersion()).isEqualTo("3.3.0"); + assertThat(client.getServerVersion()).isEqualTo("3.5.0"); } catch (Exception e) { fail("Cannot get instance of influxdb v3", e); } @@ -35,7 +35,7 @@ public void createInfluxDBContainerV3WithDisableAuthTokenTest() { container.start(); try (final InfluxDBClient client = InfluxDBClient.getInstance(container.getUrl(), null, "test")) { assertThat(client).isNotNull(); - assertThat(client.getServerVersion()).isEqualTo("3.3.0"); + assertThat(client.getServerVersion()).isEqualTo("3.5.0"); } catch (Exception e) { fail("Cannot get instance of influxdb v3", e); }