Skip to content

Commit 6e652b8

Browse files
committed
Update docker-java to 0.10.0 closes influxdata#14
1 parent 99238ac commit 6e652b8

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#### Features
44

5+
- [Issue #14] update docker-java for tests to 0.10.0
56
- Update retrofit from 1.6.0 -> 1.6.1
67
- Use ms instead of m for millisecond timeprecision.
78

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<dependency>
6969
<groupId>com.github.docker-java</groupId>
7070
<artifactId>docker-java</artifactId>
71-
<version>0.8.2</version>
71+
<version>0.10.0</version>
7272
<scope>test</scope>
7373
</dependency>
7474
<dependency>

src/test/java/org/influxdb/InfluxDBTest.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
import org.testng.annotations.BeforeClass;
2121
import org.testng.annotations.Test;
2222

23+
import com.github.dockerjava.api.DockerClient;
24+
import com.github.dockerjava.api.command.CreateContainerResponse;
25+
import com.github.dockerjava.api.command.InspectContainerResponse;
26+
import com.github.dockerjava.api.model.ExposedPort;
27+
import com.github.dockerjava.api.model.Ports;
28+
import com.github.dockerjava.core.DockerClientImpl;
2329
import com.google.common.collect.ImmutableList;
2430
import com.google.common.collect.Lists;
25-
import com.kpelykh.docker.client.DockerClient;
26-
import com.kpelykh.docker.client.DockerException;
27-
import com.kpelykh.docker.client.model.ContainerConfig;
28-
import com.kpelykh.docker.client.model.ContainerCreateResponse;
29-
import com.kpelykh.docker.client.model.HostConfig;
30-
import com.kpelykh.docker.client.model.Ports;
31-
import com.kpelykh.docker.client.model.Ports.Port;
3231

3332
/**
3433
* Test the InfluxDB API.
@@ -41,30 +40,32 @@ public class InfluxDBTest {
4140

4241
private InfluxDB influxDB;
4342
private DockerClient dockerClient;
44-
private ContainerCreateResponse container;
43+
private CreateContainerResponse container;
4544

4645
/**
4746
* Create a influxDB connection before all tests start.
4847
*
49-
* @throws DockerException
5048
* @throws InterruptedException
5149
*/
5250
@BeforeClass
53-
public void setUp() throws DockerException, InterruptedException {
51+
public void setUp() throws InterruptedException {
5452
// Disable logging for the DockerClient.
5553
Logger.getLogger("com.sun.jersey").setLevel(Level.OFF);
56-
this.dockerClient = new DockerClient("http://localhost:4243");
57-
this.dockerClient.pull("majst01/influxdb-java");
58-
59-
ContainerConfig containerConfig = new ContainerConfig();
60-
containerConfig.setImage("majst01/influxdb-java");
61-
this.container = this.dockerClient.createContainer(containerConfig);
62-
HostConfig hostconfig = new HostConfig();
63-
hostconfig.setPortBindings(new Ports());
64-
hostconfig.getPortBindings().addPort(new Port("tcp", "8086", "0.0.0.0", "8086"));
65-
this.dockerClient.startContainer(this.container.getId(), hostconfig);
66-
67-
this.influxDB = InfluxDBFactory.connect("http://localhost:8086", "root", "root");
54+
this.dockerClient = new DockerClientImpl("http://localhost:4243");
55+
this.dockerClient.pullImageCmd("majst01/influxdb-java");
56+
57+
ExposedPort tcp8086 = ExposedPort.tcp(8086);
58+
59+
Ports portBindings = new Ports();
60+
portBindings.bind(tcp8086, Ports.Binding(8086));
61+
this.container = this.dockerClient.createContainerCmd("majst01/influxdb-java").exec();
62+
this.dockerClient.startContainerCmd(this.container.getId()).withPortBindings(portBindings).exec();
63+
64+
InspectContainerResponse inspectContainerResponse = this.dockerClient.inspectContainerCmd(
65+
this.container.getId()).exec();
66+
67+
String ip = inspectContainerResponse.getNetworkSettings().getIpAddress();
68+
this.influxDB = InfluxDBFactory.connect("http://" + ip + ":8086", "root", "root");
6869
boolean influxDBstarted = false;
6970
do {
7071
Pong response;
@@ -86,17 +87,15 @@ public void setUp() throws DockerException, InterruptedException {
8687

8788
/**
8889
* Ensure all Databases created get dropped afterwards.
89-
*
90-
* @throws DockerException
9190
*/
9291
@AfterClass
93-
public void tearDown() throws DockerException {
92+
public void tearDown() {
9493
List<Database> result = this.influxDB.describeDatabases();
9594
for (Database database : result) {
9695
this.influxDB.deleteDatabase(database.getName());
9796
}
9897

99-
this.dockerClient.kill(this.container.getId());
98+
this.dockerClient.killContainerCmd(this.container.getId()).exec();
10099
}
101100

102101
/**

0 commit comments

Comments
 (0)