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));
}
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)));
}
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));
}
}
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;
}
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();
}
Aggregations