Skip to content

Commit

Permalink
Don't overwrite integration tests longs if container restarted (apach…
Browse files Browse the repository at this point in the history
…e#3080)

In the arquillian tests, processes were restarted using supervisorctl,
which preserved the contents of the filesystem. This was changed in
the testcontainers change to restart the whole container, which
obliterates the filesystem.

When a container is stopped, the logs are copied to the target
directory. In the case of multiple restarts the logs from the later
restarts were overwriting the logs from earlier restarts so the older
logs were lost.

This PR adds a check to ensure that we don't overwrite old logs and
appends a number to the log if a old log exists.
  • Loading branch information
ivankelly authored and sijie committed Nov 28, 2018
1 parent f74b939 commit 2df5540
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public static void dumpContainerLogToTarget(DockerClient dockerClient, String co
// this removes it to be consistent with what docker ps shows.
final String containerName = inspectContainerResponse.getName().replace("/","");
File output = new File(getTargetDirectory(containerName), "docker.log");
int i = 0;
while (output.exists()) {
LOG.info("{} exists, incrementing", output);
output = new File(getTargetDirectory(containerName), "docker." + i++ + ".log");
}
try (FileOutputStream os = new FileOutputStream(output)) {
CompletableFuture<Boolean> future = new CompletableFuture<>();
dockerClient.logContainerCmd(containerName).withStdOut(true)
Expand Down Expand Up @@ -116,8 +121,13 @@ public static void dumpContainerDirToTargetCompressed(DockerClient dockerClient,
// docker api returns names prefixed with "/", it's part of it's legacy design,
// this removes it to be consistent with what docker ps shows.
final String containerName = inspectContainerResponse.getName().replace("/","");
File output = new File(getTargetDirectory(containerName),
(path.replace("/", "-") + ".tar.gz").replaceAll("^-", ""));
String baseName = path.replace("/", "-").replaceAll("^-", "");
File output = new File(getTargetDirectory(containerName), baseName + ".tar.gz");
int i = 0;
while (output.exists()) {
LOG.info("{} exists, incrementing", output);
output = new File(getTargetDirectory(containerName), baseName + "_" + i++ + ".tar.gz");
}
try (InputStream dockerStream = dockerClient.copyArchiveFromContainerCmd(containerId, path).exec();
OutputStream os = new GZIPOutputStream(new FileOutputStream(output))) {
byte[] block = new byte[READ_BLOCK_SIZE];
Expand Down

0 comments on commit 2df5540

Please sign in to comment.