Search in sources :

Example 11 with RunService

use of io.fabric8.maven.docker.service.RunService in project docker-maven-plugin by fabric8io.

the class RunServiceTest method testWithMultipleStopExceptions.

@Test
public void testWithMultipleStopExceptions() throws Exception {
    GavLabel testLabel = new GavLabel("Im:A:Test");
    String firstName = "first-container:latest";
    ImageConfiguration first = new ImageConfiguration();
    first.setName(firstName);
    String secondName = "second-container:latest";
    ImageConfiguration second = new ImageConfiguration();
    second.setName(secondName);
    tracker.registerContainer(firstName, first, testLabel);
    tracker.registerContainer(secondName, second, testLabel);
    LogOutputSpecFactory logOutputSpecFactory = new LogOutputSpecFactory(true, true, null);
    new Expectations() {

        {
            docker.stopContainer(firstName, 0);
            result = new DockerAccessException("TEST one");
            docker.stopContainer(secondName, 0);
            result = new DockerAccessException("TEST two");
        }
    };
    runService = new RunService(docker, queryService, tracker, logOutputSpecFactory, log);
    Exception thrownException = assertThrows(DockerAccessException.class, () -> runService.stopStartedContainers(false, true, true, testLabel));
    assertEquals("(TEST two,TEST one)", thrownException.getLocalizedMessage());
}
Also used : GavLabel(io.fabric8.maven.docker.util.GavLabel) Expectations(mockit.Expectations) LogOutputSpecFactory(io.fabric8.maven.docker.log.LogOutputSpecFactory) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException) ExecException(io.fabric8.maven.docker.access.ExecException) PortBindingException(io.fabric8.maven.docker.model.PortBindingException) Test(org.junit.Test)

Example 12 with RunService

use of io.fabric8.maven.docker.service.RunService in project docker-maven-plugin by fabric8io.

the class StartContainerExecutorTest method testStartContainers.

@Test
public void testStartContainers(@Mocked ServiceHub hub, @Mocked DockerAccess dockerAccess, @Mocked ContainerTracker containerTracker, @Mocked Logger log) throws IOException, ExecException {
    // Given
    new Expectations() {

        {
            dockerAccess.createContainer((ContainerCreateConfig) any, anyString);
            result = "container-name";
            dockerAccess.getContainer(anyString);
            result = new ContainerDetails(JsonFactory.newJsonObject("{\"NetworkSettings\":{\"IPAddress\":\"192.168.1.2\"}}"));
            QueryService queryService = new QueryService(dockerAccess);
            hub.getQueryService();
            result = queryService;
            hub.getRunService();
            result = new RunService(dockerAccess, queryService, containerTracker, new LogOutputSpecFactory(true, true, null), log);
        }
    };
    Properties projectProps = new Properties();
    StartContainerExecutor startContainerExecutor = new StartContainerExecutor.Builder().serviceHub(hub).projectProperties(projectProps).portMapping(new PortMapping(Collections.emptyList(), projectProps)).gavLabel(new GavLabel("io.fabric8:test:0.1.0")).basedir(new File("/tmp/foo")).containerNamePattern("test-").buildTimestamp(new Date()).exposeContainerProps("docker.container").imageConfig(new ImageConfiguration.Builder().name("name").alias("alias").runConfig(new RunImageConfiguration.Builder().build()).build()).build();
    // When
    String containerId = startContainerExecutor.startContainer();
    // Then
    assertEquals("container-name", containerId);
    assertEquals("container-name", projectProps.getProperty("docker.container.alias.id"));
    assertEquals("192.168.1.2", projectProps.getProperty("docker.container.alias.ip"));
}
Also used : Expectations(mockit.Expectations) RunService(io.fabric8.maven.docker.service.RunService) LogOutputSpecFactory(io.fabric8.maven.docker.log.LogOutputSpecFactory) Properties(java.util.Properties) Date(java.util.Date) GavLabel(io.fabric8.maven.docker.util.GavLabel) QueryService(io.fabric8.maven.docker.service.QueryService) PortMapping(io.fabric8.maven.docker.access.PortMapping) File(java.io.File) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) ContainerDetails(io.fabric8.maven.docker.model.ContainerDetails) Test(org.junit.Test)

Aggregations

ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)7 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)6 RunService (io.fabric8.maven.docker.service.RunService)5 QueryService (io.fabric8.maven.docker.service.QueryService)4 GavLabel (io.fabric8.maven.docker.util.GavLabel)4 PortMapping (io.fabric8.maven.docker.access.PortMapping)3 LogOutputSpecFactory (io.fabric8.maven.docker.log.LogOutputSpecFactory)3 Properties (java.util.Properties)3 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)2 CopyConfiguration (io.fabric8.maven.docker.config.CopyConfiguration)2 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)2 Container (io.fabric8.maven.docker.model.Container)2 Network (io.fabric8.maven.docker.model.Network)2 RegistryService (io.fabric8.maven.docker.service.RegistryService)2 IOException (java.io.IOException)2 ArrayDeque (java.util.ArrayDeque)2 Expectations (mockit.Expectations)2 Test (org.junit.Test)2 DockerAccess (io.fabric8.maven.docker.access.DockerAccess)1 ExecException (io.fabric8.maven.docker.access.ExecException)1