|
1 | 1 | # InfluxDB Module |
2 | 2 |
|
3 | | -Testcontainers module for InfluxData [InfluxDB](https://github.com/influxdata/influxdb). |
| 3 | +Testcontainers module for InfluxData [InfluxDB](https://www.influxdata.com/products/influxdb/). |
4 | 4 |
|
5 | | -## Usage example |
| 5 | +## Important note |
6 | 6 |
|
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). |
8 | 10 |
|
9 | | -```java |
10 | | -public class SomeTest { |
| 11 | +## InfluxDB 2.x usage example |
11 | 12 |
|
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). |
20 | 85 |
|
21 | 86 | ## Adding this module to your project dependencies |
22 | 87 |
|
23 | 88 | Add the following dependency to your `pom.xml`/`build.gradle` file: |
24 | 89 |
|
25 | 90 | === "Gradle" |
26 | | - ```groovy |
27 | | - testImplementation "org.testcontainers:influxdb:{{latest_version}}" |
28 | | - ``` |
| 91 | + |
| 92 | +```groovy |
| 93 | +testImplementation "org.testcontainers:influxdb:{{latest_version}}" |
| 94 | +``` |
| 95 | + |
29 | 96 | === "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 | +``` |
38 | 107 |
|
39 | 108 | !!! hint |
40 | 109 | 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. |
0 commit comments