Search in sources :

Example 1 with CapturingApplicationConsole

use of com.oracle.bedrock.runtime.console.CapturingApplicationConsole 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 CapturingApplicationConsole

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

the class RemoteJavaApplicationLauncherTest method shouldSetRemoteDebugEnabledSuspendedIsTrue.

/**
 * Should run the application with remote debug enabled if set in schema
 * with start suspended set to false.
 */
@Test
public void shouldSetRemoteDebugEnabledSuspendedIsTrue() throws Exception {
    // Make sure we can run the JDB debugger otherwise we cannot run this test
    Assume.assumeThat(hasJDB(), is(true));
    CapturingApplicationConsole console = new CapturingApplicationConsole();
    RemotePlatform platform = getRemotePlatform();
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), RemoteDebugging.enabled().startSuspended(true).at(new RemoteDebugging.TransportAddress(LocalPlatform.get().getAvailablePorts())), JavaHome.at(System.getProperty("java.home")), Console.of(console))) {
        assertCanConnectDebuggerToApplication(application);
        Eventually.assertThat(invoking(console).getCapturedOutputLines(), hasItem(startsWith("Now sleeping")));
        List<String> args = application.invoke(new GetProgramArgs());
        String debugArg = null;
        for (String arg : args) {
            if (arg.startsWith("-agentlib:jdwp=")) {
                debugArg = arg.toLowerCase();
                break;
            }
        }
        Assert.assertThat(debugArg, is(notNullValue()));
        Assert.assertThat(debugArg, startsWith("-agentlib:jdwp=transport=dt_socket,"));
        Assert.assertThat(debugArg, containsString(",suspend=y"));
        Assert.assertThat(debugArg, containsString(",server=y"));
    }
}
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) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 3 with CapturingApplicationConsole

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

the class RemoteJavaApplicationLauncherTest method shouldSetRemoteDebugDisabled.

/**
 * Should run the application with remote debug disabled.
 *
 * NOTE: This test is ignored when running in an IDE in debug mode
 * as the JavaVirtualMachine class will pick up the debug settings
 * and pass them on to the process causing the test to fail
 */
@Test
public void shouldSetRemoteDebugDisabled() throws Exception {
    CapturingApplicationConsole console = new CapturingApplicationConsole();
    RemoteDebugging remoteDebugging = RemoteDebugging.disabled();
    RemotePlatform platform = getRemotePlatform();
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), DisplayName.of("Java"), Argument.of("30"), Console.of(console), remoteDebugging)) {
        Eventually.assertThat(invoking(console).getCapturedOutputLines(), hasItem(startsWith("Now sleeping")));
        List<String> args = application.invoke(new GetProgramArgs());
        String debugArg = null;
        for (String arg : args) {
            if (arg.startsWith("-agentlib:jdwp=")) {
                debugArg = arg.toLowerCase();
                break;
            }
        }
        Assert.assertThat(debugArg, is(nullValue()));
    }
}
Also used : SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) RemoteDebugging(com.oracle.bedrock.runtime.java.profiles.RemoteDebugging) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 4 with CapturingApplicationConsole

use of com.oracle.bedrock.runtime.console.CapturingApplicationConsole 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 CapturingApplicationConsole

use of com.oracle.bedrock.runtime.console.CapturingApplicationConsole 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

CapturingApplicationConsole (com.oracle.bedrock.runtime.console.CapturingApplicationConsole)30 Application (com.oracle.bedrock.runtime.Application)21 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)9 Test (org.junit.Test)9 File (java.io.File)7 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)5 SleepingApplication (com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication)5 SleepingApplication (classloader.applications.SleepingApplication)4 AbstractRemoteTest (com.oracle.bedrock.runtime.remote.AbstractRemoteTest)4 IOException (java.io.IOException)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 EventingApplication (classloader.applications.EventingApplication)3 ParentApplication (classloader.applications.ParentApplication)3 OptionsByType (com.oracle.bedrock.OptionsByType)3 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)3 Arguments (com.oracle.bedrock.runtime.options.Arguments)3 StringReader (java.io.StringReader)3 Path (java.nio.file.Path)3 JsonReader (javax.json.JsonReader)3 Option (com.oracle.bedrock.Option)2