Author: kristwaa
Date: Mon Aug 8 13:23:59 2011
New Revision: 1154956
URL: http://svn.apache.org/viewvc?rev=1154956&view=rev
Log:
DERBY-4915: test failure in OSReadOnlyTest in assertDirectoryDeleted
Merged fix from trunk (revisions 1076335 and 1078608), manually edited
DropDatabaseSetup due to conflict.
Modified:
db/derby/code/branches/10.7/ (props changed)
db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
Propchange: db/derby/code/branches/10.7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug 8 13:23:59 2011
@@ -1 +1 @@
-/db/derby/code/trunk:1035603,1036769,1038514,1038813,1039084,1039268,1040658,1041338,1043227,1043389,1044096,1051026,1053724,1055169,1059888,1060480,1062096,1063809,1065061,1066290,1067250,1067357,1069661,1071463,1071886,1076387,1078461,1078693,1081072,1081455,1081568,1085078,1091000,1097247,1103681,1103718,1129136,1130632,1130895,1131272,1132664,1136363,1138341,1138444,1139449,1141924
+/db/derby/code/trunk:1035603,1036769,1038514,1038813,1039084,1039268,1040658,1041338,1043227,1043389,1044096,1051026,1053724,1055169,1059888,1060480,1062096,1063809,1065061,1066290,1067250,1067357,1069661,1071463,1071886,1076335,1076387,1078461,1078608,1078693,1081072,1081455,1081568,1085078,1091000,1097247,1103681,1103718,1129136,1130632,1130895,1131272,1132664,1136363,1138341,1138444,1139449,1141924
Modified: db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=1154956&r1=1154955&r2=1154956&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
(original)
+++ db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
Mon Aug 8 13:23:59 2011
@@ -1393,19 +1393,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, resulting
+ * in multiple 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 < 4) {
+ try {
+ Thread.sleep(attempts * 2000);
+ } catch (InterruptedException ie) {
+ // Ignore
+ }
+ 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);
+ }
}
// If we failed to delete some of the files, list them and obtain some
Modified: db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java?rev=1154956&r1=1154955&r2=1154956&view=diff
==============================================================================
--- db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
(original)
+++ db/derby/code/branches/10.7/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
Mon Aug 8 13:23:59 2011
@@ -116,22 +116,6 @@ 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);
}
}
|