use of com.oracle.bedrock.runtime.LocalPlatform in project oracle-bedrock by coherence-community.
the class VagrantPlatform method execute.
/**
* Execute the application defined by the specified {@link OptionsByType}.
*
* @param optionsByType the {@link OptionsByType}
*/
protected void execute(OptionsByType optionsByType) {
LocalPlatform platform = LocalPlatform.get();
Timeout timeout = optionsByType.getOrDefault(Timeout.class, Timeout.after(5, TimeUnit.MINUTES));
try (Application application = platform.launch(Application.class, optionsByType.asArray())) {
application.waitFor(timeout);
} catch (Exception e) {
throw new RuntimeException("Error executing Vagrant command", e);
}
}
use of com.oracle.bedrock.runtime.LocalPlatform in project oracle-bedrock by coherence-community.
the class VagrantPlatform method detectSSH.
/**
* Detect the SSH settings for the NAT port forwarding that Vagrant
* has configured on the VM and set them into this {@link VagrantPlatform}.
*
* @return the SSH properties configured by Vagrant
*/
protected Properties detectSSH() {
OptionsByType optionsByType = getDefaultOptions().add(Argument.of("ssh-config"));
LocalPlatform platform = LocalPlatform.get();
try (PipedApplicationConsole console = new PipedApplicationConsole();
Application application = platform.launch(Application.class, optionsByType.add(Console.of(console)).asArray())) {
application.waitFor();
application.close();
Properties sshProperties = new Properties();
BufferedReader reader = console.getOutputReader();
String line = reader.readLine();
while (line != null) {
line = line.trim();
int index = line.indexOf(']');
index = line.indexOf(':', index);
line = line.substring(index + 1).trim();
index = line.indexOf(' ');
if (index > 0) {
String key = line.substring(0, index).trim();
String value = line.substring(index + 1).trim();
if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
value = value.substring(1, value.length() - 1);
}
sshProperties.setProperty(key, value);
}
try {
line = reader.readLine();
} catch (IOException e) {
line = null;
}
}
return sshProperties;
} catch (Exception e) {
throw new RuntimeException("Error attempting to detect VM's SSH settings", e);
}
}
use of com.oracle.bedrock.runtime.LocalPlatform in project oracle-bedrock by coherence-community.
the class MavenTest method shouldLaunchCoherenceCacheServer.
/**
* Ensure that {@link Maven} can resolve a single artifact (without a transitive dependency).
*/
@Test
public void shouldLaunchCoherenceCacheServer() throws Exception {
LocalPlatform platform = LocalPlatform.get();
CapturingApplicationConsole console = new CapturingApplicationConsole();
try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of("com.tangosol.net.DefaultCacheServer"), Maven.artifact("com.oracle.coherence.ce", "coherence", "14.1.1-0-3"), SystemProperty.of("tangosol.coherence.cacheconfig", "coherence-cache-config.xml"), Console.of(console), Diagnostics.enabled())) {
Eventually.assertThat(invoking(console).getCapturedErrorLines(), hasItem(containsString("14.1.1-0-3")));
}
}
use of com.oracle.bedrock.runtime.LocalPlatform in project oracle-bedrock by coherence-community.
the class JacocoProfileTest method shouldEstablishJaCoCoProfileUsingASystemProperty.
/**
* Ensure we can configure and establish a {@link JacocoProfile} using a System Property
*/
@Test
public void shouldEstablishJaCoCoProfileUsingASystemProperty() throws Exception {
// define the JaCoCo destination file pattern
String jacocoDestinationFileName = "jacoco-${bedrock.runtime.id}.exec";
// create a temp file name for JaCoCo to output the code coverage report to
File destinationFile = new File(System.getProperty("java.io.tmpdir"), jacocoDestinationFileName);
// define the JaCoCo profile as a System Property
System.getProperties().setProperty("bedrock.profile.jacoco", "destfile=" + destinationFile);
// build and start the SleepingApplication
LocalPlatform platform = LocalPlatform.get();
File telemetricsFile;
try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), IPv4Preferred.yes())) {
ExpressionEvaluator evaluator = new ExpressionEvaluator(application.getOptions());
// create a File representing the JaCoCo telemetrics file
telemetricsFile = new File(System.getProperty("java.io.tmpdir"), evaluator.evaluate(jacocoDestinationFileName, String.class));
} finally {
System.getProperties().remove("bedrock.profile.jacoco");
}
// assert that JaCoCo created the telemetrics file (and thus the agent ran)
assertThat(telemetricsFile.exists(), is(true));
// assert that the telemetrics file contains something
assertThat(telemetricsFile.length(), is(greaterThan(0L)));
}
use of com.oracle.bedrock.runtime.LocalPlatform in project oracle-bedrock by coherence-community.
the class JacocoProfileTest method shouldEstablishJaCoCoProfileUsingAnOption.
/**
* Ensure we can configure and establish a {@link JacocoProfile} as an {@link Option}.
*/
@Test
public void shouldEstablishJaCoCoProfileUsingAnOption() throws Exception {
// define the JaCoCo destination file pattern
String jacocoDestinationFileName = "jacoco-${bedrock.runtime.id}.exec";
// create a temp file name for JaCoCo to output the code coverage report to
File destinationFile = new File(System.getProperty("java.io.tmpdir"), jacocoDestinationFileName);
// define the JaCoCo profile
JacocoProfile profile = JacocoProfile.enabled("destfile=" + destinationFile);
// build and start the SleepingApplication
LocalPlatform platform = LocalPlatform.get();
File telemetricsFile;
try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), IPv4Preferred.yes(), profile)) {
ExpressionEvaluator evaluator = new ExpressionEvaluator(application.getOptions());
// create a File representing the JaCoCo telemetrics file
telemetricsFile = new File(System.getProperty("java.io.tmpdir"), evaluator.evaluate(jacocoDestinationFileName, String.class));
}
// assert that JaCoCo created the telemetrics file (and thus the agent ran)
assertThat(telemetricsFile.exists(), is(true));
// assert that the telemetrics file contains something
assertThat(telemetricsFile.length(), is(greaterThan(0L)));
}
Aggregations