[jboss-cvs] JBossAS SVN: r79672 - projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/common/unit.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 17 15:50:13 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-10-17 15:50:12 -0400 (Fri, 17 Oct 2008)
New Revision: 79672

Modified:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/common/unit/DBSetup.java
Log:
Clean up persisted hypersonic files in tearDown

Modified: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/common/unit/DBSetup.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/common/unit/DBSetup.java	2008-10-17 19:49:30 UTC (rev 79671)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/common/unit/DBSetup.java	2008-10-17 19:50:12 UTC (rev 79672)
@@ -25,6 +25,7 @@
 import java.sql.Connection;
 import java.sql.Statement;
 import java.io.File;
+import java.io.FileFilter;
 import java.io.IOException;
 import java.lang.reflect.Method;
 
@@ -39,14 +40,24 @@
  */
 public class DBSetup extends TestSetup
 {
+   private static final String HYPERSONIC_DIR = "output/hypersonic";
+   private static final String DB_NAME = "clusteredentity-db";
+   private final boolean deleteInTearDown;
+   
    public DBSetup(Test test)
    {
+      this(test, true);
+   }
+   
+   public DBSetup(Test test, boolean deleteInTearDown)
+   {
       super(test);
+      this.deleteInTearDown = deleteInTearDown;
    }
 
    protected void setUp() throws Exception
    {
-         File hypersoniDir = new File("output/hypersonic");
+         File hypersoniDir = new File(HYPERSONIC_DIR);
          if (!hypersoniDir.exists())
          {
             hypersoniDir.mkdirs();
@@ -57,7 +68,7 @@
             throw new IOException("Failed to create directory: " + hypersoniDir);
          }
       
-         File dbPath = new File(hypersoniDir, "clusteredentity-db");
+         File dbPath = new File(hypersoniDir, DB_NAME);
 
          // Start DB in new thread, or else it will block us
          DBThread serverThread = new DBThread(dbPath);
@@ -89,6 +100,26 @@
       Statement statement = conn.createStatement();      
       statement.executeQuery("SHUTDOWN COMPACT");
       
+      if (deleteInTearDown)
+      {
+         File hypersonicDir = new File(HYPERSONIC_DIR);
+         if (hypersonicDir.exists() && hypersonicDir.isDirectory())
+         {
+            FileFilter filter = new FileFilter() {
+               public boolean accept(File file) 
+               {
+                  return file.getName().indexOf(DB_NAME) >= 0;
+               }
+            };
+            
+            File[] dbFiles = hypersonicDir.listFiles(filter);
+            for (File file : dbFiles)
+            {
+               file.delete();
+            }
+         }
+      }
+      
    }
 
    public static void main(String[] args) throws Exception




More information about the jboss-cvs-commits mailing list