use of com.oracle.bedrock.runtime.console.PipedApplicationConsole in project oracle-bedrock by coherence-community.
the class LocalPlatformApplicationTest method shouldInvokeApplicationListeners.
/**
* Ensure that we can run an {@link Application} (a JVM in this case) and
* {@link ApplicationListener}s are notified.
*
* @throws Exception
*/
@Test
public void shouldInvokeApplicationListeners() throws Exception {
Assume.assumeFalse("Skipping test in GitHub", Boolean.getBoolean("github.build"));
ApplicationListener<Application> listener = Mockito.mock(ApplicationListener.class);
PipedApplicationConsole console = new PipedApplicationConsole();
try (Application application = LocalPlatform.get().launch(Application.class, Executable.named("java"), Argument.of("-help"), Diagnostics.enabled(), ErrorStreamRedirection.enabled(), Console.of(console), Decoration.of(listener), DisplayName.of("java"))) {
Mockito.verify(listener, Mockito.times(1)).onLaunched(Mockito.same(application));
BufferedReader reader = console.getOutputReader();
String stdout = reader.readLine();
while (stdout.contains("JAVA_TOOL_OPTIONS")) {
stdout = reader.readLine();
}
assertThat(stdout, containsString("Usage: java"));
application.waitFor();
application.close();
Mockito.verify(listener, Mockito.times(1)).onClosing(Mockito.same(application), any(OptionsByType.class));
Mockito.verify(listener, Mockito.times(1)).onClosed(Mockito.same(application), any(OptionsByType.class));
int exitCode = application.exitValue();
assertThat(exitCode, is(0));
}
}
use of com.oracle.bedrock.runtime.console.PipedApplicationConsole in project oracle-bedrock by coherence-community.
the class LocalPlatformApplicationTest method shouldLaunchApplication.
/**
* Ensure that we can run an {@link Application} (a JVM in this case).
*
* @throws Exception
*/
@Test
public void shouldLaunchApplication() throws Exception {
Assume.assumeFalse("Skipping test in GitHub", Boolean.getBoolean("github.build"));
PipedApplicationConsole console = new PipedApplicationConsole();
try (Application application = LocalPlatform.get().launch(Application.class, Executable.named("java"), Argument.of("-help"), DisplayName.of("java"), ErrorStreamRedirection.enabled(), Diagnostics.enabled(), Console.of(console))) {
BufferedReader reader = console.getOutputReader();
String stdout = reader.readLine();
while (stdout.contains("JAVA_TOOL_OPTIONS")) {
stdout = reader.readLine();
}
assertThat(stdout, containsString("Usage: java"));
}
}
use of com.oracle.bedrock.runtime.console.PipedApplicationConsole in project oracle-bedrock by coherence-community.
the class AbstractJavaApplicationTest method shouldRunApplication.
/**
* Ensure that we can start and terminate a {@link JavaApplication}.
*
* @throws Exception
*/
@Test
public void shouldRunApplication() throws Exception {
PipedApplicationConsole console = new PipedApplicationConsole();
try (JavaApplication application = getPlatform().launch(JavaApplication.class, DisplayName.of("java-app"), ClassName.of(DummyApp.class), Arguments.of("arg1", "arg2"), SystemProperty.of("test.prop.1", "value.1"), SystemProperty.of("test.prop.2", "value.2"), IPv4Preferred.yes(), Diagnostics.enabled(), Console.of(console))) {
String stdout = console.getOutputReader().readLine();
assertThat(stdout.startsWith("[java-app:"), is(true));
assertThat(stdout, containsString("arg1,arg2"));
stdout = console.getOutputReader().readLine();
assertThat(stdout, containsString("test.prop.1=value.1"));
}
}
use of com.oracle.bedrock.runtime.console.PipedApplicationConsole in project oracle-bedrock by coherence-community.
the class VagrantChecker method vagrantExists.
/**
* Attempt to run the Vagrant --version command and
* parse the expected output. If this succeeds then
* Vagrant is present on the system.
*
* @return true if Vagrant is installed
*/
public static synchronized boolean vagrantExists() {
boolean noVagrantProperty = Boolean.getBoolean("no.vagrant");
if (noVagrantProperty) {
return false;
}
String command = VagrantPlatform.getDefaultVagrantCommand();
try (PipedApplicationConsole console = new PipedApplicationConsole();
Application application = LocalPlatform.get().launch(Application.class, Executable.named(command), Argument.of("--version"), DisplayName.of("Vagrant"), Console.of(console))) {
int exitCode = application.waitFor();
if (exitCode != 0) {
return false;
}
String line = console.getOutputReader().readLine();
application.close();
Pattern pattern = Pattern.compile(VAGRANT_REGEX);
Matcher matcher = pattern.matcher(line);
return matcher.matches();
} catch (Throwable e) {
System.err.println("Error checking for Vagrant - assume not present. " + e.getMessage());
return false;
}
}
use of com.oracle.bedrock.runtime.console.PipedApplicationConsole in project oracle-bedrock by coherence-community.
the class LocalPlatformApplicationTest method shouldLaunchExecutable.
/**
* Ensure that we can run an {@link Application} (a JVM in this case).
*
* @throws Exception
*/
@Test
public void shouldLaunchExecutable() throws Exception {
Assume.assumeFalse("Skipping test in GitHub", Boolean.getBoolean("github.build"));
PipedApplicationConsole console = new PipedApplicationConsole();
try (Application application = LocalPlatform.get().launch("java", Argument.of("-help"), DisplayName.of("java"), ErrorStreamRedirection.enabled(), Diagnostics.enabled(), Console.of(console))) {
BufferedReader reader = console.getOutputReader();
String stdout = reader.readLine();
while (stdout.contains("JAVA_TOOL_OPTIONS")) {
stdout = reader.readLine();
}
assertThat(stdout, containsString("Usage: java"));
}
}
Aggregations