Permalink
Browse files

Adjustments to get DirtiesContext working from same JVM. Delete all r…

…ows in database instead of full wipe -- otherwise Derby has issues reconnecting.
  • Loading branch information...
1 parent 5af12ba commit e448b4d5e111c6ec94c16f75c08787739bc90fde @timf timf committed Jun 5, 2011
View
@@ -11,6 +11,7 @@
<module name="basic" />
<module name="contextualization" />
<module name="failure" />
+ <module name="installer" />
<module name="spotinstances" />
</modules>
</facet-type>
@@ -34,6 +35,28 @@
<option name="LOCALE" />
<option name="OPEN_IN_BROWSER" value="true" />
</component>
+ <component name="NullableNotNullManager">
+ <option name="myDefaultNullable" value="org.jetbrains.annotations.Nullable" />
+ <option name="myDefaultNotNull" value="org.jetbrains.annotations.NotNull" />
+ <option name="myNullables">
+ <value>
+ <list size="3">
+ <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
+ <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
+ <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
+ </list>
+ </value>
+ </option>
+ <option name="myNotNulls">
+ <value>
+ <list size="3">
+ <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
+ <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
+ <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
+ </list>
+ </value>
+ </option>
+ </component>
<component name="ProjectResources">
<default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
</component>
@@ -514,6 +514,9 @@ public void shutdownImmediately() {
if (this.executor != null) {
this.executor.shutdownNow();
}
+ if (this.cache != null) {
+ this.cache.removeAll();
+ }
}
/**
@@ -543,6 +546,8 @@ public void recover_initialize() throws Exception {
this.scheduledExecutor.setRemoveOnCancelPolicy(true);
this.scheduledExecutor.setMaximumPoolSize(5);
+ // Pass in the general executor, not the scheduled one. Sweeper uses that to
+ // execute any tasks it creates.
final ResourceSweeper sweeper =
new ResourceSweeper(this.executor, this, this.lager);
@@ -21,7 +21,11 @@
import java.io.IOException;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -36,10 +40,12 @@
import org.globus.workspace.WorkspaceException;
import org.globus.workspace.WorkspaceUtil;
import org.globus.workspace.remoting.admin.VmmNode;
+import org.globus.workspace.service.impls.WorkspaceHomeImpl;
import org.globus.workspace.testing.utils.ReprPopulator;
import org.nimbustools.api.brain.ModuleLocator;
import org.nimbustools.api.brain.NimbusHomePathResolver;
import org.nimbustools.api.services.admin.RemoteNodeManagement;
+import org.nimbustools.api.services.rm.Manager;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.AfterMethod;
@@ -60,6 +66,7 @@
protected static final String MODULE_LOCATOR_BEAN_NAME = "nimbus-brain.ModuleLocator";
private static final String DATA_SOURCE_BEAN_NAME = "other.MainDataSource";
+ private static final String WORKSPACE_HOME_BEAN_NAME = "nimbus-rm.home.instance";
private static final String TIMER_MANAGER_BEAN_NAME = "other.timerManager";
private static final String REMOTING_NATIVE_PROPERTY = "org.newsclub.net.unix.library.path";
@@ -122,14 +129,15 @@ protected void springTestContextAfterTestMethod(Method testMethod)
if(testMethod.isAnnotationPresent(DirtiesContext.class)){
logger.debug(LOG_SEP + "\n*** @DirtiesContext FOUND - STARTING CLEANUP: " + LOG_SEP);
stopTimerManager();
- shutdownDB();
- resetDB();
+ stopWorkspaceService();
+ //shutdownDB();
+ quickResetDB();
logger.debug(LOG_SEP + "\n*** @DirtiesContext FOUND - FINISHED CLEANUP: " + LOG_SEP);
}
super.springTestContextAfterTestMethod(testMethod);
- }
-
+ }
+
// -----------------------------------------------------------------------------------------
// TEST SETUP / TEARDOWN
// -----------------------------------------------------------------------------------------
@@ -157,30 +165,7 @@ protected void suiteSetup() throws Exception {
// Manually intervene here if you want to start off a test suite with your own var
// directory instead of a fresh one.
-
- final File vardir = new File(nimbusHome, "services/var");
- if (vardir.exists()) {
- FileUtils.deleteDirectory(vardir);
- logger.info("Deleted pre-existing test suite services/var dir '" + vardir.getAbsolutePath() + '\'');
- }
-
- final File vardir2 = new File(nimbusHome, "var/run/privileged");
- if (vardir2.exists()) {
- FileUtils.deleteDirectory(vardir2);
- logger.info("Deleted pre-existing privileged var dir '" + vardir2.getAbsolutePath() + '\'');
- }
- boolean created = vardir2.mkdirs();
- if (created) {
- logger.info("Created new privileged var dir '" + vardir2.getAbsolutePath() + '\'');
- } else {
- throw new Exception("Could not create new privileged var dir: " + vardir2.getAbsolutePath());
- }
-
- this.setUpShareDir(nimbusHome);
- final File setupExe =
- new File(nimbusHome,
- "services/share/nimbus/full-reset.sh"); // requires ant on PATH
- this.setUpVarDir(vardir, setupExe);
+ this.fullWipeResetDbAndVar();
String libNativePath = nimbusHome + "/services/lib-native";
System.setProperty(REMOTING_NATIVE_PROPERTY, libNativePath);
@@ -246,11 +231,19 @@ protected void suiteTeardown() throws Exception {
final File vardir = new File(nh, "services/var");
if (!vardir.exists()) {
throw new Exception("Could not tear down, var dir " +
- "does not exist: " + vardir.getAbsolutePath());
+ "does not exist? " + vardir.getAbsolutePath());
}
-
FileUtils.deleteDirectory(vardir);
logger.info("Deleted test suite var dir '" + vardir.getAbsolutePath() + '\'');
+
+ final File vardir2 = new File(nh, "var/run/privileged");
+ if (!vardir2.exists()) {
+ throw new Exception("Could not tear down, privileged var/run dir " +
+ "does not exist? " + vardir2.getAbsolutePath());
+ }
+ FileUtils.deleteDirectory(vardir2);
+ logger.info("Deleted privileged var/run dir '" + vardir2.getAbsolutePath() + '\'');
+
logger.debug(LOG_SEP + "\n*** TEARDOWN DONE: " +
this.getClass().getSimpleName() + LOG_SEP);
}
@@ -502,15 +495,83 @@ protected void setUpShareDir(String nimbusHome) throws Exception {
private void stopTimerManager() {
logger.info("Stopping Timer Manager..");
TimerManager timerManager = (TimerManager) applicationContext.getBean(TIMER_MANAGER_BEAN_NAME);
- timerManager.stop();
- logger.info("Timer Manager succesfully stopped");
+ if (timerManager != null) {
+ timerManager.stop();
+ logger.info("Timer Manager succesfully stopped");
+ } else {
+ logger.info("No Timer Manager");
+ }
}
- private void resetDB() throws Exception, WorkspaceException,
+ private void stopWorkspaceService() {
+ logger.info("Stopping Workspace Manager (thread pools)..");
+ final Manager rm = this.locator.getManager();
+ if (rm != null) {
+ rm.shutdownImmediately();
+ logger.info("Workspace Manager (thread pools) stopped");
+ } else {
+ logger.info("No Workspace Manager");
+ }
+ }
+
+ private void fullWipeResetDbAndVar() throws Exception, WorkspaceException,
ReturnException {
- final File exe = new File(getNimbusHome(), "services/share/nimbus/full-reset.sh"); // requires ant on PATH
- final String[] cmd = {exe.getAbsolutePath()};
- WorkspaceUtil.runCommand(cmd, true, true);
+
+ final String nimbusHome = this.getNimbusHome();
+ if (nimbusHome == null || nimbusHome.trim().length() == 0) {
+ throw new Exception("No Nimbus home");
+ }
+ if (!new File(nimbusHome).exists()) {
+ throw new Exception("Nimbus home does not exist: " + nimbusHome);
+ }
+
+ final File vardir = new File(nimbusHome, "services/var");
+ if (vardir.exists()) {
+ FileUtils.deleteDirectory(vardir);
+ logger.info("Deleted pre-existing test suite services/var dir '" + vardir.getAbsolutePath() + '\'');
+ }
+
+ final File vardir2 = new File(nimbusHome, "var/run/privileged");
+ if (vardir2.exists()) {
+ FileUtils.deleteDirectory(vardir2);
+ logger.info("Deleted pre-existing privileged var dir '" + vardir2.getAbsolutePath() + '\'');
+ }
+ boolean created = vardir2.mkdirs();
+ if (created) {
+ logger.info("Created new privileged var dir '" + vardir2.getAbsolutePath() + '\'');
+ } else {
+ throw new Exception("Could not create new privileged var dir: " + vardir2.getAbsolutePath());
+ }
+
+ this.setUpShareDir(nimbusHome);
+ final File setupExe =
+ new File(nimbusHome,
+ "services/share/nimbus/full-reset.sh"); // requires ant on PATH
+ this.setUpVarDir(vardir, setupExe);
+ }
+
+ private void quickResetDB() throws Exception, WorkspaceException,
+ ReturnException {
+
+ final BasicDataSource ds =
+ (BasicDataSource) applicationContext.getBean(DATA_SOURCE_BEAN_NAME);
+ final Connection conn = ds.getConnection();
+ try {
+ conn.setAutoCommit(false);
+ final DatabaseMetaData dmd = conn.getMetaData();
+ final ResultSet trs = dmd.getTables(null, "NIMBUS", null, null);
+ while (trs.next()) {
+ final String tableName = trs.getString("TABLE_NAME");
+ logger.debug("Deleting all rows from " + tableName);
+ final Statement stmt = conn.createStatement();
+ stmt.executeUpdate("DELETE FROM " + tableName);
+ }
+ } finally {
+ if (conn != null) {
+ conn.setAutoCommit(true);
+ conn.close();
+ }
+ }
}
private void shutdownDB() throws Exception {
@@ -523,8 +584,12 @@ private void shutdownDB() throws Exception {
ds.getConnection();
Thread.sleep(10);
} catch (SQLException e){
- logger.info("DB succesfully shutdown.");
- return;
+ if (e.getSQLState().equals("08006") || e.getSQLState().equals("XJ004")) {
+ logger.info("DB succesfully shutdown. ('" + e.getSQLState() + "')");
+ return;
+ } else {
+ logger.info("DB not shutdown yet ('" + e.getSQLState() + "')");
+ }
}
}

0 comments on commit e448b4d

Please sign in to comment.