This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 2df5540  Don't overwrite integration tests longs if container 
restarted (#3080)
2df5540 is described below

commit 2df55405ede20bdcfa3d2a50a2e3266c48fb54fe
Author: Ivan Kelly <[email protected]>
AuthorDate: Wed Nov 28 19:57:09 2018 +0100

    Don't overwrite integration tests longs if container restarted (#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.
---
 .../apache/pulsar/tests/integration/utils/DockerUtils.java | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git 
a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/utils/DockerUtils.java
 
b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/utils/DockerUtils.java
index 5148a36..8fdd968 100644
--- 
a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/utils/DockerUtils.java
+++ 
b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/utils/DockerUtils.java
@@ -71,6 +71,11 @@ public class DockerUtils {
         // 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)
@@ -116,8 +121,13 @@ public class DockerUtils {
         // 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];

Reply via email to