Skip to content

Commit e3ec7d4

Browse files
raminqafrnorthbsideupeddumelendez
authored
Add InfluxDB v2 support (#3669)
Co-authored-by: Richard North <[email protected]> Co-authored-by: Sergei Egorov <[email protected]> Co-authored-by: Eddú Meléndez Gonzales <[email protected]>
1 parent 3280fda commit e3ec7d4

File tree

8 files changed

+532
-170
lines changed

8 files changed

+532
-170
lines changed

docs/modules/databases/influxdb.md

Lines changed: 93 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,109 @@
11
# InfluxDB Module
22

3-
Testcontainers module for InfluxData [InfluxDB](https://github.com/influxdata/influxdb).
3+
Testcontainers module for InfluxData [InfluxDB](https://www.influxdata.com/products/influxdb/).
44

5-
## Usage example
5+
## Important note
66

7-
Running influxDbContainer as a stand-in for InfluxDB in a test:
7+
There are breaking changes in InfluxDB 2.x.
8+
For more information refer to the main [documentation](https://docs.influxdata.com/influxdb/v2.0/upgrade/v1-to-v2/).
9+
You can find more information about the official InfluxDB image on [Docker Hub](https://hub.docker.com/_/influxdb).
810

9-
```java
10-
public class SomeTest {
11+
## InfluxDB 2.x usage example
1112

12-
@Rule
13-
public InfluxDBContainer influxDbContainer = new InfluxDBContainer();
14-
15-
@Test
16-
public void someTestMethod() {
17-
InfluxDB influxDB = influxDbContainer.getNewInfluxDB();
18-
...
19-
```
13+
Running a `InfluxDBContainer` as a stand-in for InfluxDB in a test:
14+
15+
<!--codeinclude-->
16+
[Create an InfluxDB container](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java) inside_block:constructorWithDefaultVariables
17+
<!--/codeinclude-->
18+
19+
20+
The InfluxDB instance will be setup with the following data:<br/>
21+
22+
| Property | Default Value |
23+
|--------------|:-------------:|
24+
| username | test-user |
25+
| password | test-password |
26+
| organization | test-org |
27+
| bucket | test-bucket |
28+
| retention | 0 (infinite) |
29+
| adminToken | - |
30+
31+
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).
32+
33+
It is possible to overwrite the default property values. Create a container with InfluxDB admin token:
34+
<!--codeinclude-->
35+
[Create an InfluxDB container with admin token](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java) inside_block:constructorWithAdminToken
36+
<!--/codeinclude-->
37+
38+
Or create a container with custom username, password, bucket, organization, and retention time:
39+
<!--codeinclude-->
40+
[Create an InfluxDB container with custom settings](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java) inside_block:constructorWithCustomVariables
41+
<!--/codeinclude-->
42+
43+
The following code snippet shows how you can create an InfluxDB Java client:
44+
45+
<!--codeinclude-->
46+
[Create an InfluxDB Java client](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerTest.java) inside_block:createInfluxDBClient
47+
<!--/codeinclude-->
48+
49+
!!! hint
50+
You can find the latest documentation about the InfluxDB 2.x Java client [here](https://github.com/influxdata/influxdb-client-java).
51+
52+
## InfluxDB 1.x usage example
53+
54+
Running a `InfluxDBContainer` as a stand-in for InfluxDB in a test with default env variables:
55+
56+
<!--codeinclude-->
57+
[Create an InfluxDB container](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java) inside_block:constructorWithDefaultVariables
58+
<!--/codeinclude-->
59+
60+
The InfluxDB instance will be setup with the following data:<br/>
61+
62+
| Property | Default Value |
63+
|---------------|:-------------:|
64+
| username | test-user |
65+
| password | test-password |
66+
| authEnabled | true |
67+
| admin | admin |
68+
| adminPassword | password |
69+
| database | - |
70+
71+
It is possible to overwrite the default values.
72+
For instance, creating an InfluxDB container with a custom username, password, and database name:
73+
<!--codeinclude-->
74+
[Create an InfluxDB container with custom settings](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java) inside_block:constructorWithUserPassword
75+
<!--/codeinclude-->
76+
77+
In the following example you will find a snippet to create an InfluxDB client using the official Java client:
78+
79+
<!--codeinclude-->
80+
[Create an InfluxDB Java client](../../../modules/influxdb/src/test/java/org/testcontainers/containers/InfluxDBContainerV1Test.java) inside_block:createInfluxDBClient
81+
<!--/codeinclude-->
82+
83+
!!! hint
84+
You can find the latest documentation about the InfluxDB 1.x Java client [here](https://github.com/influxdata/influxdb-java).
2085

2186
## Adding this module to your project dependencies
2287

2388
Add the following dependency to your `pom.xml`/`build.gradle` file:
2489

2590
=== "Gradle"
26-
```groovy
27-
testImplementation "org.testcontainers:influxdb:{{latest_version}}"
28-
```
91+
92+
```groovy
93+
testImplementation "org.testcontainers:influxdb:{{latest_version}}"
94+
```
95+
2996
=== "Maven"
30-
```xml
31-
<dependency>
32-
<groupId>org.testcontainers</groupId>
33-
<artifactId>influxdb</artifactId>
34-
<version>{{latest_version}}</version>
35-
<scope>test</scope>
36-
</dependency>
37-
```
97+
98+
```xml
99+
100+
<dependency>
101+
<groupId>org.testcontainers</groupId>
102+
<artifactId>influxdb</artifactId>
103+
<version>{{latest_version}}</version>
104+
<scope>test</scope>
105+
</dependency>
106+
```
38107

39108
!!! hint
40109
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.

modules/influxdb/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ dependencies {
44
api project(':testcontainers')
55

66
compileOnly 'org.influxdb:influxdb-java:2.23'
7-
testImplementation 'org.influxdb:influxdb-java:2.23'
7+
88
testImplementation 'org.assertj:assertj-core:3.23.1'
9+
testImplementation 'org.influxdb:influxdb-java:2.23'
10+
testImplementation "com.influxdb:influxdb-client-java:6.4.0"
911
}

0 commit comments

Comments
 (0)