use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class DockerContainerTest method shouldRemoveContainerWithForce.
@Test
public void shouldRemoveContainerWithForce() throws Exception {
Docker docker = Docker.auto();
Platform platform = mock(Platform.class);
Application application = mock(Application.class, "App");
Application removeApp = mock(Application.class, "Inspect");
DockerContainer container = new DockerContainer("foo", OptionsByType.of(docker));
when(application.getPlatform()).thenReturn(platform);
when(platform.launch(any(MetaClass.class), anyVararg())).thenReturn(removeApp);
container.onAddingTo(application);
container.remove(true);
ArgumentCaptor<MetaClass> captor = ArgumentCaptor.forClass(MetaClass.class);
verify(platform).launch(captor.capture(), anyVararg());
OptionsByType optionsByType = OptionsByType.empty();
Remove.RemoveContainer remove = (Remove.RemoveContainer) captor.getValue();
assertThat(remove, is(notNullValue()));
remove.onLaunch(platform, optionsByType);
Arguments arguments = optionsByType.get(Arguments.class);
List<String> values = arguments.resolve(mock(Platform.class), OptionsByType.empty());
assertThat(values, contains("rm", "--force", "foo"));
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class DockerImageTest method shouldCloseWithApplicationAndUseOverridingBehaviour.
@Test
public void shouldCloseWithApplicationAndUseOverridingBehaviour() throws Exception {
Application application = mock(Application.class);
DockerImage image = new DockerImage(Arrays.asList("foo", "bar"), OptionsByType.empty());
ImageCloseBehaviour behaviourApp = mock(ImageCloseBehaviour.class, "1");
ImageCloseBehaviour behaviourOverride = mock(ImageCloseBehaviour.class, "2");
when(application.getOptions()).thenReturn(OptionsByType.of(behaviourApp));
image.onClosed(application, OptionsByType.of(behaviourOverride));
verify(behaviourApp, never()).accept(same(image));
verify(behaviourOverride).accept(same(image));
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class DockerImageTest method shouldRunInspect.
@Test
public void shouldRunInspect() throws Exception {
Docker docker = Docker.auto();
Platform platform = mock(Platform.class);
Application application = mock(Application.class, "App");
Application inspectApp = mock(Application.class, "Inspect");
Inspect inspect = mock(Inspect.class);
DockerImage image = new DockerImage(Arrays.asList("foo", "bar"), OptionsByType.of(docker));
DockerImage imageSpy = spy(image);
when(application.getPlatform()).thenReturn(platform);
when(platform.launch(any(MetaClass.class))).thenReturn(inspectApp);
doReturn(inspect).when(imageSpy).createInspectCommand();
imageSpy.onAddingTo(application);
imageSpy.inspect();
verify(inspect).run(same(platform), same(docker));
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class RemoteJavaApplicationLauncherTest method shouldEnableRemoteDebugAndConnectBackToDebugger.
/**
* Start the application with remote debugging enabled using {@link RemoteDebugging.Behavior#ATTACH_TO_DEBUGGER}
* and assert the process connects back to the debugger
*/
@Ignore("This test can cause JVMs to crash on various platforms. Disabled for now until there is a fix.")
@Test
public void shouldEnableRemoteDebugAndConnectBackToDebugger() throws Exception {
// Make sure we can run the JDB debugger otherwise we cannot run this test
Assume.assumeThat(hasJDB(), is(true));
InetAddress debugAddress = LocalPlatform.get().getAddress();
Capture<Integer> debugPort = new Capture<>(LocalPlatform.get().getAvailablePorts());
CapturingApplicationConsole jdbConsole = new CapturingApplicationConsole();
try (Application jdb = LocalPlatform.get().launch(Application.class, Executable.named(findJDB()), Argument.of("-connect"), Argument.of(String.format("com.sun.jdi.SocketListen:port=%d", debugPort.get())), Console.of(jdbConsole))) {
Eventually.assertThat("JDB did not start properly", invoking(jdbConsole).getCapturedOutputLines(), hasItem(startsWith("Listening at address:")));
CapturingApplicationConsole console = new CapturingApplicationConsole();
RemotePlatform platform = getRemotePlatform();
try (JavaApplication application = platform.launch(JavaApplication.class, ClassName.of(SleepingApplication.class), RemoteDebugging.enabled().attach().at(new RemoteDebugging.TransportAddress(debugAddress, debugPort)), Console.of(console))) {
Eventually.assertThat(invoking(console).getCapturedOutputLines(), hasItem(startsWith("Now sleeping")));
Eventually.assertThat("Application did not connect back to JDB", invoking(jdbConsole).getCapturedOutputLines(), hasItem(containsString("VM Started:")));
}
}
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class HttpDeployer method undeploy.
@Override
public DeployedArtifacts undeploy(DeployedArtifacts deployedArtifacts, Platform platform, Option... deploymentOptions) {
DeployedArtifacts failedArtifacts = new DeployedArtifacts();
for (File file : deployedArtifacts) {
CapturingApplicationConsole console = new CapturingApplicationConsole();
try (Application application = platform.launch(Application.class, Executable.named("rm"), Argument.of(StringHelper.doubleQuoteIfNecessary(file.toString())), DisplayName.of("Undeploy"))) {
if (application.waitFor() != 0) {
StringBuilder message = new StringBuilder("Error undeploying ").append(file.toString()).append(" - rm returned ").append(application.exitValue()).append("\n").append("rm output:");
for (String line : console.getCapturedOutputLines()) {
message.append(line);
}
for (String line : console.getCapturedErrorLines()) {
message.append(line);
}
failedArtifacts.add(file);
}
}
}
return failedArtifacts;
}
Aggregations