Search in sources :

Example 1 with Application

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

the class RemoteJavaApplicationLauncherTest method assertCanConnectDebuggerToApplication.

protected void assertCanConnectDebuggerToApplication(JavaApplication application) throws Exception {
    InetSocketAddress socket = application.getOptions().getInstancesOf(RemoteDebugging.Agent.class).iterator().next().getSocketAddress();
    Assert.assertThat(socket, is(notNullValue()));
    Eventually.assertThat(invoking(this).isListening(socket), is(true));
    CapturingApplicationConsole console = new CapturingApplicationConsole();
    try (Application jdb = LocalPlatform.get().launch(Application.class, Executable.named(findJDB()), Argument.of("-connect"), Argument.of(String.format("com.sun.jdi.SocketAttach:hostname=%s,port=%d", socket.getAddress().getHostAddress(), socket.getPort())), Console.of(console))) {
        Eventually.assertThat(invoking(console).getCapturedOutputLines(), hasItem(startsWith("VM Started")));
        console.getInputWriter().println("run");
        console.getInputWriter().println("quit");
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) 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)

Example 2 with Application

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

the class JSchFileShareDeployerTest method setup.

@Before
public void setup() throws Exception {
    RemotePlatform platform = getRemotePlatform();
    localShare = temporaryFolder.newFolder().getAbsolutePath();
    workingDirectory = temporaryFolder.newFolder().getAbsolutePath();
    File remoteParent = temporaryFolder.newFolder();
    remoteShare = new File(remoteParent, "share").getAbsolutePath();
    try (Application app = platform.launch(Application.class, Executable.named("ln"), Arguments.of("-s", localShare, remoteShare), DisplayName.of("Link"), Console.system())) {
        app.waitFor();
    }
}
Also used : File(java.io.File) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) Application(com.oracle.bedrock.runtime.Application) SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) Before(org.junit.Before)

Example 3 with Application

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

the class SimpleRemoteApplicationLauncherTest method shouldLaunchSimpleApplicationRemotely.

/**
 * Ensure that we can launch deploy a test file.
 */
@Test
public void shouldLaunchSimpleApplicationRemotely() throws Exception {
    RemotePlatform platform = getRemotePlatform();
    try (Application application = platform.launch("ls", Argument.of("-la"), Console.system())) {
        assertThat(application.waitFor(), is(0));
        application.close();
        assertThat(application.exitValue(), is(0));
    }
}
Also used : Application(com.oracle.bedrock.runtime.Application) Test(org.junit.Test)

Example 4 with Application

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

the class WGetHttpDeployer method deployArtifact.

@Override
protected void deployArtifact(URL sourceURL, String targetFileName, Platform platform) {
    CapturingApplicationConsole console = new CapturingApplicationConsole();
    try (Application application = platform.launch(Application.class, Executable.named(wgetCommand), Argument.of("-O"), Argument.of(targetFileName), Argument.of(sourceURL.toExternalForm()), DisplayName.of("Deploy"), Console.of(console))) {
        int exitCode = application.waitFor();
        application.close();
        if (exitCode != 0) {
            StringBuilder message = new StringBuilder("Error deploying ").append(targetFileName).append(" - wget returned ").append(exitCode).append("\n").append("wget output:");
            for (String line : console.getCapturedOutputLines()) {
                message.append(line);
            }
            for (String line : console.getCapturedErrorLines()) {
                message.append(line);
            }
            throw new RuntimeException(message.toString());
        }
    }
}
Also used : CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) Application(com.oracle.bedrock.runtime.Application)

Example 5 with Application

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

the class LocalPlatformJavaApplicationTest method shouldEnableRemoteDebugAndConnectBackToDebugger.

/**
 * Start the {@link JavaApplication} with remote debugging enabled and mode set to
 * {@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));
    Capture<Integer> debuggerPort = new Capture<>(getPlatform().getAvailablePorts());
    CapturingApplicationConsole jdbConsole = new CapturingApplicationConsole();
    try (Application jdb = getPlatform().launch(Application.class, Executable.named("jdb"), Argument.of("-connect"), Argument.of("com.sun.jdi.SocketListen:localAddress=" + getPlatform().getAddress().getHostAddress() + ",port=" + debuggerPort.get()), Console.of(jdbConsole))) {
        Eventually.assertThat("JDB did not start properly", invoking(jdbConsole).getCapturedOutputLines(), hasItem(startsWith("Listening at address:")));
        CapturingApplicationConsole console = new CapturingApplicationConsole();
        try (JavaApplication app = getPlatform().launch(JavaApplication.class, ClassName.of(SleepingApplication.class), DisplayName.of("TestApp"), // sleeping for 60 seconds to allow connection
        Argument.of("60"), RemoteDebugging.enabled().attach().at(new RemoteDebugging.TransportAddress(debuggerPort)), Console.of(console))) {
            Eventually.assertThat(invoking(console).getCapturedOutputLines(), hasItem(startsWith("Now sleeping")));
            // assert that the application connects back to the debugger
            // (this can take sometime as JDB initializes itself)
            Eventually.assertThat("Application did not connect back to JDB", invoking(jdbConsole).getCapturedOutputLines(), hasItem(containsString("VM Started:")), delayedBy(10, TimeUnit.SECONDS));
        }
    }
}
Also used : SleepingApplication(classloader.applications.SleepingApplication) CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) EventingApplication(classloader.applications.EventingApplication) SleepingApplication(classloader.applications.SleepingApplication) ParentApplication(classloader.applications.ParentApplication) Application(com.oracle.bedrock.runtime.Application) Capture(com.oracle.bedrock.util.Capture) Ignore(org.junit.Ignore) SocketBasedRemoteChannelTest(com.oracle.bedrock.runtime.concurrent.socket.SocketBasedRemoteChannelTest) Test(org.junit.Test)

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