Search in sources :

Example 1 with SleepingApplication

use of com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication in project oracle-bedrock by coherence-community.

the class RemoteJavaApplicationLauncherTest method shouldInheritRuntimeProperties.

/**
 * Ensure that {@link JavaApplication}s correctly inherits arguments based on system properties
 * starting with bedrock.runtime.inherit.xxx=
 */
@Test
public void shouldInheritRuntimeProperties() throws Exception {
    // set a system property for this process
    System.getProperties().setProperty("bedrock.runtime.inherit.property", "-Dmessage=hello");
    // build and start the SleepingApplication
    Platform platform = getRemotePlatform();
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), IPv4Preferred.yes())) {
        // ask the application for the current system property value
        String message = application.getSystemProperty("message");
        // ensure that the application has the system property
        Assert.assertThat(message, is("hello"));
    } finally {
        // remove the system property to clean up
        System.getProperties().remove("bedrock.runtime.inherit.property");
    }
}
Also used : SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) Platform(com.oracle.bedrock.runtime.Platform) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 2 with SleepingApplication

use of com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication in project oracle-bedrock by coherence-community.

the class RemoteJavaApplicationLauncherTest method shouldLaunchJavaApplicationUsingSystemPropertyWithSpaces.

/**
 * Ensure that {@link JavaApplication}s can is launched with a system-property
 * that contains spaces.
 */
@Test
public void shouldLaunchJavaApplicationUsingSystemPropertyWithSpaces() throws Exception {
    RemotePlatform platform = getRemotePlatform();
    // set a System-Property for the SleepingApplication (we'll request it back)
    String message = "Hello World";
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), SystemProperty.of("message", message), IPv4Preferred.yes())) {
        // request the system property from the SleepingApplication
        String propertyValue = application.invoke(new GetSystemProperty("message"));
        Assert.assertThat(propertyValue, is(message));
    }
}
Also used : SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) GetSystemProperty(com.oracle.bedrock.runtime.concurrent.callable.GetSystemProperty) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 3 with SleepingApplication

use of com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication in project oracle-bedrock by coherence-community.

the class RemoteJavaApplicationLauncherTest method shouldSetWorkingDirectory.

@Test
public void shouldSetWorkingDirectory() throws Exception {
    String appName = "sleeping";
    File folder = temporaryFolder.newFolder();
    String appNameSanitized = PlatformSeparators.autoDetect().asSanitizedFileName(appName);
    File expectedDirectory = new File(folder, appNameSanitized);
    // build and start the SleepingApplication
    Platform platform = getRemotePlatform();
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), DisplayName.of(appName), WorkingDirectory.subDirectoryOf(folder))) {
        String dir = application.invoke(new GetWorkingDirectory());
        Assert.assertThat(dir, is(expectedDirectory.getCanonicalPath()));
        WorkingDirectory workingDir = application.getOptions().get(WorkingDirectory.class);
        Assert.assertThat(workingDir, is(notNullValue()));
        Assert.assertThat(workingDir.getValue(), is((Object) expectedDirectory));
    }
}
Also used : SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) WorkingDirectory(com.oracle.bedrock.runtime.options.WorkingDirectory) Platform(com.oracle.bedrock.runtime.Platform) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 4 with SleepingApplication

use of com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication 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));
    }
}
Also used : SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) Platform(com.oracle.bedrock.runtime.Platform) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 5 with SleepingApplication

use of com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication 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));
    }
}
Also used : SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) Platform(com.oracle.bedrock.runtime.Platform) LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Aggregations

JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)5 AbstractRemoteTest (com.oracle.bedrock.runtime.remote.AbstractRemoteTest)5 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)5 SleepingApplication (com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication)5 Test (org.junit.Test)5 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)4 Platform (com.oracle.bedrock.runtime.Platform)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 GetSystemProperty (com.oracle.bedrock.runtime.concurrent.callable.GetSystemProperty)1 WorkingDirectory (com.oracle.bedrock.runtime.options.WorkingDirectory)1 File (java.io.File)1