db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r469632 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit: DropDatabaseSetup.java TestConfiguration.java
Date Tue, 31 Oct 2006 20:09:08 GMT
Author: djd
Date: Tue Oct 31 12:09:07 2006
New Revision: 469632

URL: http://svn.apache.org/viewvc?view=rev&rev=469632
Log:
DERBY-1975 Enhance the single database decorator and DropDatabaseSetup to use a unique database
name
and to drop the database at tearDown.

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

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?view=diff&rev=469632&r1=469631&r2=469632
==============================================================================
--- 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
Tue Oct 31 12:09:07 2006
@@ -50,5 +50,44 @@
         } catch (SQLException e) {
             BaseJDBCTestCase.assertSQLState("Database shutdown", "08006", e);
         }
+
+        String dbName = TestConfiguration.getCurrent().getDatabaseName();
+        dbName = dbName.replace('/', File.separatorChar);
+        
+        String dsh = BaseTestCase.getSystemProperty("derby.system.home");
+        if (dsh == null)
+            fail("not implemented");
+        else
+            dbName = dsh + File.separator + dbName;
+        
+        final File dbDir = new File(dbName);
+        AccessController.doPrivileged(new java.security.PrivilegedAction() {
+
+            public Object run() {
+                removeDBDir(dbDir);
+                return null;
+            }
+        });
     } 
+
+    private static void removeDBDir(File dbDir) {
+
+        String[] list = dbDir.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(dbDir, list[i]);
+
+                if (entry.isDirectory()) {
+                    removeDBDir(entry);
+                } else {
+                    assertTrue(entry.delete());
+                }
+            }
+        }
+
+        assertTrue(dbDir.delete());
+    }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java?view=diff&rev=469632&r1=469631&r2=469632
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/TestConfiguration.java
Tue Oct 31 12:09:07 2006
@@ -63,6 +63,12 @@
      * Possible values of system properties.
      */
     private final static String UNUSED = "file://unused/";
+    
+    /**
+     * Simple count to provide a unique number for database
+     * names.
+     */
+    private static int uniqueDB;
 
 
     /**
@@ -250,6 +256,8 @@
      * first connection request to the database and shutdown & deleted at
      * tearDown. The configuration differs only from the current configuration
      * by the database name.
+     * This decorator expects the database file to be local so it
+     * can be removed.
      * @param test Test to be decorated
      * @return decorated test.
      */
@@ -257,8 +265,15 @@
     {
         TestConfiguration config = TestConfiguration.getCurrent();
 
-        // WORK IN PROGRESS - need to have unique name.
-        String dbName = "singleUse/wombat2";        
+        // Forward slash is ok, Derby treats database names
+        // as URLs and translates forward slash to the local
+        // separator.
+        String dbName = "singleUse/oneuse";
+        // Synchronize on the literal name which will be invariant
+        // since it is interned.
+        synchronized (dbName) {
+            dbName = dbName.concat(Integer.toHexString(uniqueDB++));
+        }
         TestConfiguration newDBconfig = 
             new TestConfiguration(config, dbName);
         return new ChangeConfigurationSetup(newDBconfig,



Mime
View raw message