Search in sources :

Example 1 with Remove

use of com.oracle.bedrock.runtime.docker.commands.Remove in project oracle-bedrock by coherence-community.

the class DockerImageTest method shouldRemoveImage.

@Test
public void shouldRemoveImage() throws Exception {
    Docker docker = Docker.auto();
    Platform platform = mock(Platform.class);
    Application application = mock(Application.class, "App");
    Application removeApp = mock(Application.class, "Inspect");
    DockerImage image = new DockerImage(Arrays.asList("foo"), OptionsByType.of(docker));
    when(application.getPlatform()).thenReturn(platform);
    when(platform.launch(any(MetaClass.class), anyVararg())).thenReturn(removeApp);
    image.onAddingTo(application);
    image.remove();
    ArgumentCaptor<MetaClass> captor = ArgumentCaptor.forClass(MetaClass.class);
    verify(platform).launch(captor.capture(), anyVararg());
    Remove.RemoveImage remove = (Remove.RemoveImage) captor.getValue();
    assertThat(remove, is(notNullValue()));
    OptionsByType optionsByType = OptionsByType.empty();
    remove.onLaunch(platform, optionsByType);
    Arguments arguments = optionsByType.get(Arguments.class);
    List<String> values = arguments.resolve(mock(Platform.class), OptionsByType.empty());
    assertThat(values, contains("rmi", "foo"));
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) Arguments(com.oracle.bedrock.runtime.options.Arguments) Remove(com.oracle.bedrock.runtime.docker.commands.Remove) MetaClass(com.oracle.bedrock.runtime.MetaClass) Application(com.oracle.bedrock.runtime.Application) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 2 with Remove

use of com.oracle.bedrock.runtime.docker.commands.Remove in project oracle-bedrock by coherence-community.

the class DockerContainerTest method shouldRemoveContainer.

@Test
public void shouldRemoveContainer() throws Exception {
    Docker docker = Docker.auto();
    Platform platform = mock(Platform.class);
    Application application = mock(Application.class, "App");
    Application removeApp = mock(Application.class, "Inspect");
    DockerContainer container = new DockerContainer("foo", OptionsByType.of(docker));
    when(application.getPlatform()).thenReturn(platform);
    when(platform.launch(any(MetaClass.class), anyVararg())).thenReturn(removeApp);
    container.onAddingTo(application);
    container.remove(false);
    ArgumentCaptor<MetaClass> captor = ArgumentCaptor.forClass(MetaClass.class);
    verify(platform).launch(captor.capture(), anyVararg());
    OptionsByType optionsByType = OptionsByType.empty();
    Remove.RemoveContainer remove = (Remove.RemoveContainer) captor.getValue();
    assertThat(remove, is(notNullValue()));
    remove.onLaunch(platform, optionsByType);
    Arguments arguments = optionsByType.get(Arguments.class);
    List<String> values = arguments.resolve(mock(Platform.class), OptionsByType.empty());
    assertThat(values, contains("rm", "foo"));
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) Arguments(com.oracle.bedrock.runtime.options.Arguments) Remove(com.oracle.bedrock.runtime.docker.commands.Remove) Matchers.anyString(org.mockito.Matchers.anyString) MetaClass(com.oracle.bedrock.runtime.MetaClass) Application(com.oracle.bedrock.runtime.Application) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Example 3 with Remove

use of com.oracle.bedrock.runtime.docker.commands.Remove in project oracle-bedrock by coherence-community.

the class DockerContainer method remove.

/**
 * Remove this {@link DockerContainer}.
 * <p>
 * This equates to running the <code>docker rm</code> command for
 * this {@link DockerContainer}.
 * <p>
 * This command will fail to execute if the {@link DockerContainer} is still running.
 *
 * @param force  whether to add --force to the Docker rm command
 *
 * @throws IllegalStateException  if this {@link DockerContainer} has not been added
 *                                to an {@link Application} as a {@link Feature}.
 */
public void remove(boolean force) {
    if (platform == null) {
        throw new IllegalStateException("No Platform is available, is this container a feature of an Application");
    }
    Docker docker = optionsByType.get(Docker.class);
    Remove.RemoveContainer removeCommand;
    if (force) {
        removeCommand = Remove.containers(name).force(true);
    } else {
        removeCommand = Remove.containers(name);
    }
    try (Application app = platform.launch(removeCommand, docker)) {
        app.waitFor();
    }
}
Also used : Remove(com.oracle.bedrock.runtime.docker.commands.Remove) Application(com.oracle.bedrock.runtime.Application)

Example 4 with Remove

use of com.oracle.bedrock.runtime.docker.commands.Remove in project oracle-bedrock by coherence-community.

the class DockerContainerTest method shouldRemoveContainerWithForce.

@Test
public void shouldRemoveContainerWithForce() throws Exception {
    Docker docker = Docker.auto();
    Platform platform = mock(Platform.class);
    Application application = mock(Application.class, "App");
    Application removeApp = mock(Application.class, "Inspect");
    DockerContainer container = new DockerContainer("foo", OptionsByType.of(docker));
    when(application.getPlatform()).thenReturn(platform);
    when(platform.launch(any(MetaClass.class), anyVararg())).thenReturn(removeApp);
    container.onAddingTo(application);
    container.remove(true);
    ArgumentCaptor<MetaClass> captor = ArgumentCaptor.forClass(MetaClass.class);
    verify(platform).launch(captor.capture(), anyVararg());
    OptionsByType optionsByType = OptionsByType.empty();
    Remove.RemoveContainer remove = (Remove.RemoveContainer) captor.getValue();
    assertThat(remove, is(notNullValue()));
    remove.onLaunch(platform, optionsByType);
    Arguments arguments = optionsByType.get(Arguments.class);
    List<String> values = arguments.resolve(mock(Platform.class), OptionsByType.empty());
    assertThat(values, contains("rm", "--force", "foo"));
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) Arguments(com.oracle.bedrock.runtime.options.Arguments) Remove(com.oracle.bedrock.runtime.docker.commands.Remove) Matchers.anyString(org.mockito.Matchers.anyString) MetaClass(com.oracle.bedrock.runtime.MetaClass) Application(com.oracle.bedrock.runtime.Application) OptionsByType(com.oracle.bedrock.OptionsByType) Test(org.junit.Test)

Aggregations

Application (com.oracle.bedrock.runtime.Application)4 Remove (com.oracle.bedrock.runtime.docker.commands.Remove)4 OptionsByType (com.oracle.bedrock.OptionsByType)3 MetaClass (com.oracle.bedrock.runtime.MetaClass)3 Platform (com.oracle.bedrock.runtime.Platform)3 Arguments (com.oracle.bedrock.runtime.options.Arguments)3 Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)2