Search in sources :

Example 6 with JavaApplication

use of com.oracle.bedrock.runtime.java.JavaApplication 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 7 with JavaApplication

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

the class RemoteJavaApplicationLauncherTest method shouldReceiveEventsFromApplicationUsingListenerAsOption.

@Test
public void shouldReceiveEventsFromApplicationUsingListenerAsOption() throws Exception {
    Platform platform = getRemotePlatform();
    String name = "Foo";
    int count = 10;
    EventListener listener1 = new EventListener(count);
    EventListener listener2 = new EventListener(count);
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(EventingApplication.class), IPv4Preferred.yes(), RemoteEvents.listener(listener1, StreamName.of(name)), RemoteEvents.listener(listener2, StreamName.of(name)), Argument.of(name), Argument.of(count))) {
        Assert.assertThat(listener1.await(1, TimeUnit.MINUTES), is(true));
        Assert.assertThat(listener2.await(1, TimeUnit.MINUTES), is(true));
        application.close();
        Assert.assertThat(listener1.getEvents().size(), is(count));
        Assert.assertThat(listener2.getEvents().size(), is(count));
    }
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RemoteEventListener(com.oracle.bedrock.runtime.concurrent.RemoteEventListener) EventingApplication(com.oracle.bedrock.runtime.remote.java.applications.EventingApplication) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 8 with JavaApplication

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

the class RemoteJavaApplicationLauncherTest method shouldTerminateUsingRuntimeExit.

/**
 * Ensure that local {@link JavaApplication}s can be terminated using {@link RuntimeExit}.
 */
@Test
public void shouldTerminateUsingRuntimeExit() throws Exception {
    // build and start the SleepingApplication
    Platform platform = getRemotePlatform();
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), Argument.of("3"), IPv4Preferred.yes())) {
        application.close(RuntimeExit.withExitCode(42));
        int exitStatus = application.waitFor();
        assertThat(exitStatus, is(42));
    }
}
Also used : SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) Platform(com.oracle.bedrock.runtime.Platform) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 9 with JavaApplication

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

the class RemoteJavaApplicationLauncherTest method shouldTerminateUsingRuntimeHalt.

/**
 * Ensure that local {@link JavaApplication}s can be terminated using {@link RuntimeHalt}.
 */
@Test
public void shouldTerminateUsingRuntimeHalt() throws Exception {
    // build and start the SleepingApplication
    Platform platform = getRemotePlatform();
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), Argument.of("3"), IPv4Preferred.yes())) {
        application.close(RuntimeHalt.withExitCode(42));
        int exitStatus = application.waitFor();
        assertThat(exitStatus, is(42));
    }
}
Also used : SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) Platform(com.oracle.bedrock.runtime.Platform) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 10 with JavaApplication

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

Aggregations

JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)37 Test (org.junit.Test)32 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)20 AbstractRemoteTest (com.oracle.bedrock.runtime.remote.AbstractRemoteTest)17 SleepingApplication (com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication)15 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)12 Platform (com.oracle.bedrock.runtime.Platform)9 CapturingApplicationConsole (com.oracle.bedrock.runtime.console.CapturingApplicationConsole)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 EventingApplication (com.oracle.bedrock.runtime.remote.java.applications.EventingApplication)7 SleepingApplication (applications.SleepingApplication)4 OptionsByType (com.oracle.bedrock.OptionsByType)4 Application (com.oracle.bedrock.runtime.Application)4 File (java.io.File)4 RemoteEventListener (com.oracle.bedrock.runtime.concurrent.RemoteEventListener)3 BufferedReader (java.io.BufferedReader)3 ExpressionEvaluator (com.oracle.bedrock.lang.ExpressionEvaluator)2 Timeout (com.oracle.bedrock.options.Timeout)2 RemoteEvent (com.oracle.bedrock.runtime.concurrent.RemoteEvent)2 JUnitTestRun (com.oracle.bedrock.testsupport.junit.JUnitTestRun)2