You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2012/06/28 13:47:30 UTC
svn commit: r1354955 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
functionTests/tests/replicationTests/ functionTests/util/ junit/
Author: kristwaa
Date: Thu Jun 28 11:47:29 2012
New Revision: 1354955
URL: http://svn.apache.org/viewvc?rev=1354955&view=rev
Log:
DERBY-5836: Move assertDirectoryDeleted from BaseJDBCTestCase to BaseTestCase
Moved the method to a better home.
Patch file: derby-5836-1a-move.diff
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/DropDatabaseSetup.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java?rev=1354955&r1=1354954&r2=1354955&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/replicationTests/ReplicationRun.java Thu Jun 28 11:47:29 2012
@@ -1773,13 +1773,13 @@ public class ReplicationRun extends Base
if ( host.equalsIgnoreCase("localhost") || localEnv )
{
if (PrivilegedFileOpsForTests.exists(masterHome)) {
- BaseJDBCTestCase.assertDirectoryDeleted(masterHome);
+ BaseTestCase.assertDirectoryDeleted(masterHome);
}
util.mkDirs(masterHome.getPath()); // Create the directory
// Ditto for slave:
if (PrivilegedFileOpsForTests.exists(slaveHome)) {
- BaseJDBCTestCase.assertDirectoryDeleted(slaveHome);
+ BaseTestCase.assertDirectoryDeleted(slaveHome);
}
util.mkDirs(slaveHome.getPath()); // Create the directory
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java?rev=1354955&r1=1354954&r2=1354955&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java Thu Jun 28 11:47:29 2012
@@ -372,7 +372,7 @@ public class PrivilegedFileOpsForTests {
*
* @param dir the directory to delete (including subdirectories)
* @return A list of files which couldn't be deleted (may be empty).
- * @see org.apache.derbyTesting.junit.BaseJDBCTestCase#assertDirectoryDeleted
+ * @see org.apache.derbyTesting.junit.BaseTestCase#assertDirectoryDeleted
*/
public static File[] persistentRecursiveDelete(final File dir)
throws FileNotFoundException {
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=1354955&r1=1354954&r2=1354955&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 Thu Jun 28 11:47:29 2012
@@ -1506,80 +1506,6 @@ public abstract class BaseJDBCTestCase
conn.commit();
}
-
- /**
- * Deletes the specified directory and all its files and subdirectories.
- * <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;
- int attempts = 0;
- while (attempts < 4) {
- try {
- Thread.sleep(attempts * 2000);
- } catch (InterruptedException ie) {
- // Ignore
- }
- try {
- fl = PrivilegedFileOpsForTests.persistentRecursiveDelete(dir);
- attempts++;
- } catch (FileNotFoundException fnfe) {
- if (attempts == 0) {
- fail("directory doesn't exist: " +
- PrivilegedFileOpsForTests.getAbsolutePath(dir));
- } else {
- // In the previous iteration we saw remaining files, but
- // now the root directory is gone. Not what we expected...
- System.out.println("<assertDirectoryDeleted> root " +
- "directory unexpectedly gone - delayed, " +
- "external or concurrent delete?");
- return;
- }
- }
- 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
- // information about each file.
- StringBuffer sb = new StringBuffer();
- for (int i=0; i < fl.length; i++) {
- File f = fl[i];
- sb.append(PrivilegedFileOpsForTests.getAbsolutePath(f)).append(' ').
- append(PrivilegedFileOpsForTests.getFileInfo(f)).
- append(", ");
- }
- sb.deleteCharAt(sb.length() -1).deleteCharAt(sb.length() -1);
- fail("Failed to delete " + fl.length + " files (root=" +
- PrivilegedFileOpsForTests.getAbsolutePath(dir) + "): " +
- sb.toString());
- }
} // End class BaseJDBCTestCase
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1354955&r1=1354954&r2=1354955&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Thu Jun 28 11:47:29 2012
@@ -57,6 +57,7 @@ public abstract class BaseTestCase
protected final static String ERRORSTACKTRACEFILE = "error-stacktrace.out";
protected final static String DEFAULT_DB_DIR = "system";
protected final static String DERBY_LOG = "derby.log";
+
/**
* No argument constructor made private to enforce naming of test cases.
* According to JUnit documentation, this constructor is provided for
@@ -950,6 +951,78 @@ public abstract class BaseTestCase
}
/**
+ * Deletes the specified directory and all its files and subdirectories.
+ * <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;
+ int attempts = 0;
+ while (attempts < 4) {
+ try {
+ Thread.sleep(attempts * 2000);
+ } catch (InterruptedException ie) {
+ // Ignore
+ }
+ try {
+ fl = PrivilegedFileOpsForTests.persistentRecursiveDelete(dir);
+ attempts++;
+ } catch (FileNotFoundException fnfe) {
+ if (attempts == 0) {
+ fail("directory doesn't exist: " +
+ PrivilegedFileOpsForTests.getAbsolutePath(dir));
+ } else {
+ // In the previous iteration we saw remaining files, but
+ // now the root directory is gone. Not what we expected...
+ System.out.println("<assertDirectoryDeleted> root " +
+ "directory unexpectedly gone - delayed, " +
+ "external or concurrent delete?");
+ return;
+ }
+ }
+ 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
+ // information about each file.
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < fl.length; i++) {
+ File f = fl[i];
+ sb.append(PrivilegedFileOpsForTests.getAbsolutePath(f)).append(' ').
+ append(PrivilegedFileOpsForTests.getFileInfo(f)).append(", ");
+ }
+ sb.deleteCharAt(sb.length() - 1).deleteCharAt(sb.length() - 1);
+ fail("Failed to delete " + fl.length + " files (root=" +
+ PrivilegedFileOpsForTests.getAbsolutePath(dir) + "): " +
+ sb.toString());
+ }
+
+ /**
* Remove the directory and its contents.
* @param path Path of the directory
*/
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=1354955&r1=1354954&r2=1354955&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 Thu Jun 28 11:47:29 2012
@@ -117,7 +117,7 @@ class DropDatabaseSetup extends BaseTest
if (!dir.exists())
return;
- BaseJDBCTestCase.assertDirectoryDeleted(dir);
+ BaseTestCase.assertDirectoryDeleted(dir);
}
/**