forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveSwarmNodeCmdExecIT.java
More file actions
44 lines (36 loc) · 1.64 KB
/
Copy pathRemoveSwarmNodeCmdExecIT.java
File metadata and controls
44 lines (36 loc) · 1.64 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
package com.github.dockerjava.cmd.swarm;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.model.Swarm;
import com.github.dockerjava.api.model.SwarmNode;
import com.github.dockerjava.api.model.SwarmNodeRole;
import com.google.common.collect.Lists;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class RemoveSwarmNodeCmdExecIT extends SwarmCmdIT {
private static final Logger LOGGER = LoggerFactory.getLogger(RemoveSwarmNodeCmdExecIT.class);
@Test
public void testRemoveSwarmNode() throws Exception {
DockerClient dockerClient = startSwarm();
Swarm swarm = dockerClient.inspectSwarmCmd().exec();
DockerClient docker2 = startDockerInDocker();
docker2.joinSwarmCmd()
.withRemoteAddrs(Lists.newArrayList("docker1"))
.withJoinToken(swarm.getJoinTokens().getWorker())
.exec();
LOGGER.info("docker2 joined docker's swarm");
List<SwarmNode> nodes = dockerClient.listSwarmNodesCmd().exec();
assertThat(2, is(nodes.size()));
Optional<SwarmNode> firstWorkNode = nodes.stream().filter(node -> node.getSpec().getRole() == SwarmNodeRole.WORKER)
.findFirst();
dockerClient.removeSwarmNodeCmd(firstWorkNode.get().getId())
.withForce(true)
.exec();
nodes = dockerClient.listSwarmNodesCmd().exec();
assertThat(nodes.size(), is(1));
}
}