camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1169721 - /camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java
Date Mon, 12 Sep 2011 12:52:21 GMT
Author: cschneider
Date: Mon Sep 12 12:52:20 2011
New Revision: 1169721

URL: http://svn.apache.org/viewvc?rev=1169721&view=rev
Log:
Allow several tries to delete a directory as on windows the directory can still be locked
while a server process is shutting down

Modified:
    camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java

Modified: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java?rev=1169721&r1=1169720&r2=1169721&view=diff
==============================================================================
--- camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java
(original)
+++ camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java
Mon Sep 12 12:52:20 2011
@@ -410,15 +410,41 @@ public abstract class TestSupport extend
      * @param file the directory to be deleted
      */
     public static void deleteDirectory(File file) {
+        int tries = 0;
+        int maxTries = 5;
+        boolean exists = true;
+        while (exists && (tries < maxTries)) {
+            recursivelyDeleteDirectory(file);
+            tries ++;
+            exists = file.exists(); 
+            if (exists) {
+                try {
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                    // Ignore
+                }
+            }
+        }
+        if (exists) {
+            throw new RuntimeException("Deletion of file " + file + " failed");
+        }
+    }
+
+    private static void recursivelyDeleteDirectory(File file) {
+        if (!file.exists()) {
+            return;
+        }
+        
         if (file.isDirectory()) {
             File[] files = file.listFiles();
             for (int i = 0; i < files.length; i++) {
-                deleteDirectory(files[i]);
+                recursivelyDeleteDirectory(files[i]);
+            }
+        } else {
+            boolean success = file.delete();
+            if (!success) {
+                LOG.warn("Deletion of file: " + file.getAbsolutePath() + " failed");
             }
-        }
-
-        if (file.exists()) {
-            assertTrue("Deletion of file: " + file.getAbsolutePath() + " failed", file.delete());
         }
     }
 



Mime
View raw message