Search in sources :

Example 1 with InspectExecCmd

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

the class DockerImplTest method testExecuteCompletes.

@Test
public void testExecuteCompletes() throws Exception {
    final String containerId = "container-id";
    final String[] command = new String[] { "/bin/ls", "-l" };
    final String execId = "exec-id";
    final int exitCode = 3;
    final DockerClient dockerClient = mock(DockerClient.class);
    final ExecCreateCmdResponse response = mock(ExecCreateCmdResponse.class);
    when(response.getId()).thenReturn(execId);
    final ExecCreateCmd execCreateCmd = mock(ExecCreateCmd.class);
    when(dockerClient.execCreateCmd(any(String.class))).thenReturn(execCreateCmd);
    when(execCreateCmd.withCmd(Matchers.<String>anyVararg())).thenReturn(execCreateCmd);
    when(execCreateCmd.withAttachStdout(any(Boolean.class))).thenReturn(execCreateCmd);
    when(execCreateCmd.withAttachStderr(any(Boolean.class))).thenReturn(execCreateCmd);
    when(execCreateCmd.withUser(any(String.class))).thenReturn(execCreateCmd);
    when(execCreateCmd.exec()).thenReturn(response);
    final ExecStartCmd execStartCmd = mock(ExecStartCmd.class);
    when(dockerClient.execStartCmd(any(String.class))).thenReturn(execStartCmd);
    when(execStartCmd.exec(any(ExecStartResultCallback.class))).thenReturn(mock(ExecStartResultCallback.class));
    final InspectExecCmd inspectExecCmd = mock(InspectExecCmd.class);
    final InspectExecResponse state = mock(InspectExecResponse.class);
    when(dockerClient.inspectExecCmd(any(String.class))).thenReturn(inspectExecCmd);
    when(inspectExecCmd.exec()).thenReturn(state);
    when(state.isRunning()).thenReturn(false);
    when(state.getExitCode()).thenReturn(exitCode);
    final Docker docker = new DockerImpl(dockerClient);
    final ProcessResult result = docker.executeInContainer(new ContainerName(containerId), command);
    assertThat(result.getExitStatus(), is(exitCode));
}
Also used : DockerClient(com.github.dockerjava.api.DockerClient) ExecStartResultCallback(com.github.dockerjava.core.command.ExecStartResultCallback) InspectExecCmd(com.github.dockerjava.api.command.InspectExecCmd) ExecCreateCmdResponse(com.github.dockerjava.api.command.ExecCreateCmdResponse) ExecStartCmd(com.github.dockerjava.api.command.ExecStartCmd) InspectExecResponse(com.github.dockerjava.api.command.InspectExecResponse) ExecCreateCmd(com.github.dockerjava.api.command.ExecCreateCmd) Test(org.junit.Test)

Aggregations

DockerClient (com.github.dockerjava.api.DockerClient)1 ExecCreateCmd (com.github.dockerjava.api.command.ExecCreateCmd)1 ExecCreateCmdResponse (com.github.dockerjava.api.command.ExecCreateCmdResponse)1 ExecStartCmd (com.github.dockerjava.api.command.ExecStartCmd)1 InspectExecCmd (com.github.dockerjava.api.command.InspectExecCmd)1 InspectExecResponse (com.github.dockerjava.api.command.InspectExecResponse)1 ExecStartResultCallback (com.github.dockerjava.core.command.ExecStartResultCallback)1 Test (org.junit.Test)1