Search in sources :

Example 26 with Application

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

the class DockerImageTest method shouldCloseWithApplicationAndUseApplicationCloseBehaviour.

@Test
public void shouldCloseWithApplicationAndUseApplicationCloseBehaviour() throws Exception {
    Application application = mock(Application.class);
    DockerImage image = new DockerImage(Arrays.asList("foo", "bar"), OptionsByType.empty());
    ImageCloseBehaviour behaviourApp = mock(ImageCloseBehaviour.class);
    when(application.getOptions()).thenReturn(OptionsByType.of(behaviourApp));
    image.onClosed(application, OptionsByType.empty());
    verify(behaviourApp).accept(same(image));
}
Also used : ImageCloseBehaviour(com.oracle.bedrock.runtime.docker.options.ImageCloseBehaviour) Application(com.oracle.bedrock.runtime.Application) Test(org.junit.Test)

Example 27 with Application

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

the class DockerImageTest method shouldAddAsFeature.

@Test
public void shouldAddAsFeature() throws Exception {
    Platform platform = mock(Platform.class);
    Application application = mock(Application.class);
    DockerImage image = new DockerImage(Arrays.asList("foo", "bar"), OptionsByType.empty());
    when(application.getPlatform()).thenReturn(platform);
    image.onAddingTo(application);
    assertThat(image.getApplication(), is(sameInstance(application)));
}
Also used : Platform(com.oracle.bedrock.runtime.Platform) Application(com.oracle.bedrock.runtime.Application) Test(org.junit.Test)

Example 28 with Application

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

the class AbstractFunctionalTest method ensureJavaImage.

/**
 * Ensure that a Java image can be created on the target platform
 * <p>
 * This method requires the <code>oracle.bedrock.container.tests.jre</code>
 * System property to be set to point to the location of a Java 8 <strong>JRE</strong>
 * install for linux-x64 as a tar.gz file. This is typically what is downloaded
 * from Oracle's Java site.
 */
public static void ensureJavaImage(Platform platform, TemporaryFolder temporaryFolder) throws Exception {
    // ----- use the Images command to list the images on the platform to see if the java image already exists -----
    CapturingApplicationConsole console = new CapturingApplicationConsole();
    String format = Images.FORMAT_REPOSITORY + ':' + Images.FORMAT_TAG;
    try (Application images = platform.launch(Images.list().format(format), Console.of(console))) {
        if (images.waitFor() == 0) {
            boolean present = console.getCapturedOutputLines().stream().filter((line) -> line.equals(javaImageName)).findFirst().isPresent();
            if (present) {
                return;
            }
        }
    }
    // ----- the image does not exist so we need to build it -----
    File installerFile = findJavaInstaller();
    // ----- create a temporary working directory -----
    File workingDirectory = temporaryFolder.newFolder();
    File dockerFile = new File(workingDirectory, "Dockerfile");
    Path dockerFileTemplate = Paths.get(DockerFunctionalTest.class.getResource("/JavaDockerFile").toURI());
    // ----- copy the Dockerfile template to the working directory -----
    Files.copy(dockerFileTemplate, dockerFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    // ----- copy the JRE .tar.gz file to the working directory -----
    Files.copy(installerFile.toPath(), new File(workingDirectory, "jre.tar.gz").toPath(), StandardCopyOption.REPLACE_EXISTING);
    try (Application application = platform.launch(Build.fromDockerFile().withTags(javaImageName), ImageCloseBehaviour.none(), WorkingDirectory.at(workingDirectory))) {
        Assume.assumeThat("An error occurred building the Java Docker image", application.waitFor(), is(0));
    }
}
Also used : Path(java.nio.file.Path) CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) Application(com.oracle.bedrock.runtime.Application) File(java.io.File)

Example 29 with Application

use of com.oracle.bedrock.runtime.Application in project helidon by oracle.

the class MainTest method startTheApplication.

/**
 * Start the application using the application jar and classpath
 *
 * @param appJarPath    Path to jar file with application
 * @param javaArgs      Additional java arguments to pass
 * @throws Exception    Error starting the application
 */
HelidonApplication startTheApplication(String appJarPath, List<String> javaArgs) throws Exception {
    int port = localPlatform.getAvailablePorts().next();
    Arguments args = toArguments(appJarPath, javaArgs, null, port);
    Application application = localPlatform.launch("java", args);
    HelidonApplication helidonApplication = new HelidonApplication(application, port);
    helidonApplication.waitForApplicationUp();
    return helidonApplication;
}
Also used : Arguments(com.oracle.bedrock.runtime.options.Arguments) Application(com.oracle.bedrock.runtime.Application)

Example 30 with Application

use of com.oracle.bedrock.runtime.Application in project helidon by oracle.

the class MainTest method runExitOnStartedTest.

private void runExitOnStartedTest(String edition) throws Exception {
    int port = localPlatform.getAvailablePorts().next();
    Arguments args = toArguments(editionToJarPath(edition), List.of("-Dexit.on.started=!"), null, port);
    CapturingApplicationConsole console = new CapturingApplicationConsole();
    Application application = localPlatform.launch("java", args, Console.of(console));
    Queue<String> stdOut = console.getCapturedOutputLines();
    long maxTime = System.currentTimeMillis() + (10 * 1000);
    do {
        if (stdOut.stream().anyMatch(line -> line.contains("exit.on.started"))) {
            return;
        }
        Thread.sleep(500);
    } while (System.currentTimeMillis() < maxTime);
    String eol = System.getProperty("line.separator");
    Assertions.fail("quickstart " + edition + " did not exit as expected." + eol + eol + "stdOut: " + stdOut + eol + eol + " stdErr: " + console.getCapturedErrorLines());
    application.close();
}
Also used : Arguments(com.oracle.bedrock.runtime.options.Arguments) CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) Application(com.oracle.bedrock.runtime.Application)

Aggregations

Application (com.oracle.bedrock.runtime.Application)57 Test (org.junit.Test)23 CapturingApplicationConsole (com.oracle.bedrock.runtime.console.CapturingApplicationConsole)22 Platform (com.oracle.bedrock.runtime.Platform)16 Arguments (com.oracle.bedrock.runtime.options.Arguments)13 OptionsByType (com.oracle.bedrock.OptionsByType)12 File (java.io.File)12 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)11 Timeout (com.oracle.bedrock.options.Timeout)9 MetaClass (com.oracle.bedrock.runtime.MetaClass)9 List (java.util.List)7 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)6 Remove (com.oracle.bedrock.runtime.docker.commands.Remove)5 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)5 InetAddress (java.net.InetAddress)5 SleepingApplication (applications.SleepingApplication)4 ContainerCloseBehaviour (com.oracle.bedrock.runtime.docker.options.ContainerCloseBehaviour)4 TimeUnit (java.util.concurrent.TimeUnit)4 Collectors (java.util.stream.Collectors)4 EventingApplication (classloader.applications.EventingApplication)3