docs/modules/databases/influxdb.md
Testcontainers module for InfluxData InfluxDB.
There are breaking changes in InfluxDB 2.x. For more information refer to the main documentation. You can find more information about the official InfluxDB image on Docker Hub.
Running a InfluxDBContainer as a stand-in for InfluxDB in a test:
Create an InfluxDB container inside_block:constructorWithDefaultVariables
<!--/codeinclude-->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.
It is possible to overwrite the default property values. Create a container with InfluxDB admin token:
<!--codeinclude-->Create an InfluxDB container with admin token inside_block:constructorWithAdminToken
<!--/codeinclude-->Or create a container with custom username, password, bucket, organization, and retention time:
<!--codeinclude-->Create an InfluxDB container with custom settings inside_block:constructorWithCustomVariables
<!--/codeinclude-->The following code snippet shows how you can create an InfluxDB Java client:
<!--codeinclude-->Create an InfluxDB Java client inside_block:createInfluxDBClient
<!--/codeinclude-->!!! hint You can find the latest documentation about the InfluxDB 2.x Java client here.
Running a InfluxDBContainer as a stand-in for InfluxDB in a test with default env variables:
Create an InfluxDB container inside_block:constructorWithDefaultVariables
<!--/codeinclude-->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:
<!--codeinclude-->Create an InfluxDB container with custom settings inside_block:constructorWithUserPassword
<!--/codeinclude-->In the following example you will find a snippet to create an InfluxDB client using the official Java client:
<!--codeinclude-->Create an InfluxDB Java client inside_block:createInfluxDBClient
<!--/codeinclude-->!!! hint You can find the latest documentation about the InfluxDB 1.x Java client here.
Add the following dependency to your pom.xml/build.gradle file:
=== "Gradle"
testImplementation "org.testcontainers:testcontainers-influxdb:{{latest_version}}"
=== "Maven"
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-influxdb</artifactId>
<version>{{latest_version}}</version>
<scope>test</scope>
</dependency>
!!! 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.