Search in sources :

Example 51 with Application

use of com.oracle.bedrock.runtime.Application 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)

Example 52 with Application

use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.

the class DockerImageTest method shouldCloseWithApplicationAndUseOverridingBehaviour.

@Test
public void shouldCloseWithApplicationAndUseOverridingBehaviour() throws Exception {
    Application application = mock(Application.class);
    DockerImage image = new DockerImage(Arrays.asList("foo", "bar"), OptionsByType.empty());
    ImageCloseBehaviour behaviourApp = mock(ImageCloseBehaviour.class, "1");
    ImageCloseBehaviour behaviourOverride = mock(ImageCloseBehaviour.class, "2");
    when(application.getOptions()).thenReturn(OptionsByType.of(behaviourApp));
    image.onClosed(application, OptionsByType.of(behaviourOverride));
    verify(behaviourApp, never()).accept(same(image));
    verify(behaviourOverride).accept(same(image));
}
Also used : ImageCloseBehaviour(com.oracle.bedrock.runtime.docker.options.ImageCloseBehaviour) Application(com.oracle.bedrock.runtime.Application) Test(org.junit.Test)

Example 53 with Application

use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.

the class DockerImageTest method shouldRunInspect.

@Test
public void shouldRunInspect() throws Exception {
    Docker docker = Docker.auto();
    Platform platform = mock(Platform.class);
    Application application = mock(Application.class, "App");
    Application inspectApp = mock(Application.class, "Inspect");
    Inspect inspect = mock(Inspect.class);
    DockerImage image = new DockerImage(Arrays.asList("foo", "bar"), OptionsByType.of(docker));
    DockerImage imageSpy = spy(image);
    when(application.getPlatform()).thenReturn(platform);
    when(platform.launch(any(MetaClass.class))).thenReturn(inspectApp);
    doReturn(inspect).when(imageSpy).createInspectCommand();
    imageSpy.onAddingTo(application);
    imageSpy.inspect();
    verify(inspect).run(same(platform), same(docker));
}
Also used : Inspect(com.oracle.bedrock.runtime.docker.commands.Inspect) Platform(com.oracle.bedrock.runtime.Platform) MetaClass(com.oracle.bedrock.runtime.MetaClass) Application(com.oracle.bedrock.runtime.Application) Test(org.junit.Test)

Example 54 with Application

use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.

the class RemoteJavaApplicationLauncherTest method shouldEnableRemoteDebugAndConnectBackToDebugger.

/**
 * Start the application with remote debugging enabled using {@link RemoteDebugging.Behavior#ATTACH_TO_DEBUGGER}
 * and assert the process connects back to the debugger
 */
@Ignore("This test can cause JVMs to crash on various platforms.  Disabled for now until there is a fix.")
@Test
public void shouldEnableRemoteDebugAndConnectBackToDebugger() throws Exception {
    // Make sure we can run the JDB debugger otherwise we cannot run this test
    Assume.assumeThat(hasJDB(), is(true));
    InetAddress debugAddress = LocalPlatform.get().getAddress();
    Capture<Integer> debugPort = new Capture<>(LocalPlatform.get().getAvailablePorts());
    CapturingApplicationConsole jdbConsole = new CapturingApplicationConsole();
    try (Application jdb = LocalPlatform.get().launch(Application.class, Executable.named(findJDB()), Argument.of("-connect"), Argument.of(String.format("com.sun.jdi.SocketListen:port=%d", debugPort.get())), Console.of(jdbConsole))) {
        Eventually.assertThat("JDB did not start properly", invoking(jdbConsole).getCapturedOutputLines(), hasItem(startsWith("Listening at address:")));
        CapturingApplicationConsole console = new CapturingApplicationConsole();
        RemotePlatform platform = getRemotePlatform();
        try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), RemoteDebugging.enabled().attach().at(new RemoteDebugging.TransportAddress(debugAddress, debugPort)), Console.of(console))) {
            Eventually.assertThat(invoking(console).getCapturedOutputLines(), hasItem(startsWith("Now sleeping")));
            Eventually.assertThat("Application did not connect back to JDB", invoking(jdbConsole).getCapturedOutputLines(), hasItem(containsString("VM Started:")));
        }
    }
}
Also used : SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) InetAddress(java.net.InetAddress) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) Application(com.oracle.bedrock.runtime.Application) SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) EventingApplication(com.oracle.bedrock.runtime.remote.java.applications.EventingApplication) Capture(com.oracle.bedrock.util.Capture) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) Ignore(org.junit.Ignore) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 55 with Application

use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.

the class HttpDeployer method undeploy.

@Override
public DeployedArtifacts undeploy(DeployedArtifacts deployedArtifacts, Platform platform, Option... deploymentOptions) {
    DeployedArtifacts failedArtifacts = new DeployedArtifacts();
    for (File file : deployedArtifacts) {
        CapturingApplicationConsole console = new CapturingApplicationConsole();
        try (Application application = platform.launch(Application.class, Executable.named("rm"), Argument.of(StringHelper.doubleQuoteIfNecessary(file.toString())), DisplayName.of("Undeploy"))) {
            if (application.waitFor() != 0) {
                StringBuilder message = new StringBuilder("Error undeploying ").append(file.toString()).append(" - rm returned ").append(application.exitValue()).append("\n").append("rm output:");
                for (String line : console.getCapturedOutputLines()) {
                    message.append(line);
                }
                for (String line : console.getCapturedErrorLines()) {
                    message.append(line);
                }
                failedArtifacts.add(file);
            }
        }
    }
    return failedArtifacts;
}
Also used : DeployedArtifacts(com.oracle.bedrock.runtime.remote.DeployedArtifacts) CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) File(java.io.File) Application(com.oracle.bedrock.runtime.Application)

Aggregations

Application (com.oracle.bedrock.runtime.Application)57 Test (org.junit.Test)23 CapturingApplicationConsole (com.oracle.bedrock.runtime.console.CapturingApplicationConsole)22 Platform (com.oracle.bedrock.runtime.Platform)16 Arguments (com.oracle.bedrock.runtime.options.Arguments)13 OptionsByType (com.oracle.bedrock.OptionsByType)12 File (java.io.File)12 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)11 Timeout (com.oracle.bedrock.options.Timeout)9 MetaClass (com.oracle.bedrock.runtime.MetaClass)9 List (java.util.List)7 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)6 Remove (com.oracle.bedrock.runtime.docker.commands.Remove)5 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)5 InetAddress (java.net.InetAddress)5 SleepingApplication (applications.SleepingApplication)4 ContainerCloseBehaviour (com.oracle.bedrock.runtime.docker.options.ContainerCloseBehaviour)4 TimeUnit (java.util.concurrent.TimeUnit)4 Collectors (java.util.stream.Collectors)4 EventingApplication (classloader.applications.EventingApplication)3