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