camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1332591 - in /camel/trunk/components: camel-test/src/main/java/org/apache/camel/test/TestSupport.java camel-test/src/main/java/org/apache/camel/test/junit4/TestSupport.java camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java
Date Tue, 01 May 2012 09:42:33 GMT
Author: davsclaus
Date: Tue May  1 09:42:32 2012
New Revision: 1332591

URL: http://svn.apache.org/viewvc?rev=1332591&view=rev
Log:
deleteDirectory method in camel-test modules now returns a boolean with status. This allows
to ignore issues such as pesky Windows may fail for no good reason really.

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

Modified: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/TestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/TestSupport.java?rev=1332591&r1=1332590&r2=1332591&view=diff
==============================================================================
--- camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/TestSupport.java
(original)
+++ camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/TestSupport.java
Tue May  1 09:42:32 2012
@@ -413,26 +413,51 @@ public abstract class TestSupport extend
      * Recursively delete a directory, useful to zapping test data
      *
      * @param file the directory to be deleted
+     * @return <tt>false</tt> if error deleting directory
      */
-    public static void deleteDirectory(String file) {
-        deleteDirectory(new File(file));
+    public static boolean deleteDirectory(String file) {
+        return deleteDirectory(new File(file));
     }
 
     /**
      * Recursively delete a directory, useful to zapping test data
      *
      * @param file the directory to be deleted
+     * @return <tt>false</tt> if error deleting directory
      */
-    public static void deleteDirectory(File file) {
+    public static boolean 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
+                }
+            }
+        }
+        return !exists;
+    }
+
+    private static void recursivelyDeleteDirectory(File file) {
+        if (!file.exists()) {
+            return;
+        }
+
         if (file.isDirectory()) {
             File[] files = file.listFiles();
             for (File child : files) {
-                deleteDirectory(child);
+                recursivelyDeleteDirectory(child);
             }
         }
-
-        if (file.exists()) {
-            assertTrue("Deletion of file: " + file.getAbsolutePath() + " failed", file.delete());
+        boolean success = file.delete();
+        if (!success) {
+            LOG.warn("Deletion of file: " + file.getAbsolutePath() + " failed");
         }
     }
 

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=1332591&r1=1332590&r2=1332591&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
Tue May  1 09:42:32 2012
@@ -399,17 +399,19 @@ public abstract class TestSupport extend
      * Recursively delete a directory, useful to zapping test data
      *
      * @param file the directory to be deleted
+     * @return <tt>false</tt> if error deleting directory
      */
-    public static void deleteDirectory(String file) {
-        deleteDirectory(new File(file));
+    public static boolean deleteDirectory(String file) {
+        return deleteDirectory(new File(file));
     }
 
     /**
      * Recursively delete a directory, useful to zapping test data
      *
      * @param file the directory to be deleted
+     * @return <tt>false</tt> if error deleting directory
      */
-    public static void deleteDirectory(File file) {
+    public static boolean deleteDirectory(File file) {
         int tries = 0;
         int maxTries = 5;
         boolean exists = true;
@@ -425,9 +427,7 @@ public abstract class TestSupport extend
                 }
             }
         }
-        if (exists) {
-            throw new RuntimeException("Deletion of file " + file + " failed");
-        }
+        return !exists;
     }
 
     private static void recursivelyDeleteDirectory(File file) {

Modified: camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java?rev=1332591&r1=1332590&r2=1332591&view=diff
==============================================================================
--- camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java
(original)
+++ camel/trunk/components/camel-testng/src/main/java/org/apache/camel/testng/TestSupport.java
Tue May  1 09:42:32 2012
@@ -387,26 +387,51 @@ public abstract class TestSupport extend
      * Recursively delete a directory, useful to zapping test data
      *
      * @param file the directory to be deleted
+     * @return <tt>false</tt> if error deleting directory
      */
-    public static void deleteDirectory(String file) {
-        deleteDirectory(new File(file));
+    public static boolean deleteDirectory(String file) {
+        return deleteDirectory(new File(file));
     }
 
     /**
      * Recursively delete a directory, useful to zapping test data
      *
      * @param file the directory to be deleted
+     * @return <tt>false</tt> if error deleting directory
      */
-    public static void deleteDirectory(File file) {
+    public static boolean 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
+                }
+            }
+        }
+        return !exists;
+    }
+
+    private static void recursivelyDeleteDirectory(File file) {
+        if (!file.exists()) {
+            return;
+        }
+
         if (file.isDirectory()) {
             File[] files = file.listFiles();
             for (File child : files) {
-                deleteDirectory(child);
+                recursivelyDeleteDirectory(child);
             }
         }
-
-        if (file.exists()) {
-            assertTrue(file.delete(), "Deletion of file: " + file.getAbsolutePath() + " failed");
+        boolean success = file.delete();
+        if (!success) {
+            LOG.warn("Deletion of file: " + file.getAbsolutePath() + " failed");
         }
     }
 



Mime
View raw message