Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 50769 invoked from network); 31 Oct 2006 20:09:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 31 Oct 2006 20:09:35 -0000 Received: (qmail 27068 invoked by uid 500); 31 Oct 2006 20:09:46 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 27035 invoked by uid 500); 31 Oct 2006 20:09:46 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 27020 invoked by uid 99); 31 Oct 2006 20:09:46 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Oct 2006 12:09:46 -0800 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Oct 2006 12:09:32 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 9D1021A9846; Tue, 31 Oct 2006 12:09:08 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: derby-commits@db.apache.org From: djd@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061031200908.9D1021A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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,