You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2015/10/01 19:58:52 UTC
[11/26] incubator-geode git commit: GEODE-320: Close the cache in
DistributedTestCase tear down
GEODE-320: Close the cache in DistributedTestCase tear down
Close the cache in distributed test case teardown to deal with bad
behaving tests that aren't cleaning up their cache.
Adding a log that shows us what tests ran previously to help debug
in situations where the progress file is not available.
I also found that RegionTestCase was previously not cleaning up the
cache at all, so I added a missing call to super.tearDown.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/4e65f0c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/4e65f0c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/4e65f0c7
Branch: refs/heads/feature/GEODE-77
Commit: 4e65f0c72d30ca24c582543a62dc72b064e9d448
Parents: 391a93d
Author: Dan Smith <up...@apache.org>
Authored: Wed Sep 9 13:21:06 2015 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Mon Sep 14 13:54:27 2015 -0700
----------------------------------------------------------------------
.../gemstone/gemfire/cache30/CacheTestCase.java | 27 ++--------
.../gemfire/cache30/RegionTestCase.java | 1 +
.../test/java/dunit/DistributedTestCase.java | 56 ++++++++++++++++++++
3 files changed, 60 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4e65f0c7/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
index e318370..951c985 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheTestCase.java
@@ -16,6 +16,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;
@@ -453,29 +454,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 {
@@ -497,7 +476,7 @@ public abstract class CacheTestCase extends DistributedTestCase {
getLogWriter().error("Error cleaning disk dirs", e);
}
}
-
+
/**
* Returns a region with the given name and attributes
*/
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4e65f0c7/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
index 4b20b42..81c8afb 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java
@@ -102,6 +102,7 @@ public abstract class RegionTestCase extends CacheTestCase {
}
public void tearDown2() throws Exception {
+ super.tearDown2();
cleanup();
invokeInEveryVM(getClass(), "cleanup");
/*for (int h = 0; h < Host.getHostCount(); h++) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4e65f0c7/gemfire-core/src/test/java/dunit/DistributedTestCase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/dunit/DistributedTestCase.java b/gemfire-core/src/test/java/dunit/DistributedTestCase.java
index 2e7ac03..c78510a 100755
--- a/gemfire-core/src/test/java/dunit/DistributedTestCase.java
+++ b/gemfire-core/src/test/java/dunit/DistributedTestCase.java
@@ -16,6 +16,7 @@ import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -24,13 +25,17 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.springframework.data.gemfire.support.GemfireCache;
import junit.framework.TestCase;
+import com.gemstone.gemfire.InternalGemFireError;
import com.gemstone.gemfire.LogWriter;
+import com.gemstone.gemfire.SystemFailure;
import com.gemstone.gemfire.admin.internal.AdminDistributedSystemImpl;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DiskStoreFactory;
+import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.hdfs.internal.HDFSStoreImpl;
import com.gemstone.gemfire.cache.hdfs.internal.hoplog.HoplogConfig;
import com.gemstone.gemfire.cache.query.QueryTestUtils;
@@ -54,8 +59,10 @@ import com.gemstone.gemfire.internal.SocketCreator;
import com.gemstone.gemfire.internal.admin.ClientStatsManager;
import com.gemstone.gemfire.internal.cache.DiskStoreObserver;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.internal.cache.HARegion;
import com.gemstone.gemfire.internal.cache.InitialImageOperation;
import com.gemstone.gemfire.internal.cache.LocalRegion;
+import com.gemstone.gemfire.internal.cache.PartitionedRegion;
import com.gemstone.gemfire.internal.cache.tier.InternalBridgeMembership;
import com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerTestUtil;
import com.gemstone.gemfire.internal.cache.tier.sockets.ClientProxyMembershipID;
@@ -92,6 +99,7 @@ import dunit.standalone.DUnitLauncher;
public abstract class DistributedTestCase extends TestCase implements java.io.Serializable {
private static final Logger logger = LogService.getLogger();
private static final LogWriterLogger oldLogger = LogWriterLogger.create(logger);
+ private static final LinkedHashSet<String> testHistory = new LinkedHashSet<String>();
private static void setUpCreationStackGenerator() {
// the following is moved from InternalDistributedSystem to fix #51058
@@ -672,6 +680,7 @@ public abstract class DistributedTestCase extends TestCase implements java.io.Se
*/
@Override
public void setUp() throws Exception {
+ logTestHistory();
setUpCreationStackGenerator();
testName = getName();
System.setProperty(HoplogConfig.ALLOW_LOCAL_HDFS_PROP, "true");
@@ -691,6 +700,16 @@ public abstract class DistributedTestCase extends TestCase implements java.io.Se
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);
+ }
+
public static void perVMSetUp(String name, String defaultDiskStoreName) {
setTestName(name);
GemFireCacheImpl.setDefaultDiskStoreName(defaultDiskStoreName);
@@ -767,6 +786,8 @@ public abstract class DistributedTestCase extends TestCase implements java.io.Se
private static void cleanupThisVM() {
+ closeCache();
+
IpAddress.resolve_dns = true;
SocketCreator.resolve_dns = true;
InitialImageOperation.slowImageProcessing = 0;
@@ -794,6 +815,41 @@ public abstract class DistributedTestCase extends TestCase implements java.io.Se
ex.remove();
}
}
+
+ private static void closeCache() {
+ GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
+ if(cache != null && !cache.isClosed()) {
+ destroyRegions(cache);
+ cache.close();
+ }
+ }
+
+ protected 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);
+ }
+ }
+ }
+ }
+
public static void unregisterAllDataSerializersFromAllVms()
{