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");
}
}
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));
}
}
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));
}
}
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));
}
}
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"));
}
}
Aggregations