Search in sources :

Example 1 with PortBindingException

use of io.fabric8.maven.docker.model.PortBindingException in project docker-maven-plugin by fabric8io.

the class RunServiceTest method failAfterRetryingIfInsufficientPortBindingInformation.

@Test(expected = PortBindingException.class)
public void failAfterRetryingIfInsufficientPortBindingInformation(@Mocked Container container, @Mocked ImageConfiguration imageConfiguration, @Mocked PortMapping portMapping) throws DockerAccessException {
    new Expectations() {

        {
            docker.createContainer(withAny(new ContainerCreateConfig("img")), anyString);
            result = "containerId";
            portMapping.needsPropertiesUpdate();
            result = true;
            queryService.getMandatoryContainer("containerId");
            result = container;
            times = 20;
            container.isRunning();
            result = true;
            container.getPortBindings();
            result = new PortBindingException("5432/tcp", new Gson().fromJson("{\"5432/tcp\": []}", JsonObject.class));
        }
    };
    runService.createAndStartContainer(imageConfiguration, portMapping, new GavLabel("Im:A:Test"), properties, getBaseDirectory(), "blah", new Date());
}
Also used : Expectations(mockit.Expectations) GavLabel(io.fabric8.maven.docker.util.GavLabel) ContainerCreateConfig(io.fabric8.maven.docker.access.ContainerCreateConfig) Gson(com.google.gson.Gson) PortBindingException(io.fabric8.maven.docker.model.PortBindingException) Date(java.util.Date) Test(org.junit.Test)

Example 2 with PortBindingException

use of io.fabric8.maven.docker.model.PortBindingException in project docker-maven-plugin by fabric8io.

the class RunServiceTest method retryIfInsufficientPortBindingInformation.

@Test
public void retryIfInsufficientPortBindingInformation(@Mocked Container container, @Mocked ImageConfiguration imageConfiguration, @Mocked PortMapping portMapping) throws DockerAccessException {
    new Expectations() {

        {
            docker.createContainer(withAny(new ContainerCreateConfig("img")), anyString);
            result = "containerId";
            portMapping.needsPropertiesUpdate();
            result = true;
            queryService.getMandatoryContainer("containerId");
            result = container;
            times = 2;
            container.isRunning();
            result = true;
            container.getPortBindings();
            result = new PortBindingException("5432/tcp", new Gson().fromJson("{\"5432/tcp\": []}", JsonObject.class));
            returns(ImmutableMap.of("5432/tcp", new Container.PortBinding(56741, "0.0.0.0")), ImmutableMap.of("5432/tcp", new Container.PortBinding(56741, "0.0.0.0")));
        }
    };
    String containerId = runService.createAndStartContainer(imageConfiguration, portMapping, new GavLabel("Im:A:Test"), properties, getBaseDirectory(), "blah", new Date());
    new Verifications() {

        {
            assertEquals("containerId", containerId);
        }
    };
}
Also used : Expectations(mockit.Expectations) GavLabel(io.fabric8.maven.docker.util.GavLabel) ContainerCreateConfig(io.fabric8.maven.docker.access.ContainerCreateConfig) Gson(com.google.gson.Gson) PortBindingException(io.fabric8.maven.docker.model.PortBindingException) Verifications(mockit.Verifications) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)2 ContainerCreateConfig (io.fabric8.maven.docker.access.ContainerCreateConfig)2 PortBindingException (io.fabric8.maven.docker.model.PortBindingException)2 GavLabel (io.fabric8.maven.docker.util.GavLabel)2 Date (java.util.Date)2 Expectations (mockit.Expectations)2 Test (org.junit.Test)2 Verifications (mockit.Verifications)1