summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-07-20 07:05:22 (EDT)
committerStefan Winkler2009-07-20 07:05:22 (EDT)
commit170f482ad9fedda295d6bccfea1f8c4e3f51e30f (patch)
treec55b180f8ad6b4e8257a5b9d5a9503bc848b7e00
parent8f84dfafb71b6634d1774f45773f994d7b81b8ea (diff)
downloadcdo-170f482ad9fedda295d6bccfea1f8c4e3f51e30f.zip
cdo-170f482ad9fedda295d6bccfea1f8c4e3f51e30f.tar.gz
cdo-170f482ad9fedda295d6bccfea1f8c4e3f51e30f.tar.bz2
[283516] [DB] Reuse H2 database in test runs
https://bugs.eclipse.org/bugs/show_bug.cgi?id=283516
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java72
1 files changed, 64 insertions, 8 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java
index c974469..f337f53 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2.java
@@ -13,8 +13,10 @@ package org.eclipse.emf.cdo.tests.db;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
+import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.h2.H2Adapter;
+import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.io.TMPUtil;
@@ -23,6 +25,7 @@ import org.h2.jdbcx.JdbcDataSource;
import javax.sql.DataSource;
import java.io.File;
+import java.sql.Connection;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -40,7 +43,7 @@ public class AllTestsDBH2 extends DBConfigs
@Override
protected void initConfigSuites(TestSuite parent)
{
- addScenario(parent, COMBINED, AllTestsDBH2.H2.INSTANCE, JVM, NATIVE);
+ addScenario(parent, COMBINED, AllTestsDBH2.H2.ReusableFolder.INSTANCE, JVM, NATIVE);
}
/**
@@ -84,13 +87,6 @@ public class AllTestsDBH2 extends DBConfigs
return dataSource;
}
- @Override
- public void tearDown() throws Exception
- {
- tearDownClean();
- super.tearDown();
- }
-
protected void tearDownClean()
{
IOUtil.delete(dbFolder);
@@ -100,5 +96,65 @@ public class AllTestsDBH2 extends DBConfigs
{
return TMPUtil.createTempFolder("h2_", "_test", new File("/temp"));
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class ReusableFolder extends H2
+ {
+ private static final long serialVersionUID = 1L;
+
+ public static final ReusableFolder INSTANCE = new ReusableFolder("DBStore: H2 (Reusable Folder)");
+
+ private static File reusableFolder;
+
+ public ReusableFolder(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected DataSource createDataSource()
+ {
+ dataSource = new JdbcDataSource();
+ if (reusableFolder == null)
+ {
+ reusableFolder = createDBFolder();
+ IOUtil.delete(reusableFolder);
+ }
+
+ dbFolder = reusableFolder;
+ dataSource.setURL("jdbc:h2:" + dbFolder.getAbsolutePath());
+
+ tearDownClean();
+
+ return dataSource;
+ }
+
+ @Override
+ protected void tearDownClean()
+ {
+ reusableFolder.deleteOnExit();
+ Connection connection = null;
+
+ try
+ {
+ connection = dataSource.getConnection();
+ DBUtil.dropAllTables(connection, null); // null is the default catalog for H2.
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ finally
+ {
+ DBUtil.close(connection);
+ }
+ }
+ }
}
}