http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestFunctionsDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestFunctionsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestFunctionsDUnitTest.java index b410a82..2666b0c 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestFunctionsDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestFunctionsDUnitTest.java @@ -44,11 +44,6 @@ public class TestFunctionsDUnitTest extends ManagementTestBase { super(name); } - public void setUp() throws Exception { - super.setUp(); - - } - public static Integer getNumOfRunningFunction() { final WaitCriterion waitCriteria = new WaitCriterion() {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestHeapDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestHeapDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestHeapDUnitTest.java index 78e91b0..4eefdca 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestHeapDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestHeapDUnitTest.java @@ -38,12 +38,7 @@ public class TestHeapDUnitTest extends ManagementTestBase { super(name); } - public void setUp() throws Exception { - super.setUp(); - - } - - public static long getHeapSizeOfClient() { + public static long getHeapSizeOfClient() { return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestLocatorsDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestLocatorsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestLocatorsDUnitTest.java index 926c2ff..69f8bc9 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestLocatorsDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestLocatorsDUnitTest.java @@ -37,11 +37,6 @@ public class TestLocatorsDUnitTest extends ManagementTestBase { super(name); } - public void setUp() throws Exception { - super.setUp(); - - } - public static int getNumOfLocatorFromMBean() { final WaitCriterion waitCriteria = new WaitCriterion() { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestSubscriptionsDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestSubscriptionsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestSubscriptionsDUnitTest.java index ef491b0..95ef63b 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestSubscriptionsDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/pulse/TestSubscriptionsDUnitTest.java @@ -74,8 +74,8 @@ public class TestSubscriptionsDUnitTest extends DistributedTestCase { this.helper = new ManagementTestBase(name); } - public void setUp() throws Exception { - super.setUp(); + @Override + public final void postSetUp() throws Exception { final Host host = Host.getHost(0); managingNode = host.getVM(0); server = host.getVM(1); @@ -84,7 +84,7 @@ public class TestSubscriptionsDUnitTest extends DistributedTestCase { } @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { helper.closeCache(managingNode); helper.closeCache(server); helper.closeCache(client); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/pdx/ClientsWithVersioningRetryDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/pdx/ClientsWithVersioningRetryDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/pdx/ClientsWithVersioningRetryDUnitTest.java index 40592ff..0f747db 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/pdx/ClientsWithVersioningRetryDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/pdx/ClientsWithVersioningRetryDUnitTest.java @@ -79,8 +79,7 @@ public class ClientsWithVersioningRetryDUnitTest extends CacheTestCase { } @Override - public void setUp() throws Exception { - super.setUp(); + public final void postSetUp() throws Exception { Invoke.invokeInEveryVM(new SerializableRunnable() { @Override public void run() { @@ -93,7 +92,7 @@ public class ClientsWithVersioningRetryDUnitTest extends CacheTestCase { } @Override - protected final void postTearDownCacheTestCase() throws Exception { + public final void postTearDownCacheTestCase() throws Exception { Invoke.invokeInEveryVM(new SerializableRunnable() { @Override public void run() { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONPdxClientServerDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONPdxClientServerDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONPdxClientServerDUnitTest.java index 937ff31..4949b43 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONPdxClientServerDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/pdx/JSONPdxClientServerDUnitTest.java @@ -60,7 +60,7 @@ public class JSONPdxClientServerDUnitTest extends CacheTestCase { } @Override - protected final void preTearDownCacheTestCase() { + public final void preTearDownCacheTestCase() { // this test creates client caches in some VMs and so // breaks the contract of CacheTestCase to hold caches in // that class's "cache" instance variable http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxSerializableDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxSerializableDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxSerializableDUnitTest.java index 51635f3..1e901bc 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxSerializableDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxSerializableDUnitTest.java @@ -35,12 +35,6 @@ public class PdxSerializableDUnitTest extends CacheTestCase { super(name); } - - @Override - public void setUp() throws Exception { - super.setUp(); - } - public void testSimplePut() { Host host = Host.getHost(0); VM vm1 = host.getVM(0); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxTypeExportDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxTypeExportDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxTypeExportDUnitTest.java index c820e72..58f2128 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxTypeExportDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/pdx/PdxTypeExportDUnitTest.java @@ -68,9 +68,9 @@ public class PdxTypeExportDUnitTest extends CacheTestCase { Host.getHost(0).getVM(3).invoke(test); } - - public void setUp() throws Exception { - super.setUp(); + + @Override + public final void postSetUp() throws Exception { loadCache(); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java index f787909..825f532 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java @@ -64,8 +64,7 @@ public class RedisDistDUnitTest extends DistributedTestCase { } @Override - public void setUp() throws Exception { - super.setUp(); + public final void postSetUp() throws Exception { disconnectAllFromDS(); host = Host.getHost(0); server1 = host.getVM(0); @@ -102,7 +101,7 @@ public class RedisDistDUnitTest extends DistributedTestCase { } @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { disconnectAllFromDS(); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationDUnitTest.java index 739dd42..456a6ed 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationDUnitTest.java @@ -74,9 +74,7 @@ public class ClientAuthenticationDUnitTest extends DistributedTestCase { SSLHandshakeException.class.getName() }; @Override - public void setUp() throws Exception { - - super.setUp(); + public final void postSetUp() throws Exception { final Host host = Host.getHost(0); server1 = host.getVM(0); server2 = host.getVM(1); @@ -893,7 +891,7 @@ public class ClientAuthenticationDUnitTest extends DistributedTestCase { ////////////////////////////////////////////////////////////////////////////// @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { // close the clients first client1.invoke(() -> SecurityTestUtil.closeCache()); client2.invoke(() -> SecurityTestUtil.closeCache()); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationDUnitTest.java index e3d8ccf..9271cd1 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationDUnitTest.java @@ -56,9 +56,7 @@ public class ClientAuthorizationDUnitTest extends ClientAuthorizationTestBase { } @Override - public void setUp() throws Exception { - - super.setUp(); + public final void postSetUp() throws Exception { final Host host = Host.getHost(0); server1 = host.getVM(0); server2 = host.getVM(1); @@ -801,7 +799,7 @@ public class ClientAuthorizationDUnitTest extends ClientAuthorizationTestBase { // End Region: Tests @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { // close the clients first client1.invoke(() -> SecurityTestUtil.closeCache()); client2.invoke(() -> SecurityTestUtil.closeCache()); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java index 325f0bb..496c3a2 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java @@ -44,9 +44,8 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase { super(name); } - public void setUp() throws Exception { - - super.setUp(); + @Override + public final void postSetUp() throws Exception { final Host host = Host.getHost(0); server1 = host.getVM(0); server2 = host.getVM(1); @@ -510,7 +509,7 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase { // End Region: Tests @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { // close the clients first client1.invoke(() -> SecurityTestUtil.closeCache()); client2.invoke(() -> SecurityTestUtil.closeCache()); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientAuthorizationDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientAuthorizationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientAuthorizationDUnitTest.java index a7d6131..8a78378 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientAuthorizationDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientAuthorizationDUnitTest.java @@ -97,8 +97,8 @@ public class DeltaClientAuthorizationDUnitTest extends super(name); } - public void setUp() throws Exception { - super.setUp(); + @Override + public final void postSetUp() throws Exception { final Host host = Host.getHost(0); server1 = host.getVM(0); server2 = host.getVM(1); @@ -112,7 +112,7 @@ public class DeltaClientAuthorizationDUnitTest extends } @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { // close the clients first client1.invoke(() -> SecurityTestUtil.closeCache()); client2.invoke(() -> SecurityTestUtil.closeCache()); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientPostAuthorizationDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientPostAuthorizationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientPostAuthorizationDUnitTest.java index 090b96a..e0502a2 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientPostAuthorizationDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientPostAuthorizationDUnitTest.java @@ -58,9 +58,8 @@ public class DeltaClientPostAuthorizationDUnitTest extends super(name); } - public void setUp() throws Exception { - - super.setUp(); + @Override + public final void postSetUp() throws Exception { final Host host = Host.getHost(0); server1 = host.getVM(0); server2 = host.getVM(1); @@ -74,7 +73,7 @@ public class DeltaClientPostAuthorizationDUnitTest extends } @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { // close the clients first client1.invoke(() -> SecurityTestUtil.closeCache()); client2.invoke(() -> SecurityTestUtil.closeCache()); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java index 560b9e4..b31f15c 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java @@ -72,9 +72,8 @@ public class P2PAuthenticationDUnitTest extends DistributedTestCase { super(name); } - public void setUp() throws Exception { - - super.setUp(); + @Override + public final void postSetUp() throws Exception { final Host host = Host.getHost(0); locatorVM = host.getVM(0); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java b/geode-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java index d3c379f..af8c0fe 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java @@ -187,16 +187,16 @@ public class SecurityTestUtil extends DistributedTestCase { DistributedSystem dsys = getSystem(sysProps); assertNotNull(dsys); - addExpectedExceptions(SecurityTestUtil.expectedExceptions, system + addExpectedExceptions(SecurityTestUtil.expectedExceptions, dsys .getLogWriter()); return dsys; } void openCache() { - assertNotNull(system); - assertTrue(system.isConnected()); - cache = CacheFactory.create(system); + assertNotNull(basicGetSystem()); + assertTrue(basicGetSystem().isConnected()); + cache = CacheFactory.create(basicGetSystem()); assertNotNull(cache); } @@ -1875,7 +1875,7 @@ public class SecurityTestUtil extends DistributedTestCase { private static LogWriter getLogger() { LogWriter logger = null; - DistributedSystem dsys = system; + DistributedSystem dsys = getSystemStatic(); if (dsys == null || !dsys.isConnected()) { while ((dsys = InternalDistributedSystem.getAnyInstance()) != null && !dsys.isConnected()) { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java index 4f656fd..6a6227c 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/DistributedTestCase.java @@ -16,520 +16,25 @@ */ package com.gemstone.gemfire.test.dunit; -import java.text.DecimalFormat; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.apache.logging.log4j.Logger; -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.SystemFailure; -import com.gemstone.gemfire.admin.internal.AdminDistributedSystemImpl; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.hdfs.internal.hoplog.HoplogConfig; -import com.gemstone.gemfire.cache.query.QueryTestUtils; -import com.gemstone.gemfire.cache.query.internal.QueryObserverHolder; -import com.gemstone.gemfire.cache30.ClientServerTestCase; -import com.gemstone.gemfire.cache30.GlobalLockingDUnitTest; -import com.gemstone.gemfire.cache30.MultiVMRegionTestCase; -import com.gemstone.gemfire.cache30.RegionTestCase; -import com.gemstone.gemfire.distributed.DistributedSystem; -import com.gemstone.gemfire.distributed.internal.DistributionConfig; -import com.gemstone.gemfire.distributed.internal.DistributionMessageObserver; -import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; -import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem.CreationStackGenerator; -import com.gemstone.gemfire.distributed.internal.tcpserver.TcpClient; -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.PartitionedRegion; -import com.gemstone.gemfire.internal.cache.tier.InternalClientMembership; -import com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerTestUtil; -import com.gemstone.gemfire.internal.cache.tier.sockets.ClientProxyMembershipID; -import com.gemstone.gemfire.internal.cache.xmlcache.CacheCreation; -import com.gemstone.gemfire.internal.logging.LogService; -import com.gemstone.gemfire.management.internal.cli.LogWrapper; +import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase; import com.gemstone.gemfire.test.dunit.standalone.DUnitLauncher; import com.gemstone.gemfire.test.junit.categories.DistributedTest; - -import junit.framework.TestCase; +import org.junit.experimental.categories.Category; /** * This class is the superclass of all distributed unit tests. - * - * tests/hydra/JUnitTestTask is the main DUnit driver. It supports two - * additional public static methods if they are defined in the test case: - * - * public static void caseSetUp() -- comparable to JUnit's BeforeClass annotation - * - * public static void caseTearDown() -- comparable to JUnit's AfterClass annotation * * @author David Whitlock */ @Category(DistributedTest.class) @SuppressWarnings("serial") -public abstract class DistributedTestCase extends TestCase implements java.io.Serializable { - - private static final Logger logger = LogService.getLogger(); - - private static final Set<String> testHistory = new LinkedHashSet<String>(); - - /** This VM's connection to the distributed system */ - public static InternalDistributedSystem system; - private static Class lastSystemCreatedInTest; - private static Properties lastSystemProperties; - private static volatile String testMethodName; +public abstract class DistributedTestCase extends JUnit3DistributedTestCase { - /** For formatting timing info */ - private static final DecimalFormat format = new DecimalFormat("###.###"); - - public static boolean reconnect = false; - - public static final boolean logPerTest = Boolean.getBoolean("dunitLogPerTest"); - /** - * Creates a new <code>DistributedTestCase</code> test with the - * given name. + * Creates a new <code>DistributedTestCase</code> test with the given name. */ public DistributedTestCase(final String name) { super(name); DUnitLauncher.launchIfNeeded(); } - - //--------------------------------------------------------------------------- - // methods for tests - //--------------------------------------------------------------------------- - - public final void setSystem(final Properties props, final DistributedSystem ds) { // TODO: override getDistributedSystemProperties and then delete - system = (InternalDistributedSystem)ds; - lastSystemProperties = props; - lastSystemCreatedInTest = getClass(); // used to be getDeclaringClass() - } - - /** - * Returns this VM's connection to the distributed system. If - * necessary, the connection will be lazily created using the given - * <code>Properties</code>. Note that this method uses hydra's - * configuration to determine the location of log files, etc. - * Note: "final" was removed so that WANTestBase can override this method. - * This was part of the xd offheap merge. - * - * see hydra.DistributedConnectionMgr#connect - * @since 3.0 - */ - public /*final*/ InternalDistributedSystem getSystem(final Properties props) { // TODO: make final - // Setting the default disk store name is now done in setUp - if (system == null) { - system = InternalDistributedSystem.getAnyInstance(); - } - if (system == null || !system.isConnected()) { - // Figure out our distributed system properties - Properties p = DistributedTestUtils.getAllDistributedSystemProperties(props); - lastSystemCreatedInTest = getClass(); // used to be getDeclaringClass() - if (logPerTest) { - String testMethod = getTestMethodName(); - String testName = lastSystemCreatedInTest.getName() + '-' + testMethod; - String oldLogFile = p.getProperty(DistributionConfig.LOG_FILE_NAME); - p.put(DistributionConfig.LOG_FILE_NAME, - oldLogFile.replace("system.log", testName+".log")); - String oldStatFile = p.getProperty(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME); - p.put(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME, - oldStatFile.replace("statArchive.gfs", testName+".gfs")); - } - system = (InternalDistributedSystem)DistributedSystem.connect(p); - lastSystemProperties = p; - } else { - boolean needNewSystem = false; - if(!getClass().equals(lastSystemCreatedInTest)) { // used to be getDeclaringClass() - Properties newProps = DistributedTestUtils.getAllDistributedSystemProperties(props); - needNewSystem = !newProps.equals(lastSystemProperties); - if(needNewSystem) { - LogWriterUtils.getLogWriter().info( - "Test class has changed and the new DS properties are not an exact match. " - + "Forcing DS disconnect. Old props = " - + lastSystemProperties + "new props=" + newProps); - } - } else { - Properties activeProps = system.getProperties(); - for (Iterator iter = props.entrySet().iterator(); - iter.hasNext(); ) { - Map.Entry entry = (Map.Entry) iter.next(); - String key = (String) entry.getKey(); - String value = (String) entry.getValue(); - if (!value.equals(activeProps.getProperty(key))) { - needNewSystem = true; - LogWriterUtils.getLogWriter().info("Forcing DS disconnect. For property " + key - + " old value = " + activeProps.getProperty(key) - + " new value = " + value); - break; - } - } - } - if(needNewSystem) { - // the current system does not meet our needs to disconnect and - // call recursively to get a new system. - LogWriterUtils.getLogWriter().info("Disconnecting from current DS in order to make a new one"); - disconnectFromDS(); - getSystem(props); - } - } - return system; - } - - /** - * Returns this VM's connection to the distributed system. If - * necessary, the connection will be lazily created using the - * <code>Properties</code> returned by {@link - * #getDistributedSystemProperties}. - * - * @see #getSystem(Properties) - * - * @since 3.0 - */ - public final InternalDistributedSystem getSystem() { - return getSystem(getDistributedSystemProperties()); - } - - /** - * Returns a loner distributed system that isn't connected to other - * vms - * - * @since 6.5 - */ - public final InternalDistributedSystem getLonerSystem() { - Properties props = getDistributedSystemProperties(); - props.put(DistributionConfig.MCAST_PORT_NAME, "0"); - props.put(DistributionConfig.LOCATORS_NAME, ""); - return getSystem(props); - } - - /** - * Returns a loner distributed system in combination with enforceUniqueHost - * and redundancyZone properties. - * Added specifically to test scenario of defect #47181. - */ - public final InternalDistributedSystem getLonerSystemWithEnforceUniqueHost() { - Properties props = getDistributedSystemProperties(); - props.put(DistributionConfig.MCAST_PORT_NAME, "0"); - props.put(DistributionConfig.LOCATORS_NAME, ""); - props.put(DistributionConfig.ENFORCE_UNIQUE_HOST_NAME, "true"); - props.put(DistributionConfig.REDUNDANCY_ZONE_NAME, "zone1"); - return getSystem(props); - } - - /** - * Returns whether or this VM is connected to a {@link - * DistributedSystem}. - */ - public final boolean isConnectedToDS() { - return system != null && system.isConnected(); - } - - /** - * Returns a <code>Properties</code> object used to configure a - * connection to a {@link - * com.gemstone.gemfire.distributed.DistributedSystem}. - * Unless overridden, this method will return an empty - * <code>Properties</code> object. - * - * @since 3.0 - */ - public Properties getDistributedSystemProperties() { - Properties props = new Properties(); - return props; - } - - public static void disconnectAllFromDS() { - disconnectFromDS(); - Invoke.invokeInEveryVM(()->disconnectFromDS()); - } - - /** - * Disconnects this VM from the distributed system - */ - public static void disconnectFromDS() { - setTestMethodName(null); - GemFireCacheImpl.testCacheXml = null; - if (system != null) { - system.disconnect(); - system = null; - } - - for (;;) { - DistributedSystem ds = InternalDistributedSystem.getConnectedInstance(); - if (ds == null) { - break; - } - try { - ds.disconnect(); - } catch (Exception e) { - // ignore - } - } - - AdminDistributedSystemImpl ads = AdminDistributedSystemImpl.getConnectedInstance(); - if (ads != null) {// && ads.isConnected()) { - ads.disconnect(); - } - } - - //--------------------------------------------------------------------------- - // name methods - //--------------------------------------------------------------------------- - - public static String getTestMethodName() { - return testMethodName; - } - - public static void setTestMethodName(final String testMethodName) { // TODO: delete - DistributedTestCase.testMethodName = testMethodName; - } - - /** - * Returns a unique name for this test method. It is based on the - * name of the class as well as the name of the method. - */ - public String getUniqueName() { - return getClass().getSimpleName() + "_" + getName(); - } - - //--------------------------------------------------------------------------- - // setup methods - //--------------------------------------------------------------------------- - - /** - * Sets up the DistributedTestCase. - * <p> - * Do not override this method. Override {@link #preSetUp()} with work that - * needs to occur before setUp() or override {@link #postSetUp()} with work - * that needs to occur after setUp(). - */ - @Override - public void setUp() throws Exception { - preSetUp(); - setUpDistributedTestCase(); - postSetUp(); - } - - /** - * Sets up DistributedTest in controller and remote VMs. This includes the - * defining the test name, setting the default disk store name, logging the - * test history, and capturing a creation stack for detecting the source of - * incompatible DistributedSystem connections. - * <p> - * Do not override this method. - */ - private final void setUpDistributedTestCase() { - final String className = getClass().getCanonicalName(); - final String methodName = getName(); - - logTestHistory(); - - setUpVM(methodName, getDefaultDiskStoreName(0, -1, className, methodName)); - - for (int hostIndex = 0; hostIndex < Host.getHostCount(); hostIndex++) { - Host host = Host.getHost(hostIndex); - for (int vmIndex = 0; vmIndex < host.getVMCount(); vmIndex++) { - final String vmDefaultDiskStoreName = getDefaultDiskStoreName(hostIndex, vmIndex, className, methodName); - host.getVM(vmIndex).invoke(()->setUpVM(methodName, vmDefaultDiskStoreName)); - } - } - - logTestStart(); - } - - /** - * <code>preSetUp()</code> is invoked before {@link #setUpDistributedTestCase()}. - * <p> - * Override this as needed. Default implementation is empty. - */ - protected void preSetUp() throws Exception { - } - - /** - * <code>postSetUp()</code> is invoked after {@link #setUpDistributedTestCase()}. - * <p> - * Override this as needed. Default implementation is empty. - */ - protected void postSetUp() throws Exception { - } - - private static String getDefaultDiskStoreName(final int hostIndex, final int vmIndex, final String className, final String methodName) { - return "DiskStore-" + String.valueOf(hostIndex) + "-" + String.valueOf(vmIndex) + "-" + className + "." + methodName; // used to be getDeclaringClass() - } - - private static void setUpVM(final String methodName, final String defaultDiskStoreName) { - setTestMethodName(methodName); - GemFireCacheImpl.setDefaultDiskStoreName(defaultDiskStoreName); - System.setProperty(HoplogConfig.ALLOW_LOCAL_HDFS_PROP, "true"); - setUpCreationStackGenerator(); - } - - private void logTestStart() { - System.out.println("\n\n[setup] START TEST " + getClass().getSimpleName()+"."+testMethodName+"\n\n"); - } - - private static void setUpCreationStackGenerator() { - // the following is moved from InternalDistributedSystem to fix #51058 - InternalDistributedSystem.TEST_CREATION_STACK_GENERATOR.set( - new CreationStackGenerator() { - @Override - public Throwable generateCreationStack(final DistributionConfig config) { - final StringBuilder sb = new StringBuilder(); - final String[] validAttributeNames = config.getAttributeNames(); - for (int i = 0; i < validAttributeNames.length; i++) { - final String attName = validAttributeNames[i]; - final Object actualAtt = config.getAttributeObject(attName); - String actualAttStr = actualAtt.toString(); - sb.append(" "); - sb.append(attName); - sb.append("=\""); - if (actualAtt.getClass().isArray()) { - actualAttStr = InternalDistributedSystem.arrayToString(actualAtt); - } - sb.append(actualAttStr); - sb.append("\""); - sb.append("\n"); - } - return new Throwable("Creating distributed system with the following configuration:\n" + sb.toString()); - } - }); - } - - /** - * 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); - } - - //--------------------------------------------------------------------------- - // teardown methods - //--------------------------------------------------------------------------- - - /** - * Tears down the DistributedTestCase. - * <p> - * Do not override this method. Override {@link #preTearDown()} with work that - * needs to occur before tearDown() or override {@link #postTearDown()} with work - * that needs to occur after tearDown(). - */ - @Override - public final void tearDown() throws Exception { - preTearDown(); - tearDownDistributedTestCase(); - postTearDown(); - } - - private final void tearDownDistributedTestCase() throws Exception { - Invoke.invokeInEveryVM(()->tearDownCreationStackGenerator()); - if (logPerTest) { - disconnectFromDS(); - Invoke.invokeInEveryVM(()->disconnectFromDS()); - } - cleanupAllVms(); - } - - /** - * <code>preTearDown()</code> is invoked before {@link #tearDownDistributedTestCase()}. - * <p> - * Override this as needed. Default implementation is empty. - */ - protected void preTearDown() throws Exception { - } - - /** - * <code>postTearDown()</code> is invoked after {@link #tearDownDistributedTestCase()}. - * <p> - * Override this as needed. Default implementation is empty. - */ - protected void postTearDown() throws Exception { - } - - public static void cleanupAllVms() { // TODO: make private - tearDownVM(); - Invoke.invokeInEveryVM(()->tearDownVM()); - Invoke.invokeInLocator(()->{ - DistributionMessageObserver.setInstance(null); - DistributedTestUtils.unregisterInstantiatorsInThisVM(); - }); - DUnitLauncher.closeAndCheckForSuspects(); - } - - private static void tearDownVM() { - closeCache(); - - // keep alphabetized to detect duplicate lines - CacheCreation.clearThreadLocals(); - CacheServerTestUtil.clearCacheReference(); - ClientProxyMembershipID.system = null; - ClientServerTestCase.AUTO_LOAD_BALANCE = false; - ClientStatsManager.cleanupForTests(); - DiskStoreObserver.setInstance(null); - DistributedTestUtils.unregisterInstantiatorsInThisVM(); - DistributionMessageObserver.setInstance(null); - GlobalLockingDUnitTest.region_testBug32356 = null; - InitialImageOperation.slowImageProcessing = 0; - InternalClientMembership.unregisterAllListeners(); - LogWrapper.close(); - MultiVMRegionTestCase.CCRegion = null; - QueryObserverHolder.reset(); - QueryTestUtils.setCache(null); - RegionTestCase.preSnapshotRegion = null; - SocketCreator.resetHostNameCache(); - SocketCreator.resolve_dns = true; - TcpClient.clearStaticData(); - - // clear system properties -- keep alphabetized - System.clearProperty("gemfire.log-level"); - System.clearProperty(HoplogConfig.ALLOW_LOCAL_HDFS_PROP); - System.clearProperty("jgroups.resolve_dns"); - - if (InternalDistributedSystem.systemAttemptingReconnect != null) { - InternalDistributedSystem.systemAttemptingReconnect.stopReconnecting(); - } - - IgnoredException.removeAllExpectedExceptions(); - } - - private static void closeCache() { - GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); - if (cache != null && !cache.isClosed()) { - destroyRegions(cache); - cache.close(); - } - } - - protected static final void destroyRegions(final Cache cache) { // TODO: make private - 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 regionFullPath = root == null ? null : root.getFullPath(); - // 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 (Throwable t) { - logger.error("Failure during tearDown destroyRegions for " + regionFullPath, t); - } - } - } - } - - private static void tearDownCreationStackGenerator() { - InternalDistributedSystem.TEST_CREATION_STACK_GENERATOR.set(InternalDistributedSystem.DEFAULT_CREATION_STACK_GENERATOR); - } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/CacheTestFixture.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/CacheTestFixture.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/CacheTestFixture.java new file mode 100644 index 0000000..f0f64d4 --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/CacheTestFixture.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.test.dunit.cache.internal; + +import com.gemstone.gemfire.test.dunit.internal.DistributedTestFixture; + +/** + * Defines the {@code CacheTestCase} methods that can be overridden by its subclasses. + */ +public interface CacheTestFixture extends DistributedTestFixture { + + /** + * {@code preTearDownCacheTestCase()} is invoked before {@code CacheTestCase#tearDownCacheTestCase()}. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void preTearDownCacheTestCase() throws Exception; + + /** + * {@code postTearDownCacheTestCase()} is invoked after {@code CacheTestCase#tearDownCacheTestCase()}. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void postTearDownCacheTestCase() throws Exception; + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit3CacheTestCase.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit3CacheTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit3CacheTestCase.java new file mode 100644 index 0000000..afbb29d --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit3CacheTestCase.java @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.test.dunit.cache.internal; + +import java.io.File; +import java.io.IOException; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheException; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.RegionExistsException; +import com.gemstone.gemfire.cache.TimeoutException; +import com.gemstone.gemfire.cache.client.ClientCache; +import com.gemstone.gemfire.cache.client.ClientCacheFactory; +import com.gemstone.gemfire.cache30.CacheSerializableRunnable; +import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; +import com.gemstone.gemfire.test.dunit.IgnoredException; +import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase; + +/** + * The abstract superclass of tests that require the creation of a + * {@link Cache}. + */ +public abstract class JUnit3CacheTestCase extends JUnit3DistributedTestCase implements CacheTestFixture { + + private final JUnit4CacheTestCase delegate = new JUnit4CacheTestCase(this); + + public JUnit3CacheTestCase(final String name) { + super(name); + } + + /** + * Creates the {@code Cache} for this test that is not connected to other + * members. + */ + public final Cache createLonerCache() { + return delegate.createLonerCache(); + } + + /** + * Sets this test up with a {@code CacheCreation} as its cache. Any existing + * cache is closed. Whoever calls this must also call {@code finishCacheXml}. + */ + public static final void beginCacheXml() { + JUnit4CacheTestCase.beginCacheXml(); + } + + /** + * Finish what {@code beginCacheXml} started. It does this be generating a + * cache.xml file and then creating a real cache using that cache.xml. + */ + public final void finishCacheXml(final String name) { + delegate.finishCacheXml(name); + } + + /** + * Finish what {@code beginCacheXml} started. It does this be generating a + * cache.xml file and then creating a real cache using that cache.xml. + */ + public final void finishCacheXml(final String name, final boolean useSchema, final String xmlVersion) { + delegate.finishCacheXml(name, useSchema, xmlVersion); + } + + /** + * Return a cache for obtaining regions, created lazily. + */ + public final Cache getCache() { + return delegate.getCache(); + } + + public final Cache getCache(final CacheFactory factory) { + return delegate.getCache(factory); + } + + public final Cache getCache(final boolean client) { + return delegate.getCache(client); + } + + public final Cache getCache(final boolean client, final CacheFactory factory) { + return delegate.getCache(client, factory); + } + + /** + * Creates a client cache from the factory if one does not already exist. + * + * @since 6.5 + */ + public final ClientCache getClientCache(final ClientCacheFactory factory) { + return delegate.getClientCache(factory); + } + + /** + * Invokes {@link #getCache()} and casts the return to + * {@code GemFireCacheImpl}. + */ + public final GemFireCacheImpl getGemfireCache() { // TODO: remove? + return delegate.getGemfireCache(); + } + + public static final boolean hasCache() { + return JUnit4CacheTestCase.hasCache(); + } + + /** + * Return current cache without creating one. + */ + public static final Cache basicGetCache() { + return JUnit4CacheTestCase.basicGetCache(); + } + + /** + * Close the cache. + */ + public static final void closeCache() { + JUnit4CacheTestCase.closeCache(); + } + + /** + * Closed the cache in all VMs. + */ + protected final void closeAllCache() { + delegate.closeAllCache(); + } + + @Override + public final void preTearDown() throws Exception { + delegate.preTearDown(); + } + + @Override + public void preTearDownCacheTestCase() throws Exception { + } + + @Override + public void postTearDownCacheTestCase() throws Exception { + } + + /** + * Local destroy all root regions and close the cache. + */ + protected static final void remoteTearDown() { + JUnit4CacheTestCase.remoteTearDown(); + } + + /** + * Returns a region with the given name and attributes + */ + public final Region createRegion(final String name, final RegionAttributes attributes) throws CacheException { + return delegate.createRegion(name, attributes); + } + + public final Region createRegion(final String name, final String rootName, final RegionAttributes attributes) throws CacheException { + return delegate.createRegion(name, rootName, attributes); + } + + public final Region getRootRegion() { + return delegate.getRootRegion(); + } + + public final Region getRootRegion(final String rootName) { + return delegate.getRootRegion(rootName); + } + + protected final Region createRootRegion(final RegionAttributes attributes) throws RegionExistsException, TimeoutException { + return delegate.createRootRegion(attributes); + } + + public final Region createRootRegion(final String rootName, final RegionAttributes attributes) throws RegionExistsException, TimeoutException { + return delegate.createRootRegion(rootName, attributes); + } + + public final Region createExpiryRootRegion(final String rootName, final RegionAttributes attributes) throws RegionExistsException, TimeoutException { + return delegate.createExpiryRootRegion(rootName, attributes); + } + + /** + * @deprecated Please use {@link IgnoredException#addIgnoredException(String)} instead. + */ + @Deprecated + public final CacheSerializableRunnable addExceptionTag1(final String exceptionStringToIgnore) { + return delegate.addExceptionTag1(exceptionStringToIgnore); + } + + /** + * @deprecated Please use {@link IgnoredException#remove()} instead. + */ + @Deprecated + public final CacheSerializableRunnable removeExceptionTag1(final String exceptionStringToIgnore) { + return delegate.removeExceptionTag1(exceptionStringToIgnore); + } + + public static final File getDiskDir() { + return JUnit4CacheTestCase.getDiskDir(); + } + + /** + * Return a set of disk directories for persistence tests. These directories + * will be automatically cleaned up during tear down. + */ + public static final File[] getDiskDirs() { + return JUnit4CacheTestCase.getDiskDirs(); + } + + public static final void cleanDiskDirs() throws IOException { + JUnit4CacheTestCase.cleanDiskDirs(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit4CacheTestCase.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit4CacheTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit4CacheTestCase.java new file mode 100644 index 0000000..d3988ef --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/cache/internal/JUnit4CacheTestCase.java @@ -0,0 +1,567 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.test.dunit.cache.internal; + +import java.io.File; +import java.io.FileWriter; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Map; +import java.util.Properties; + +import com.gemstone.gemfire.cache.AttributesFactory; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheException; +import com.gemstone.gemfire.cache.CacheExistsException; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.CacheTransactionManager; +import com.gemstone.gemfire.cache.ExpirationAttributes; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.RegionExistsException; +import com.gemstone.gemfire.cache.TimeoutException; +import com.gemstone.gemfire.cache.client.ClientCache; +import com.gemstone.gemfire.cache.client.ClientCacheFactory; +import com.gemstone.gemfire.cache.client.PoolManager; +import com.gemstone.gemfire.cache30.CacheSerializableRunnable; +import com.gemstone.gemfire.distributed.internal.DistributionMessageObserver; +import com.gemstone.gemfire.internal.FileUtil; +import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; +import com.gemstone.gemfire.internal.cache.InternalRegionArguments; +import com.gemstone.gemfire.internal.cache.LocalRegion; +import com.gemstone.gemfire.internal.cache.xmlcache.CacheCreation; +import com.gemstone.gemfire.internal.cache.xmlcache.CacheXmlGenerator; +import com.gemstone.gemfire.internal.logging.LogService; +import com.gemstone.gemfire.test.dunit.Assert; +import com.gemstone.gemfire.test.dunit.IgnoredException; +import com.gemstone.gemfire.test.dunit.Invoke; +import com.gemstone.gemfire.test.dunit.LogWriterUtils; +import com.gemstone.gemfire.test.dunit.VM; +import com.gemstone.gemfire.test.dunit.Wait; +import com.gemstone.gemfire.test.dunit.WaitCriterion; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; +import org.apache.logging.log4j.Logger; + +/** + * This class is the base class for all distributed tests using JUnit 4 that + * require the creation of a {@link Cache}. + * + * TODO: make this class abstract when JUnit3CacheTestCase is deleted + */ +public class JUnit4CacheTestCase extends JUnit4DistributedTestCase implements CacheTestFixture { + + private static final Logger logger = LogService.getLogger(); + + /** + * The Cache from which regions are obtained. + * + * <p>All references synchronized via {@code JUnit4CacheTestCase.class}. + * + * <p>Field is static so it doesn't get serialized with SerializableRunnable inner classes. + */ + private static Cache cache; + + private final CacheTestFixture cacheTestFixture; + + public JUnit4CacheTestCase() { + this((CacheTestFixture)null); + } + + JUnit4CacheTestCase(final CacheTestFixture cacheTestFixture) { + super(cacheTestFixture); + if (cacheTestFixture == null) { + this.cacheTestFixture = this; + } else { + this.cacheTestFixture = cacheTestFixture; + } + } + + /** + * Creates the {@code Cache} for this test + */ + private final void createCache() { + createCache(false); + } + + private final void createCache(final boolean client) { + createCache(client, null); + } + + private final void createCache(final boolean client, final CacheFactory factory) { + synchronized(JUnit4CacheTestCase.class) { + try { + System.setProperty("gemfire.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true"); + Cache newCache; + if (client) { + newCache = (Cache)new ClientCacheFactory(getSystem().getProperties()).create(); + } else { + if(factory == null) { + newCache = CacheFactory.create(getSystem()); + } else { + Properties props = getSystem().getProperties(); + for(Map.Entry entry : props.entrySet()) { + factory.set((String) entry.getKey(), (String)entry.getValue()); + } + newCache = factory.create(); + } + } + cache = newCache; + } catch (CacheExistsException e) { + Assert.fail("the cache already exists", e); // TODO: remove error handling + + } catch (RuntimeException ex) { + throw ex; + + } catch (Exception ex) { + Assert.fail("Checked exception while initializing cache??", ex); + } finally { + System.clearProperty("gemfire.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE"); + } + } + } + + /** + * Creates the {@code Cache} for this test that is not connected to other + * members. + */ + public final Cache createLonerCache() { + synchronized(JUnit4CacheTestCase.class) { + try { + System.setProperty("gemfire.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true"); + Cache newCache = CacheFactory.create(getLonerSystem()); + cache = newCache; + } catch (CacheExistsException e) { + Assert.fail("the cache already exists", e); // TODO: remove error handling + + } catch (RuntimeException ex) { + throw ex; + + } catch (Exception ex) { + Assert.fail("Checked exception while initializing cache??", ex); + } finally { + System.clearProperty("gemfire.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE"); + } + return cache; + } + } + + /** + * Sets this test up with a {@code CacheCreation} as its cache. Any existing + * cache is closed. Whoever calls this must also call {@code finishCacheXml}. + */ + public static final synchronized void beginCacheXml() { + closeCache(); + cache = new TestCacheCreation(); + } + + /** + * Finish what {@code beginCacheXml} started. It does this be generating a + * cache.xml file and then creating a real cache using that cache.xml. + */ + public final void finishCacheXml(final String name) { + synchronized(JUnit4CacheTestCase.class) { + File file = new File(name + "-cache.xml"); + try { + PrintWriter pw = new PrintWriter(new FileWriter(file), true); + CacheXmlGenerator.generate(cache, pw); + pw.close(); + } catch (IOException ex) { + Assert.fail("IOException during cache.xml generation to " + file, ex); // TODO: remove error handling + } + cache = null; + GemFireCacheImpl.testCacheXml = file; + try { + createCache(); + } finally { + GemFireCacheImpl.testCacheXml = null; + } + } + } + + /** + * Finish what {@code beginCacheXml} started. It does this be generating a + * cache.xml file and then creating a real cache using that cache.xml. + */ + public final void finishCacheXml(final String name, final boolean useSchema, final String xmlVersion) { + synchronized(JUnit4CacheTestCase.class) { + File dir = new File("XML_" + xmlVersion); + dir.mkdirs(); + File file = new File(dir, name + ".xml"); + try { + PrintWriter pw = new PrintWriter(new FileWriter(file), true); + CacheXmlGenerator.generate(cache, pw, useSchema, xmlVersion); + pw.close(); + } catch (IOException ex) { + Assert.fail("IOException during cache.xml generation to " + file, ex); // TODO: remove error handling + } + cache = null; + GemFireCacheImpl.testCacheXml = file; + try { + createCache(); + } finally { + GemFireCacheImpl.testCacheXml = null; + } + } + } + + /** + * Return a cache for obtaining regions, created lazily. + */ + public final Cache getCache() { + return getCache(false); + } + + public final Cache getCache(final CacheFactory factory) { + return getCache(false, factory); + } + + public final Cache getCache(final boolean client) { + return getCache(client, null); + } + + public final Cache getCache(final boolean client, final CacheFactory factory) { + synchronized (JUnit4CacheTestCase.class) { + final GemFireCacheImpl gemFireCache = GemFireCacheImpl.getInstance(); + if (gemFireCache != null && !gemFireCache.isClosed() + && gemFireCache.getCancelCriterion().cancelInProgress() != null) { + Wait.waitForCriterion(new WaitCriterion() { // TODO: replace with Awaitility + @Override + public boolean done() { + return gemFireCache.isClosed(); + } + @Override + public String description() { + return "waiting for cache to close"; + } + }, 30 * 1000, 300, true); + } + if (cache == null || cache.isClosed()) { + cache = null; + createCache(client, factory); + } + if (client && cache != null) { + IgnoredException.addIgnoredException("java.net.ConnectException"); + } + return cache; + } + } + + /** + * Creates a client cache from the factory if one does not already exist. + * + * @since 6.5 + */ + public final ClientCache getClientCache(final ClientCacheFactory factory) { + synchronized (JUnit4CacheTestCase.class) { + final GemFireCacheImpl gemFireCache = GemFireCacheImpl.getInstance(); + if (gemFireCache != null && !gemFireCache.isClosed() + && gemFireCache.getCancelCriterion().cancelInProgress() != null) { + Wait.waitForCriterion(new WaitCriterion() { // TODO: replace with Awaitility + @Override + public boolean done() { + return gemFireCache.isClosed(); + } + @Override + public String description() { + return "waiting for cache to close"; + } + }, 30 * 1000, 300, true); + } + if (cache == null || cache.isClosed()) { + cache = null; + disconnectFromDS(); + cache = (Cache)factory.create(); + } + if (cache != null) { + IgnoredException.addIgnoredException("java.net.ConnectException"); + } + return (ClientCache)cache; + } + } + + /** + * Invokes {@link #getCache()} and casts the return to + * {@code GemFireCacheImpl}. + */ + public final GemFireCacheImpl getGemfireCache() { // TODO: remove? + return (GemFireCacheImpl)getCache(); + } + + public static final synchronized boolean hasCache() { + return cache != null; + } + + /** + * Return current cache without creating one. + */ + public static final synchronized Cache basicGetCache() { + return cache; + } + + /** + * Close the cache. + */ + public static final synchronized void closeCache() { + // Workaround for that fact that some classes are now extending + // CacheTestCase but not using it properly. + if(cache == null) { + cache = GemFireCacheImpl.getInstance(); + } + try { + if (cache != null) { + try { + if (!cache.isClosed()) { + if (cache instanceof GemFireCacheImpl) { + CacheTransactionManager txMgr = ((GemFireCacheImpl)cache).getTxManager(); + if (txMgr != null) { + if (txMgr.exists()) { + try { + // make sure we cleanup this threads txid stored in a thread local + txMgr.rollback(); + }catch(Exception ignore) { + + } + } + } + } + cache.close(); + } + } + finally { + cache = null; + } + } // cache != null + } finally { + //Make sure all pools are closed, even if we never + //created a cache + PoolManager.close(false); + } + } + + /** + * Close the cache in all VMs. + */ + protected final void closeAllCache() { + closeCache(); + Invoke.invokeInEveryVM(()->closeCache()); + } + + @Override + public final void preTearDown() throws Exception { + preTearDownCacheTestCase(); + tearDownCacheTestCase(); + postTearDownCacheTestCase(); + } + + private final void tearDownCacheTestCase() { + remoteTearDown(); + Invoke.invokeInEveryVM(()->remoteTearDown()); + } + + @Override + public void preTearDownCacheTestCase() throws Exception { + if (this.cacheTestFixture != this) { + this.cacheTestFixture.preTearDownCacheTestCase(); + } + } + + @Override + public void postTearDownCacheTestCase() throws Exception { + if (this.cacheTestFixture != this) { + this.cacheTestFixture.postTearDownCacheTestCase(); + } + } + + /** + * Local destroy all root regions and close the cache. + */ + protected static final synchronized void remoteTearDown() { + try { + DistributionMessageObserver.setInstance(null); + destroyRegions(cache); + } + finally { + try { + closeCache(); + } + finally { + try { + cleanDiskDirs(); + } catch(Exception e) { + LogWriterUtils.getLogWriter().error("Error cleaning disk dirs", e); + } + } + } + } + + /** + * Returns a region with the given name and attributes. + */ + public final Region createRegion(final String name, final RegionAttributes attributes) throws CacheException { + return createRegion(name, "root", attributes); + } + + /** + * Provide any internal region arguments, typically required when internal + * use (aka meta-data) regions are needed. + * + * @return internal arguments, which may be null. If null, then default + * InternalRegionArguments are used to construct the Region + */ + private final InternalRegionArguments getInternalRegionArguments() { // TODO: delete? + return null; + } + + public final Region createRegion(final String name, final String rootName, final RegionAttributes attributes) throws CacheException { + Region root = getRootRegion(rootName); + if (root == null) { + // don't put listeners on root region + RegionAttributes rootAttrs = attributes; + AttributesFactory fac = new AttributesFactory(attributes); + ExpirationAttributes expiration = ExpirationAttributes.DEFAULT; + + // fac.setCacheListener(null); + fac.setCacheLoader(null); + fac.setCacheWriter(null); + fac.setPoolName(null); + fac.setPartitionAttributes(null); + fac.setRegionTimeToLive(expiration); + fac.setEntryTimeToLive(expiration); + fac.setRegionIdleTimeout(expiration); + fac.setEntryIdleTimeout(expiration); + rootAttrs = fac.create(); + root = createRootRegion(rootName, rootAttrs); + } + + InternalRegionArguments internalArgs = getInternalRegionArguments(); + if (internalArgs == null) { + return root.createSubregion(name, attributes); + } else { + try { + LocalRegion lr = (LocalRegion) root; + return lr.createSubregion(name, attributes, internalArgs); + } catch (IOException ioe) { + AssertionError assErr = new AssertionError("unexpected exception"); + assErr.initCause(ioe); + throw assErr; + } catch (ClassNotFoundException cnfe) { + AssertionError assErr = new AssertionError("unexpected exception"); + assErr.initCause(cnfe); + throw assErr; + } + } + } + + public final Region getRootRegion() { + return getRootRegion("root"); + } + + public final Region getRootRegion(final String rootName) { + return getCache().getRegion(rootName); + } + + protected final Region createRootRegion(final RegionAttributes attributes) throws RegionExistsException, TimeoutException { + return createRootRegion("root", attributes); + } + + public final Region createRootRegion(final String rootName, final RegionAttributes attributes) throws RegionExistsException, TimeoutException { + return getCache().createRegion(rootName, attributes); + } + + public final Region createExpiryRootRegion(final String rootName, final RegionAttributes attributes) throws RegionExistsException, TimeoutException { + System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true"); + try { + return createRootRegion(rootName, attributes); + } finally { + System.clearProperty(LocalRegion.EXPIRY_MS_PROPERTY); + } + } + + /** + * @deprecated Please use {@link IgnoredException#addIgnoredException(String)} instead. + */ + @Deprecated + public final CacheSerializableRunnable addExceptionTag1(final String exceptionStringToIgnore) { // TODO: delete this method + CacheSerializableRunnable addExceptionTag = new CacheSerializableRunnable("addExceptionTag") { + @Override + public void run2() { + getCache().getLogger().info("<ExpectedException action=add>" + exceptionStringToIgnore + "</ExpectedException>"); + } + }; + return addExceptionTag; + } + + /** + * @deprecated Please use {@link IgnoredException#addIgnoredException(String)} instead. + */ + @Deprecated + public final CacheSerializableRunnable removeExceptionTag1(final String exceptionStringToIgnore) { // TODO: delete this method + CacheSerializableRunnable removeExceptionTag = new CacheSerializableRunnable("removeExceptionTag") { + @Override + public void run2() throws CacheException { + getCache().getLogger().info("<ExpectedException action=remove>" + exceptionStringToIgnore + "</ExpectedException>"); + } + }; + return removeExceptionTag; + } + + public static final File getDiskDir() { + int vmNum = VM.getCurrentVMNum(); + File dir = new File("diskDir", "disk" + String.valueOf(vmNum)).getAbsoluteFile(); + dir.mkdirs(); + return dir; + } + + /** + * Return a set of disk directories for persistence tests. These directories + * will be automatically cleaned up on test case closure. + */ + public static final File[] getDiskDirs() { + return new File[] {getDiskDir()}; + } + + public static final void cleanDiskDirs() throws IOException { + FileUtil.delete(getDiskDir()); + File[] defaultStoreFiles = new File(".").listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.startsWith("BACKUPDiskStore-" + System.getProperty("vmid")); + } + }); + + for(File file: defaultStoreFiles) { + FileUtil.delete(file); + } + } + + /** + * Used to generate a cache.xml. Basically just a {@code CacheCreation} with + * a few more methods implemented. + */ + private static final class TestCacheCreation extends CacheCreation { + private boolean closed = false; + @Override + public void close() { + this.closed = true; + } + @Override + public boolean isClosed() { + return this.closed; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java new file mode 100755 index 0000000..46c24b2 --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/DistributedTestFixture.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.gemstone.gemfire.test.dunit.internal; + +import java.util.Properties; + +/** + * Defines the {@code DistributedTestCase} methods that can be overridden by its subclasses. + */ +public interface DistributedTestFixture { + + /** + * {@code preSetUp()} is invoked before {@code DistributedTestCase#setUp()}. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void preSetUp() throws Exception; + + /** + * {@code postSetUp()} is invoked after {@code DistributedTestCase#setUp()}. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void postSetUp() throws Exception; + + /** + * {@code preTearDown()} is invoked before {@code DistributedTestCase#tearDown()}. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void preTearDown() throws Exception; + + /** + * {@code postTearDown()} is invoked after {@code DistributedTestCase#tearDown()}. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void postTearDown() throws Exception; + + /** + * {@code preTearDownAssertions()} is invoked before any tear down methods + * have been invoked. If this method throws anything, tear down methods will + * still be invoked. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void preTearDownAssertions() throws Exception; + + /** + * {@code postTearDownAssertions()} is invoked after all tear down methods + * have completed. This method will not be invoked if + * {@code preTearDownAssertions()} throws. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void postTearDownAssertions() throws Exception; + + /** + * Returns the {@code Properties} used to define the {@code DistributedSystem}. + * + * <p>Override this as needed. This method is called by various + * {@code getSystem} methods in {@code DistributedTestCase}. + */ + public Properties getDistributedSystemProperties(); + + /** + * Returns the {@code name} of the test method being executed. + */ + public String getName(); + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java new file mode 100755 index 0000000..f453e7e --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/test/dunit/internal/JUnit3DistributedTestCase.java @@ -0,0 +1,247 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.test.dunit.internal; + +import java.io.Serializable; +import java.util.Properties; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.distributed.DistributedSystem; +import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; +import com.gemstone.gemfire.internal.logging.LogService; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; +import junit.framework.TestCase; +import org.apache.logging.log4j.Logger; +import org.junit.experimental.categories.Category; + +/** + * This class is the superclass of all distributed tests using JUnit 3. + */ +@Category(DistributedTest.class) +public abstract class JUnit3DistributedTestCase extends TestCase implements DistributedTestFixture, Serializable { + + private static final Logger logger = LogService.getLogger(); + + private final JUnit4DistributedTestCase delegate = new JUnit4DistributedTestCase(this); + + /** + * Constructs a new distributed test. All JUnit 3 test classes need to have a + * String-arg constructor. + */ + public JUnit3DistributedTestCase(final String name) { + super(name); + JUnit4DistributedTestCase.initializeDistributedTestCase(); + } + + //--------------------------------------------------------------------------- + // methods for tests + //--------------------------------------------------------------------------- + + /** + * @deprecated Please override {@link #getDistributedSystemProperties()} instead. + */ + @Deprecated + public final void setSystem(final Properties props, final DistributedSystem ds) { // TODO: override getDistributedSystemProperties and then delete + delegate.setSystem(props, ds); + } + + /** + * Returns this VM's connection to the distributed system. If necessary, the + * connection will be lazily created using the given {@code Properties}. + * + * <p>Do not override this method. Override {@link #getDistributedSystemProperties()} + * instead. + * + * <p>Note: "final" was removed so that WANTestBase can override this method. + * This was part of the xd offheap merge. + * + * @since 3.0 + */ + public final InternalDistributedSystem getSystem(final Properties props) { + return delegate.getSystem(props); + } + + /** + * Returns this VM's connection to the distributed system. If necessary, the + * connection will be lazily created using the {@code Properties} returned by + * {@link #getDistributedSystemProperties()}. + * + * <p>Do not override this method. Override {@link #getDistributedSystemProperties()} + * instead. + * + * @see #getSystem(Properties) + * + * @since 3.0 + */ + public final InternalDistributedSystem getSystem() { + return delegate.getSystem(); + } + + public final InternalDistributedSystem basicGetSystem() { + return delegate.basicGetSystem(); + } + + public final void nullSystem() { // TODO: delete + delegate.nullSystem(); + } + + public static final InternalDistributedSystem getSystemStatic() { + return JUnit4DistributedTestCase.getSystemStatic(); + } + + /** + * Returns a loner distributed system that isn't connected to other vms. + * + * @since 6.5 + */ + public final InternalDistributedSystem getLonerSystem() { + return delegate.getLonerSystem(); + } + + /** + * Returns whether or this VM is connected to a {@link DistributedSystem}. + */ + public final boolean isConnectedToDS() { + return delegate.isConnectedToDS(); + } + + /** + * Returns a {@code Properties} object used to configure a connection to a + * {@link DistributedSystem}. Unless overridden, this method will return an + * empty {@code Properties} object. + * + * @since 3.0 + */ + public Properties getDistributedSystemProperties() { + return delegate.defaultGetDistributedSystemProperties(); + } + + public static final void disconnectAllFromDS() { + JUnit4DistributedTestCase.disconnectAllFromDS(); + } + + /** + * Disconnects this VM from the distributed system + */ + public static final void disconnectFromDS() { + JUnit4DistributedTestCase.disconnectFromDS(); + } + + //--------------------------------------------------------------------------- + // name methods + //--------------------------------------------------------------------------- + + public static final String getTestMethodName() { + return JUnit4DistributedTestCase.getTestMethodName(); + } + + /** + * Returns a unique name for this test method. It is based on the + * name of the class as well as the name of the method. + */ + public final String getUniqueName() { + return delegate.getUniqueName(); + } + + //--------------------------------------------------------------------------- + // setup methods + //--------------------------------------------------------------------------- + + /** + * Sets up the DistributedTestCase. + * <p> + * Do not override this method. Override {@link #preSetUp()} with work that + * needs to occur before setUp() or override {@link #postSetUp()} with work + * that needs to occur after setUp(). + */ + @Override + public final void setUp() throws Exception { + delegate.setUp(); + } + + /** + * {@code preSetUp()} is invoked before {@link JUnit4DistributedTestCase#setUpDistributedTestCase()}. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void preSetUp() throws Exception { + } + + /** + * {@code postSetUp()} is invoked after {@link JUnit4DistributedTestCase#setUpDistributedTestCase()}. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void postSetUp() throws Exception { + } + + //--------------------------------------------------------------------------- + // teardown methods + //--------------------------------------------------------------------------- + + /** + * Tears down the DistributedTestCase. + * + * <p>Do not override this method. Override {@link #preTearDown()} with work that + * needs to occur before tearDown() or override {@link #postTearDown()} with work + * that needs to occur after tearDown(). + */ + @Override + public final void tearDown() throws Exception { + delegate.tearDown(); + } + + /** + * {@code preTearDown()} is invoked before {@link JUnit4DistributedTestCase#tearDownDistributedTestCase()}. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void preTearDown() throws Exception { + } + + /** + * {@code postTearDown()} is invoked after {@link JUnit4DistributedTestCase#tearDownDistributedTestCase()}. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void postTearDown() throws Exception { + } + + /** + * {@code preTearDownAssertions()} is invoked before any tear down methods + * have been invoked. If this method throws anything, tear down methods will + * still be invoked. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void preTearDownAssertions() throws Exception { + } + + /** + * {@code postTearDownAssertions()} is invoked after all tear down methods + * have completed. This method will not be invoked if + * {@code preTearDownAssertions()} throws. + * + * <p>Override this as needed. Default implementation is empty. + */ + public void postTearDownAssertions() throws Exception { + } + + protected static final void destroyRegions(final Cache cache) { // TODO: this should move to CacheTestCase + JUnit4DistributedTestCase.destroyRegions(cache); + } +}
