Skip to content

Commit

Permalink
Remove h2 and derby database files so we start at ground zero for eac…
Browse files Browse the repository at this point in the history
…h integration test.
  • Loading branch information
chenson42 committed Sep 14, 2009
1 parent 2252a27 commit 1defde0
Showing 1 changed file with 27 additions and 3 deletions.
Expand Up @@ -39,6 +39,7 @@
import javax.servlet.ServletContext;
import javax.sql.DataSource;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -109,9 +110,8 @@ public static void cleanup() throws Exception {
}

/**
* Unit tests were failing after opening and closing several data connection
* pools against the same database in memory. After shutting down the
* connection pool, it seems to help by shutting down the entire database.
* Unit tests were failing after opening and closing several data connection pools against the same database in
* memory. After shutting down the connection pool, it seems to help by shutting down the entire database.
*/
protected static void closeDerbyAndReloadDriver() throws SQLException {
try {
Expand All @@ -128,6 +128,9 @@ protected static void closeDerbyAndReloadDriver() throws SQLException {

public static void setup(String testPrefix, String sqlScriptSuffix, String clientDb, String rootDb)
throws Exception {

removeEmbededdedDatabases();

if (rootDb != null) {
rootServer = new SymmetricWebServer("file:"
+ writeTempPropertiesFileFor(testPrefix, rootDb, DatabaseRole.ROOT).getAbsolutePath());
Expand All @@ -146,6 +149,27 @@ public static void setup(String testPrefix, String sqlScriptSuffix, String clien
}
}

public static void removeEmbededdedDatabases() {
File derby = new File("target/derby");
if (derby.exists()) {
try {
logger.info("Removing derby database files.");
FileUtils.deleteDirectory(derby);
} catch (IOException e) {
logger.error(e, e);
}
}
File h2 = new File("target/h2");
if (h2.exists()) {
try {
logger.info("Removing h2 database files");
FileUtils.deleteDirectory(h2);
} catch (IOException e) {
logger.error(e, e);
}
}
}

public static SymmetricEngine getRootEngine() {
return rootServer.getEngine();
}
Expand Down

0 comments on commit 1defde0

Please sign in to comment.