forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeaveSwarmCmdExecIT.java
More file actions
45 lines (32 loc) · 1.42 KB
/
Copy pathLeaveSwarmCmdExecIT.java
File metadata and controls
45 lines (32 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.github.dockerjava.cmd.swarm;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.exception.DockerException;
import com.github.dockerjava.api.model.Info;
import com.github.dockerjava.api.model.LocalNodeState;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class LeaveSwarmCmdExecIT extends SwarmCmdIT {
public static final Logger LOG = LoggerFactory.getLogger(LeaveSwarmCmdExecIT.class);
@Test
public void leaveSwarmAsMaster() throws DockerException {
DockerClient dockerClient = startSwarm();
Info info = dockerClient.infoCmd().exec();
LOG.info("Inspected docker: {}", info.toString());
assertThat(info.getSwarm().getLocalNodeState(), is(LocalNodeState.ACTIVE));
dockerClient.leaveSwarmCmd()
.withForceEnabled(true)
.exec();
LOG.info("Left swarm");
info = dockerClient.infoCmd().exec();
LOG.info("Inspected docker: {}", info.toString());
assertThat(info.getSwarm().getLocalNodeState(), is(LocalNodeState.INACTIVE));
}
@Test(expected = DockerException.class)
public void leavingSwarmThrowsWhenNotInSwarm() throws Exception {
DockerClient dockerClient = startDockerInDocker();
dockerClient.leaveSwarmCmd().exec();
}
}