use of com.spotify.docker.client.messages.swarm.RestartPolicy in project docker-client by spotify.
the class DefaultDockerClientTest method testCreateServiceWithDefaults.
@Test
public void testCreateServiceWithDefaults() throws Exception {
requireDockerApiVersionAtLeast("1.24", "swarm support");
final String serviceName = randomName();
final TaskSpec taskSpec = TaskSpec.builder().containerSpec(ContainerSpec.builder().image("alpine").command(new String[] { "ping", "-c1000", "localhost" }).mounts(Mount.builder().volumeOptions(VolumeOptions.builder().driverConfig(com.spotify.docker.client.messages.mount.Driver.builder().build()).build()).bindOptions(BindOptions.builder().build()).tmpfsOptions(TmpfsOptions.builder().build()).build()).build()).resources(ResourceRequirements.builder().build()).restartPolicy(RestartPolicy.builder().build()).placement(Placement.create(null)).networks(NetworkAttachmentConfig.builder().build()).logDriver(Driver.builder().build()).build();
final ServiceMode serviceMode = ServiceMode.builder().replicated(ReplicatedService.builder().build()).build();
final ServiceSpec serviceSpec = ServiceSpec.builder().name(serviceName).taskTemplate(taskSpec).mode(serviceMode).updateConfig(UpdateConfig.create(null, null, null)).networks(Collections.<NetworkAttachmentConfig>emptyList()).endpointSpec(EndpointSpec.builder().addPort(PortConfig.builder().build()).build()).build();
final ServiceCreateResponse response = sut.createService(serviceSpec);
assertThat(response.id(), is(notNullValue()));
sut.listTasks();
final Service service = sut.inspectService(serviceName);
final ServiceSpec actualServiceSpec = service.spec();
assertThat(actualServiceSpec.mode().replicated().replicas(), equalTo(1L));
assertThat(actualServiceSpec.taskTemplate().logDriver().options(), equalTo(Collections.<String, String>emptyMap()));
assertThat(actualServiceSpec.endpointSpec().mode(), equalTo(EndpointSpec.Mode.RESOLUTION_MODE_VIP));
assertThat(actualServiceSpec.updateConfig().failureAction(), equalTo("pause"));
final PortConfig.Builder portConfigBuilder = PortConfig.builder().protocol(PROTOCOL_TCP);
if (dockerApiVersionAtLeast("1.25")) {
// Ingress publish mode is the default for ports in API versions >= 1.25
portConfigBuilder.publishMode(PortConfigPublishMode.INGRESS);
}
final PortConfig expectedPortConfig = portConfigBuilder.build();
assertThat(actualServiceSpec.endpointSpec().ports(), contains(expectedPortConfig));
assertThat(service.endpoint().spec().ports(), contains(expectedPortConfig));
final ContainerSpec containerSpec = actualServiceSpec.taskTemplate().containerSpec();
assertThat(containerSpec.labels(), equalTo(Collections.<String, String>emptyMap()));
assertThat(containerSpec.mounts().size(), equalTo(1));
final Mount mount = containerSpec.mounts().get(0);
assertThat(mount.type(), equalTo("bind"));
final VolumeOptions volumeOptions = mount.volumeOptions();
assertThat(volumeOptions.noCopy(), nullValue());
assertThat(volumeOptions.labels(), nullValue());
final com.spotify.docker.client.messages.mount.Driver driver = volumeOptions.driverConfig();
assertThat(driver.name(), nullValue());
assertThat(driver.options(), nullValue());
final RestartPolicy restartPolicy = actualServiceSpec.taskTemplate().restartPolicy();
assertThat(restartPolicy.condition(), equalTo(RESTART_POLICY_ANY));
assertThat(restartPolicy.maxAttempts(), equalTo(0));
}
Aggregations