From 6540b1f3837042cf0be8f0ade2ec71fd531996d6 Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Sun, 31 Jan 2016 22:29:39 +0100 Subject: [PATCH] Remove Docker container after launch script test execution Closes gh-5059 --- .../launchscript/SysVinitLaunchScriptIT.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java index 22ab687d1e..3adef38ba5 100644 --- a/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java +++ b/spring-boot-integration-tests/spring-boot-launch-script-tests/src/test/java/org/springframework/boot/launchscript/SysVinitLaunchScriptIT.java @@ -206,24 +206,29 @@ public class SysVinitLaunchScriptIT { DockerClient docker = createClient(); String imageId = buildImage(docker); String container = createContainer(docker, imageId, script); - copyFilesToContainer(docker, container, script); - docker.startContainerCmd(container).exec(); - StringBuilder output = new StringBuilder(); - AttachContainerResultCallback resultCallback = docker - .attachContainerCmd(container).withStdOut(true).withStdErr(true) - .withFollowStream(true).withLogs(true) - .exec(new AttachContainerResultCallback() { - - @Override - public void onNext(Frame item) { - output.append(new String(item.getPayload())); - super.onNext(item); - } - - }); - resultCallback.awaitCompletion(60, TimeUnit.SECONDS).close(); - docker.waitContainerCmd(container).exec(); - return output.toString(); + try { + copyFilesToContainer(docker, container, script); + docker.startContainerCmd(container).exec(); + StringBuilder output = new StringBuilder(); + AttachContainerResultCallback resultCallback = docker + .attachContainerCmd(container).withStdOut(true).withStdErr(true) + .withFollowStream(true).withLogs(true) + .exec(new AttachContainerResultCallback() { + + @Override + public void onNext(Frame item) { + output.append(new String(item.getPayload())); + super.onNext(item); + } + + }); + resultCallback.awaitCompletion(60, TimeUnit.SECONDS).close(); + docker.waitContainerCmd(container).exec(); + return output.toString(); + } + finally { + docker.removeContainerCmd(container).exec(); + } } private DockerClient createClient() {