db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r1076335 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit: BaseJDBCTestCase.java DropDatabaseSetup.java
Date Wed, 02 Mar 2011 19:11:26 GMT
Author: kristwaa
Date: Wed Mar  2 19:11:25 2011
New Revision: 1076335

URL: http://svn.apache.org/viewvc?rev=1076335&view=rev
Log:
DERBY-4915: test failure in OSReadOnlyTest in assertDirectoryDeleted

Make BaseJDBCTestCase.assertDirectoryDeleted retry up to three times before
giving up and raising an assert failure.
Make DropDatabaseSetup.removeDir use the above mentioned method, since it is
also failing to delete files on Windows.

Patch file: derby-4915-1b-more_persistent_delete.diff

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=1076335&r1=1076334&r2=1076335&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Wed
Mar  2 19:11:25 2011
@@ -1468,19 +1468,49 @@ public abstract class BaseJDBCTestCase
      * <p>
      * This method will attempt to delete all the files inside the root
      * directory, even if one of the delete operations fails.
+     * <p>
+     * After having tried to delete all files once, any remaining files will be
+     * attempted deleted again after a pause. This is repeated twice, resulting
+     * in three failed delete attempts for any single file before the method
+     * gives up and raises a failure.
+     * <p>
+     * The approach above will mask any slowness involved in releasing file
+     * handles, but should fail if a file handle actually isn't released on a
+     * system that doesn't allow deletes on files with open handles (i.e.
+     * Windows). It will also mask slowness caused by the JVM, the file system,
+     * or the operation system.
      *
      * @param dir the root to start deleting from (root will also be deleted)
      */
     public static void assertDirectoryDeleted(File dir) {
         File[] fl = null;
-        try {
-            fl = PrivilegedFileOpsForTests.persistentRecursiveDelete(dir);
-        } catch (FileNotFoundException fnfe) {
-            fail("directory doesn't exist: " +
-                    PrivilegedFileOpsForTests.getAbsolutePath(dir));
-        }
-        if (fl.length == 0) {
-            return;
+        int attempts = 0;
+        while (attempts < 3) {
+            try {
+                fl = PrivilegedFileOpsForTests.persistentRecursiveDelete(dir);
+                attempts++;
+            } catch (FileNotFoundException fnfe) {
+                fail("directory doesn't exist: " +
+                        PrivilegedFileOpsForTests.getAbsolutePath(dir));
+            }
+            if (fl.length == 0) {
+                return;
+            } else {
+                // Print the list of remaining files to stdout for debugging.
+                StringBuffer sb = new StringBuffer();
+                sb.append("<assertDirectoryDeleted> attempt ").append(attempts).
+                        append(" left ").append(fl.length).
+                        append(" files/dirs behind:");
+                for (int i=0; i < fl.length; i++) {
+                    sb.append(' ').append(i).append('=').append(fl[i]);
+                }
+                System.out.println(sb);
+                try {
+                    Thread.sleep(attempts * 1000);
+                } catch (InterruptedException ie) {
+                    // Ignore
+                }
+            }
         }
 
         // If we failed to delete some of the files, list them and obtain some

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java?rev=1076335&r1=1076334&r2=1076335&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
Wed Mar  2 19:11:25 2011
@@ -116,25 +116,9 @@ class DropDatabaseSetup extends BaseTest
         if (!dir.exists())
             return;
 
-        String[] list = dir.list();
-
-        // Some JVMs return null for File.list() when the
-        // directory is empty.
-        if (list != null) {
-            for (int i = 0; i < list.length; i++) {
-                File entry = new File(dir, list[i]);
-
-                if (entry.isDirectory()) {
-                    removeDir(entry);
-                } else {
-                    assertTrue(entry.getPath(), entry.delete());
-                }
-            }
-        }
-
-        assertTrue(dir.getPath(), dir.delete());
+        BaseJDBCTestCase.assertDirectoryDeleted(dir);
     }
-    
+
     /**
      * Remove all the files in the list
      * @param list the list of files that will be deleted



Mime
View raw message