Search in sources :

Example 1 with JavaApplication

use of com.oracle.bedrock.runtime.java.JavaApplication in project oracle-bedrock by coherence-community.

the class RemoteJavaApplicationLauncherTest method shouldLaunchJavaApplicationRemotely.

/**
 * Ensure that we can launch Java remotely.
 */
@Test
public void shouldLaunchJavaApplicationRemotely() throws Exception {
    RemotePlatform platform = getRemotePlatform();
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), Argument.of("3"), Console.system())) {
        assertThat(application.waitFor(), is(0));
        application.close();
        assertThat(application.exitValue(), is(0));
    }
}
Also used : SleepingApplication(com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication) JavaApplication(com.oracle.bedrock.runtime.java.JavaApplication) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Example 2 with JavaApplication

use of com.oracle.bedrock.runtime.java.JavaApplication 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 3 with JavaApplication

use of com.oracle.bedrock.runtime.java.JavaApplication 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 4 with JavaApplication

use of com.oracle.bedrock.runtime.java.JavaApplication 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 5 with JavaApplication

use of com.oracle.bedrock.runtime.java.JavaApplication in project oracle-bedrock by coherence-community.

the class RemoteJavaApplicationLauncherTest method shouldSubmitCallableBack.

@Test
public void shouldSubmitCallableBack() throws Exception {
    Platform platform = getRemotePlatform();
    try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(EventingApplication.class), IPv4Preferred.yes())) {
        EventingApplication.GetIntCallable.value = 1234;
        CompletableFuture<Integer> result = application.submit(new EventingApplication.RoundTripCallable());
        Assert.assertThat(result.get(), is(1234));
    }
}
Also used : 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) EventingApplication(com.oracle.bedrock.runtime.remote.java.applications.EventingApplication) AbstractRemoteTest(com.oracle.bedrock.runtime.remote.AbstractRemoteTest) Test(org.junit.Test)

Aggregations

JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)37 Test (org.junit.Test)32 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)20 AbstractRemoteTest (com.oracle.bedrock.runtime.remote.AbstractRemoteTest)17 SleepingApplication (com.oracle.bedrock.runtime.remote.java.applications.SleepingApplication)15 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)12 Platform (com.oracle.bedrock.runtime.Platform)9 CapturingApplicationConsole (com.oracle.bedrock.runtime.console.CapturingApplicationConsole)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 EventingApplication (com.oracle.bedrock.runtime.remote.java.applications.EventingApplication)7 SleepingApplication (applications.SleepingApplication)4 OptionsByType (com.oracle.bedrock.OptionsByType)4 Application (com.oracle.bedrock.runtime.Application)4 File (java.io.File)4 RemoteEventListener (com.oracle.bedrock.runtime.concurrent.RemoteEventListener)3 BufferedReader (java.io.BufferedReader)3 ExpressionEvaluator (com.oracle.bedrock.lang.ExpressionEvaluator)2 Timeout (com.oracle.bedrock.options.Timeout)2 RemoteEvent (com.oracle.bedrock.runtime.concurrent.RemoteEvent)2 JUnitTestRun (com.oracle.bedrock.testsupport.junit.JUnitTestRun)2