Search in sources :

Example 11 with LocalPlatform

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);
    }
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) Timeout(com.oracle.bedrock.options.Timeout) Application(com.oracle.bedrock.runtime.Application) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 12 with LocalPlatform

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);
    }
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) PipedApplicationConsole(com.oracle.bedrock.runtime.console.PipedApplicationConsole) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Properties(java.util.Properties) OptionsByType(com.oracle.bedrock.OptionsByType) Application(com.oracle.bedrock.runtime.Application) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 13 with LocalPlatform

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")));
    }
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) Test(org.junit.Test)

Example 14 with LocalPlatform

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)));
}
Also used : SleepingApplication(applications.SleepingApplication) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) File(java.io.File) ExpressionEvaluator(com.oracle.bedrock.lang.ExpressionEvaluator) Test(org.junit.Test)

Example 15 with LocalPlatform

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)));
}
Also used : SleepingApplication(applications.SleepingApplication) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) File(java.io.File) ExpressionEvaluator(com.oracle.bedrock.lang.ExpressionEvaluator) Test(org.junit.Test)

Aggregations

LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)16 Test (org.junit.Test)7 OptionsByType (com.oracle.bedrock.OptionsByType)6 MetaClass (com.oracle.bedrock.runtime.MetaClass)4 CoherenceClusterMember (com.oracle.bedrock.runtime.coherence.CoherenceClusterMember)4 ClassPath (com.oracle.bedrock.runtime.java.ClassPath)4 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4 File (java.io.File)3 IOException (java.io.IOException)3 SleepingApplication (applications.SleepingApplication)2 ExpressionEvaluator (com.oracle.bedrock.lang.ExpressionEvaluator)2 Application (com.oracle.bedrock.runtime.Application)2 IsServiceRunning (com.oracle.bedrock.runtime.coherence.callables.IsServiceRunning)2 UnknownHostException (java.net.UnknownHostException)2 Timeout (com.oracle.bedrock.options.Timeout)1 CoherenceCacheServer (com.oracle.bedrock.runtime.coherence.CoherenceCacheServer)1 CapturingApplicationConsole (com.oracle.bedrock.runtime.console.CapturingApplicationConsole)1 PipedApplicationConsole (com.oracle.bedrock.runtime.console.PipedApplicationConsole)1 JavaVirtualMachine (com.oracle.bedrock.runtime.java.JavaVirtualMachine)1