Search in sources :

Example 6 with PullImageCmd

use of com.github.dockerjava.api.command.PullImageCmd in project vespa by vespa-engine.

the class DockerImplTest method pullImageAsyncIfNeededWithError.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void pullImageAsyncIfNeededWithError() {
    final DockerImage image = new DockerImage("test:1.2.3");
    InspectImageCmd imageInspectCmd = mock(InspectImageCmd.class);
    when(imageInspectCmd.exec()).thenThrow(new NotFoundException("Image not found"));
    // Array to make it final
    ArgumentCaptor<ResultCallback> resultCallback = ArgumentCaptor.forClass(ResultCallback.class);
    PullImageCmd pullImageCmd = mock(PullImageCmd.class);
    when(pullImageCmd.exec(resultCallback.capture())).thenReturn(null);
    final DockerClient dockerClient = mock(DockerClient.class);
    when(dockerClient.inspectImageCmd(image.asString())).thenReturn(imageInspectCmd);
    when(dockerClient.pullImageCmd(eq(image.asString()))).thenReturn(pullImageCmd);
    final DockerImpl docker = new DockerImpl(dockerClient);
    docker.setMetrics(new MetricReceiverWrapper(MetricReceiver.nullImplementation));
    assertTrue("Should return true, we just scheduled the pull", docker.pullImageAsyncIfNeeded(image));
    assertTrue("Should return true, the pull i still ongoing", docker.pullImageAsyncIfNeeded(image));
    try {
        resultCallback.getValue().onComplete();
    } catch (Exception ignored) {
    }
    assertFalse(docker.imageIsDownloaded(image));
    assertTrue("Should return true, new pull scheduled", docker.pullImageAsyncIfNeeded(image));
}
Also used : InspectImageCmd(com.github.dockerjava.api.command.InspectImageCmd) MetricReceiverWrapper(com.yahoo.vespa.hosted.dockerapi.metrics.MetricReceiverWrapper) ExecStartResultCallback(com.github.dockerjava.core.command.ExecStartResultCallback) ResultCallback(com.github.dockerjava.api.async.ResultCallback) DockerClient(com.github.dockerjava.api.DockerClient) PullImageCmd(com.github.dockerjava.api.command.PullImageCmd) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) Test(org.junit.Test)

Aggregations

PullImageCmd (com.github.dockerjava.api.command.PullImageCmd)6 DockerClient (com.github.dockerjava.api.DockerClient)4 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)4 ResultCallback (com.github.dockerjava.api.async.ResultCallback)3 ExecStartResultCallback (com.github.dockerjava.core.command.ExecStartResultCallback)3 MetricReceiverWrapper (com.yahoo.vespa.hosted.dockerapi.metrics.MetricReceiverWrapper)3 InspectImageCmd (com.github.dockerjava.api.command.InspectImageCmd)2 InspectImageResponse (com.github.dockerjava.api.command.InspectImageResponse)2 AuthConfig (com.github.dockerjava.api.model.AuthConfig)2 Image (com.github.dockerjava.api.model.Image)2 PullImageResultCallback (com.github.dockerjava.core.command.PullImageResultCallback)2 IOException (java.io.IOException)2 HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)1 ExecCreateCmdResponse (com.github.dockerjava.api.command.ExecCreateCmdResponse)1 ExecStartCmd (com.github.dockerjava.api.command.ExecStartCmd)1 InspectContainerCmd (com.github.dockerjava.api.command.InspectContainerCmd)1 InspectContainerResponse (com.github.dockerjava.api.command.InspectContainerResponse)1 InspectExecResponse (com.github.dockerjava.api.command.InspectExecResponse)1 DockerClientException (com.github.dockerjava.api.exception.DockerClientException)1 NotModifiedException (com.github.dockerjava.api.exception.NotModifiedException)1