Repository: incubator-geode
Updated Branches:
refs/heads/feature/GEODE-217 435dc63c1 -> eb9e4d7fb
Incorporate Dan's changes for closing Cache in tearDown.
In my changes, I moved everything related to Cache or Regions
to CacheTestCase.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/eb9e4d7f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/eb9e4d7f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/eb9e4d7f
Branch: refs/heads/feature/GEODE-217
Commit: eb9e4d7fbe16f04f5bc6e358be8c4b471f92e6e3
Parents: 435dc63
Author: Kirk Lund <klund@pivotal.io>
Authored: Mon Sep 14 11:02:18 2015 -0700
Committer: Kirk Lund <klund@pivotal.io>
Committed: Mon Sep 14 11:02:18 2015 -0700
----------------------------------------------------------------------
.../gemfire/test/dunit/DistributedTestCase.java | 20 ++++++
.../gemfire/test/dunit/cache/CacheTestCase.java | 65 +++++++++++++-------
2 files changed, 62 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/eb9e4d7f/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
index 2557368..def74b8 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java
@@ -5,6 +5,7 @@ import static com.gemstone.gemfire.test.dunit.Invoke.*;
import static org.junit.Assert.*;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Properties;
@@ -57,6 +58,7 @@ public abstract class DistributedTestCase implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
private static final Logger logger = LogService.getLogger();
private static final LogWriterLogger oldLogger = LogWriterLogger.create(logger);
+ private static final LinkedHashSet<String> testHistory = new LinkedHashSet<String>();
@Rule
public transient TestName testNameRule = new TestName();
@@ -82,6 +84,7 @@ public abstract class DistributedTestCase implements java.io.Serializable
{
@Before
public final void setUpDistributedTestCase() throws Exception {
+ logTestHistory();
setUpCreationStackGenerator();
testName = getMethodName();
@@ -99,6 +102,16 @@ public abstract class DistributedTestCase implements java.io.Serializable
{
//System.out.println("\n\n[setup] START TEST " + getClass().getSimpleName()+"."+testName+"\n\n");
}
+ /**
+ * Write a message to the log about what tests have ran previously. This
+ * makes it easier to figure out if a previous test may have caused problems
+ */
+ private void logTestHistory() {
+ String classname = getClass().getSimpleName();
+ testHistory.add(classname);
+ System.out.println("Previously run tests: " + testHistory);
+ }
+
private static void setUpInVM(final VM vm, final String testNameToUse, final String diskStoreNameToUse)
{
vm.invoke(new SerializableRunnable() {
private static final long serialVersionUID = 1L;
@@ -127,6 +140,7 @@ public abstract class DistributedTestCase implements java.io.Serializable
{
@After
public final void tearDownDistributedTestCase() throws Exception {
tearDownBefore();
+ preTestCaseTearDown();
realTearDown();
tearDownAfter();
@@ -137,6 +151,12 @@ public abstract class DistributedTestCase implements java.io.Serializable
{
tearDownInEveryVM();
}
+ /**
+ * Override this in CacheTest to closeCache and destroyRegions
+ */
+ protected void preTestCaseTearDown() {
+ }
+
private static void tearDownInEveryVM() {
invokeInEveryVM(new SerializableRunnable() {
private static final long serialVersionUID = 1L;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/eb9e4d7f/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/CacheTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/CacheTestCase.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/CacheTestCase.java
index 0dbda35..2e8c264 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/CacheTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/CacheTestCase.java
@@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
+import com.gemstone.gemfire.InternalGemFireError;
import com.gemstone.gemfire.SystemFailure;
import com.gemstone.gemfire.cache.AttributesFactory;
import com.gemstone.gemfire.cache.Cache;
@@ -440,29 +441,7 @@ public abstract class CacheTestCase extends DistributedTestCase {
protected synchronized static void remoteTearDown() {
try {
DistributionMessageObserver.setInstance(null);
- if (cache != null && !cache.isClosed()) {
- //try to destroy the root regions first so that
- //we clean up any persistent files.
- for (Iterator itr = cache.rootRegions().iterator(); itr.hasNext();) {
- Region root = (Region)itr.next();
-// String name = root.getName();
- //for colocated regions you can't locally destroy a partitioned
- //region.
- if(root.isDestroyed() || root instanceof HARegion || root instanceof PartitionedRegion)
{
- continue;
- }
- try {
- root.localDestroyRegion("teardown");
- }
- catch (VirtualMachineError e) {
- SystemFailure.initiateFailure(e);
- throw e;
- }
- catch (Throwable t) {
- getLogWriter().error(t);
- }
- }
- }
+ destroyRegions(cache);
}
finally {
try {
@@ -485,6 +464,46 @@ public abstract class CacheTestCase extends DistributedTestCase {
}
}
+ @Override
+ protected void preTestCaseTearDown() {
+ destroyRegionsAndCloseCache();
+ invokeInEveryVM(CacheTestCase.class, "destroyRegionsAndCloseCache");
+ }
+
+ private static void destroyRegionsAndCloseCache() {
+ GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
+ if(cache != null && !cache.isClosed()) {
+ destroyRegions(cache);
+ cache.close();
+ }
+ }
+
+ private static final void destroyRegions(Cache cache)
+ throws InternalGemFireError, Error, VirtualMachineError {
+ if (cache != null && !cache.isClosed()) {
+ //try to destroy the root regions first so that
+ //we clean up any persistent files.
+ for (Iterator itr = cache.rootRegions().iterator(); itr.hasNext();) {
+ Region root = (Region)itr.next();
+ //for colocated regions you can't locally destroy a partitioned
+ //region.
+ if(root.isDestroyed() || root instanceof HARegion || root instanceof PartitionedRegion)
{
+ continue;
+ }
+ try {
+ root.localDestroyRegion("teardown");
+ }
+ catch (VirtualMachineError e) {
+ SystemFailure.initiateFailure(e);
+ throw e;
+ }
+ catch (Throwable t) {
+ getLogWriter().error(t);
+ }
+ }
+ }
+ }
+
/**
* Returns a region with the given name and attributes
*/
|