You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2015/08/25 17:58:20 UTC
incubator-geode git commit: More changes
Repository: incubator-geode
Updated Branches:
refs/heads/feature/GEODE-217 09403b2cf -> 921ce90df
More changes
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/921ce90d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/921ce90d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/921ce90d
Branch: refs/heads/feature/GEODE-217
Commit: 921ce90dfbb7e472c45330d23f30381948c26725
Parents: 09403b2
Author: Kirk Lund <kl...@pivotal.io>
Authored: Tue Aug 25 08:57:29 2015 -0700
Committer: Kirk Lund <kl...@pivotal.io>
Committed: Tue Aug 25 08:57:29 2015 -0700
----------------------------------------------------------------------
.../internal/lang/reflect/ReflectionUtils.java | 17 +-
.../lang/reflect/ReflectionUtilsJUnitTest.java | 46 +-
.../gemfire/test/dunit/DUnitTestRule.java | 628 +++++++++++++++++++
.../gemfire/test/dunit/DistributedTestCase.java | 14 +-
.../gemfire/test/dunit/standalone/ChildVM.java | 3 -
.../test/dunit/tests/BasicDUnitTest.java | 2 +-
.../tests/DistributedTestNameDUnitTest.java | 10 +-
.../DistributedTestNameWithRuleDUnitTest.java | 66 ++
.../dunit/tests/LogPerTestOneDUnitTest.java | 39 ++
.../test/dunit/tests/LogPerTestSuite.java | 12 +
.../dunit/tests/LogPerTestTwoDUnitTest.java | 39 ++
.../gemfire/test/dunit/tests/MyTestSuite.java | 5 +
.../SerializableTemporaryFolderDUnitTest.java | 49 ++
.../tests/SerializableTestNameDUnitTest.java | 49 ++
.../tests/SerializableTestWatcherDUnitTest.java | 67 ++
.../gemfire/test/dunit/tests/VMDUnitTest.java | 2 +-
.../test/dunit/tests/VMMoreDUnitTest.java | 65 ++
.../rules/SerializableTemporaryFolder.java | 49 ++
.../test/junit/rules/SerializableTestName.java | 33 +
.../junit/rules/SerializableTestWatcher.java | 9 +
.../test/junit/rules/SerializableTimeout.java | 98 +++
21 files changed, 1268 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/main/java/com/gemstone/gemfire/internal/lang/reflect/ReflectionUtils.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/lang/reflect/ReflectionUtils.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/lang/reflect/ReflectionUtils.java
index 0b5fee2..b183012 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/lang/reflect/ReflectionUtils.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/lang/reflect/ReflectionUtils.java
@@ -37,5 +37,20 @@ public abstract class ReflectionUtils {
public static String getMethodName() {
return Thread.currentThread().getStackTrace()[2].getMethodName();
}
-}
+
+ public static String getSimpleClassName(final String className) {
+ if (className.indexOf(".") > -1) {
+ return className.substring(className.lastIndexOf(".")+1);
+ } else {
+ return className;
+ }
+ }
+ public static String getSimpleClassName(final int depth) {
+ return getSimpleClassName(Thread.currentThread().getStackTrace()[depth].getClassName());
+ }
+
+ public static String getSimpleClassName() {
+ return getSimpleClassName(Thread.currentThread().getStackTrace()[2].getClassName());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/internal/lang/reflect/ReflectionUtilsJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/lang/reflect/ReflectionUtilsJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/lang/reflect/ReflectionUtilsJUnitTest.java
index 346dc75..4fad81e 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/lang/reflect/ReflectionUtilsJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/lang/reflect/ReflectionUtilsJUnitTest.java
@@ -33,28 +33,46 @@ public class ReflectionUtilsJUnitTest {
private String testMethodName;
@Test
- public void getClassNameZeroShouldReturnReflectionUtilsClass() {
+ public void getClassNameZeroShouldReturnThreadClassName() {
assertThat(getClassName(0), is(Thread.class.getName()));
}
@Test
- public void getClassNameOneShouldReturnReflectionUtilsClass() {
+ public void getSimpleClassNameZeroShouldReturnThreadClassSimpleName() {
+ assertThat(getSimpleClassName(0), is(Thread.class.getSimpleName()));
+ }
+
+ @Test
+ public void getClassNameOneShouldReturnReflectionUtilsClassName() {
assertThat(getClassName(1), is(ReflectionUtils.class.getName()));
}
@Test
- public void getClassNameTwoShouldReturnReflectionUtilsClass() {
- assertThat(getClassName(2), is(getClass().getName()));
+ public void getSimpleClassNameOneShouldReturnReflectionUtilsClassSimpleName() {
+ assertThat(getSimpleClassName(1), is(ReflectionUtils.class.getSimpleName()));
+ }
+
+ @Test
+ public void getClassNameTwoShouldReturnThisClassName() {
assertThat(getClassName(2), is(this.testClassName));
}
@Test
- public void getClassNameShouldReturnReflectionUtilsClass() {
- assertThat(getClassName(), is(getClass().getName()));
+ public void getSimpleClassNameTwoShouldReturnThisClassSimpleName() {
+ assertThat(getSimpleClassName(2), is(getSimpleClassName(this.testClassName)));
+ }
+
+ @Test
+ public void getClassNameShouldReturnThisClassName() {
assertThat(getClassName(), is(this.testClassName));
}
@Test
+ public void getSimpleClassNameShouldReturnThisClassSimpleName() {
+ assertThat(getSimpleClassName(), is(getSimpleClassName(this.testClassName)));
+ }
+
+ @Test
public void getMethodNameZeroShouldReturnGetStackTrace() {
assertThat(getMethodName(0), is("getStackTrace"));
}
@@ -65,14 +83,22 @@ public class ReflectionUtilsJUnitTest {
}
@Test
- public void getMethodNameTwoShouldReturnThisMethod() {
- assertThat(getMethodName(2), is("getMethodNameTwoShouldReturnThisMethod"));
+ public void getMethodNameTwoShouldReturnThisMethodName() {
assertThat(getMethodName(2), is(this.testMethodName));
}
@Test
- public void getMethodNameShouldReturnThisMethod() {
- assertThat(getMethodName(), is("getMethodNameShouldReturnThisMethod"));
+ public void getMethodNameShouldReturnThisMethodName() {
assertThat(getMethodName(), is(this.testMethodName));
}
+
+ @Test
+ public void getSimpleClassNameWithPackageShouldRemovePackage() {
+ assertThat(getSimpleClassName(getClass().getSimpleName()), is(getClass().getSimpleName()));
+ }
+
+ @Test
+ public void getSimpleClassNameWithoutPackageShouldReturnClassName() {
+ assertThat(getSimpleClassName("SomeClass"), is("SomeClass"));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/DUnitTestRule.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/DUnitTestRule.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/DUnitTestRule.java
new file mode 100755
index 0000000..94f8d91
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/DUnitTestRule.java
@@ -0,0 +1,628 @@
+package com.gemstone.gemfire.test.dunit;
+
+import static com.gemstone.gemfire.test.dunit.DUnitEnv.getAllDistributedSystemProperties;
+import static com.gemstone.gemfire.test.dunit.Invoke.invokeInEveryVM;
+import static com.gemstone.gemfire.test.dunit.Invoke.invokeInLocator;
+import static org.junit.Assert.assertEquals;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.logging.log4j.Logger;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import com.gemstone.gemfire.admin.internal.AdminDistributedSystemImpl;
+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.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.internal.AvailablePort;
+import com.gemstone.gemfire.internal.InternalDataSerializer;
+import com.gemstone.gemfire.internal.InternalInstantiator;
+import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.admin.ClientStatsManager;
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.internal.cache.InitialImageOperation;
+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;
+import com.gemstone.gemfire.internal.cache.tier.sockets.DataSerializerPropogationDUnitTest;
+import com.gemstone.gemfire.internal.logging.InternalLogWriter;
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.internal.logging.log4j.LogWriterLogger;
+import com.gemstone.gemfire.management.internal.cli.LogWrapper;
+import com.gemstone.gemfire.test.dunit.standalone.DUnitLauncher;
+import com.gemstone.org.jgroups.stack.IpAddress;
+import com.gemstone.org.jgroups.stack.Protocol;
+import com.gemstone.org.jgroups.util.GemFireTracer;
+
+@SuppressWarnings("serial")
+public class DUnitTestRule implements TestRule, Serializable {
+
+ private static volatile String testClassName;
+ private static volatile String testMethodName;
+
+ private volatile String className;
+ private volatile String methodName;
+
+ private final DUnitTestCase distTestCase;
+
+ protected DUnitTestRule(Builder builder) {
+ this.distTestCase = new DUnitTestCase();
+ }
+
+ public DUnitTestRule() {
+ this.distTestCase = new DUnitTestCase();
+ }
+
+ @Override
+ public Statement apply(final Statement base, final Description description) {
+ starting(description);
+ return statement(base);
+ }
+
+ /**
+ * Invoked when a test is about to start
+ */
+ protected void starting(Description description) {
+ this.className = description.getClassName();
+ this.methodName = description.getMethodName();
+
+ testClassName = this.className;
+ testMethodName = this.methodName;
+ }
+
+ protected void before() throws Throwable {
+ DUnitLauncher.launchIfNeeded();
+
+ this.distTestCase.setUpDistributedTestCase();
+ }
+
+ protected void after() throws Throwable {
+ try {
+ this.distTestCase.tearDownDistributedTestCase();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public String getClassName() {
+ return this.className;
+ }
+
+ public String getMethodName() {
+ return this.methodName;
+ }
+
+ public final String getUniqueName() {
+ return testClassName + "_" + testMethodName;
+ }
+
+ public static String getTestClassName() {
+ return testClassName;
+ }
+
+ public static String getTestMethodName() {
+ return testMethodName;
+ }
+
+ private Statement statement(final Statement base) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ before();
+ try {
+ base.evaluate();
+ } finally {
+ after();
+ }
+ }
+ };
+ }
+
+ public static class Builder {
+ protected Builder() {}
+
+ public Builder vmCount(final int vmCount) {
+ return this;
+ }
+
+ public Builder logPerTest(final boolean logPerTest) {
+ return this;
+ }
+
+ public Builder logPerTestClass(final boolean logPerTestClass) {
+ return this;
+ }
+
+ public DUnitTestRule build() {
+ return new DUnitTestRule(this);
+ }
+ }
+
+ public static class DUnitTestCase implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static final Logger logger = LogService.getLogger();
+ private static final LogWriterLogger oldLogger = LogWriterLogger.create(logger);
+
+ private static InternalDistributedSystem system;
+ protected static String previousSystemCreatedInTestClass;
+ protected static Properties previousProperties;
+
+ protected volatile boolean logPerTest = Boolean.getBoolean("dunitLogPerTest");
+
+ /**
+ * Creates a new <code>DistributedTestCase</code> test.
+ */
+ public DUnitTestCase() {
+ DUnitLauncher.launchIfNeeded();
+ }
+
+ //---------------------------------------------------------------------------
+ // setUp methods
+ //---------------------------------------------------------------------------
+
+ public final void setUpDistributedTestCase() throws Exception {
+ setUpCreationStackGenerator();
+
+ System.setProperty(HoplogConfig.ALLOW_LOCAL_HDFS_PROP, "true");
+ GemFireCacheImpl.setDefaultDiskStoreName(getDefaultDiskStoreName()); // TODO: not thread safe
+
+ for (int h = 0; h < Host.getHostCount(); h++) {
+ Host host = Host.getHost(h);
+ for (int v = 0; v < host.getVMCount(); v++) {
+ VM vm = host.getVM(v);
+ final String vmDefaultDiskStoreName = "DiskStore-" + h + "-" + v + "-" + testClassName + "." + testMethodName;
+ setUpInVM(vm, testClassName, testMethodName, vmDefaultDiskStoreName);
+ }
+ }
+ //System.out.println("\n\n[setup] START TEST " + getClass().getSimpleName()+"."+testName+"\n\n");
+ }
+
+ private static void setUpInVM(final VM vm, final String testClassNameToUse, final String testMethodNameToUse, final String diskStoreNameToUse) {
+ vm.invoke(new SerializableRunnable() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void run() {
+ setUpCreationStackGenerator();
+ testClassName = testClassNameToUse;
+ testMethodName = testMethodNameToUse;
+ System.setProperty(HoplogConfig.ALLOW_LOCAL_HDFS_PROP, "true");
+ GemFireCacheImpl.setDefaultDiskStoreName(diskStoreNameToUse); // TODO: not thread safe
+ }
+ });
+ }
+
+ //---------------------------------------------------------------------------
+ // tearDown methods
+ //---------------------------------------------------------------------------
+
+ /**
+ * For logPerTest to work, we have to disconnect from the DS, but all
+ * subclasses do not call super.tearDown(). To prevent this scenario
+ * this method has been declared final. Subclasses must now override
+ * {@link #tearDownBefore()} instead.
+ * @throws Exception
+ */
+ public final void tearDownDistributedTestCase() throws Exception {
+ tearDownBefore();
+ realTearDown();
+ tearDownAfter();
+
+ tearDownCreationStackGenerator();
+
+ tearDownInEveryVM();
+ }
+
+ private static void tearDownInEveryVM() {
+ invokeInEveryVM(new SerializableRunnable() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void run() {
+ tearDownCreationStackGenerator();
+ testClassName = null;
+ testMethodName = null;
+ }
+ });
+ }
+
+ protected void realTearDown() throws Exception {
+ if (logPerTest) {
+ disconnectFromDS();
+ invokeInEveryVM(DistributedTestCase.class, "disconnectFromDS");
+ }
+ cleanupAllVms();
+ }
+
+ /**
+ * Tears down the test. This method is called by the final {@link #tearDown()} method and should be overridden to
+ * perform actual test cleanup and release resources used by the test. The tasks executed by this method are
+ * performed before the DUnit test framework using Hydra cleans up the client VMs.
+ * <p/>
+ * @throws Exception if the tear down process and test cleanup fails.
+ * @see #tearDown
+ * @see #tearDownAfter()
+ */
+ protected void tearDownBefore() throws Exception {
+ }
+
+ /**
+ * Tears down the test. Performs additional tear down tasks after the DUnit tests framework using Hydra cleans up
+ * the client VMs. This method is called by the final {@link #tearDown()} method and should be overridden to perform
+ * post tear down activities.
+ * <p/>
+ * @throws Exception if the test tear down process fails.
+ * @see #tearDown()
+ * @see #tearDownBefore()
+ */
+ protected void tearDownAfter() throws Exception {
+ }
+
+ //---------------------------------------------------------------------------
+ // test name methods
+ //---------------------------------------------------------------------------
+
+ /**
+ * 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() { // TODO: consider using FQCN
+ return testClassName + "_" + testMethodName;
+ }
+
+ protected static String getTestName() {
+ return testMethodName;
+ }
+
+ //---------------------------------------------------------------------------
+ // public final methods
+ //---------------------------------------------------------------------------
+
+ /**
+ * 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(Properties properties) {
+ if (system == null) {
+ system = InternalDistributedSystem.getAnyInstance();
+ }
+
+ if (system == null || !system.isConnected()) {
+ // there is no previous system yet
+ final Properties newProperties = getAllDistributedSystemProperties(properties);
+ previousSystemCreatedInTestClass = getTestClassName();
+ if (logPerTest) {
+ newProperties.put(DistributionConfig.LOG_FILE_NAME, getUniqueName() + ".log");
+ newProperties.put(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME, getUniqueName() + ".gfs");
+ }
+ system = (InternalDistributedSystem)DistributedSystem.connect(newProperties);
+ previousProperties = newProperties;
+
+ } else {
+ // there is a previous system
+ boolean needNewSystem = false;
+ //if (!getUniqueName().equals(previousTestName)) {
+ if (!getTestClassName().equals(previousSystemCreatedInTestClass)) {
+ // previous system was created in a previous test class
+ final Properties newProperties = getAllDistributedSystemProperties(properties);
+ needNewSystem = !newProperties.equals(previousProperties);
+ if (needNewSystem) {
+ logger.info(
+ "Test class has changed and the new DS properties are not an exact match. "
+ + "Forcing DS disconnect. Old props = "
+ + previousProperties + "new props=" + newProperties);
+ }
+
+ } else {
+ // previous system was created in this test class
+ final Properties currentProperties = system.getProperties();
+ for (Iterator iter = properties.entrySet().iterator(); iter.hasNext(); ) {
+ final Map.Entry entry = (Map.Entry) iter.next();
+ final String key = (String) entry.getKey();
+ final String value = (String) entry.getValue();
+ if (!value.equals(currentProperties.getProperty(key))) {
+ needNewSystem = true;
+ logger.info("Forcing DS disconnect. For property " + key
+ + " old value = " + currentProperties.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.
+ logger.info("Disconnecting from current DS in order to make a new one");
+ disconnectFromDS();
+ getSystem(properties);
+ }
+ }
+ 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(this.getDistributedSystemProperties());
+ }
+
+ /**
+ * Returns a loner distributed system that isn't connected to other
+ * vms
+ *
+ * @since 6.5
+ */
+ public final InternalDistributedSystem getLonerSystem() {
+ Properties props = this.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 = this.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 an mcast distributed system that is connected to other
+ * vms using a random mcast port.
+ */
+ public final InternalDistributedSystem getMcastSystem() {
+ Properties props = this.getDistributedSystemProperties();
+ int port = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS);
+ props.put(DistributionConfig.MCAST_PORT_NAME, ""+port);
+ props.put(DistributionConfig.MCAST_TTL_NAME, "0");
+ props.put(DistributionConfig.LOCATORS_NAME, "");
+ return getSystem(props);
+ }
+
+ /**
+ * Returns an mcast distributed system that is connected to other
+ * vms using the given mcast port.
+ */
+ public final InternalDistributedSystem getMcastSystem(int jgroupsPort) {
+ Properties props = this.getDistributedSystemProperties();
+ props.put(DistributionConfig.MCAST_PORT_NAME, ""+jgroupsPort);
+ props.put(DistributionConfig.MCAST_TTL_NAME, "0");
+ props.put(DistributionConfig.LOCATORS_NAME, "");
+ return getSystem(props);
+ }
+
+ /**
+ * Returns whether or this VM is connected to a {@link
+ * DistributedSystem}.
+ */
+ public final boolean isConnectedToDS() {
+ return system != null && system.isConnected();
+ }
+
+ //---------------------------------------------------------------------------
+ // public methods
+ //---------------------------------------------------------------------------
+
+ /**
+ * 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() {
+ return new Properties();
+ }
+
+ //---------------------------------------------------------------------------
+ // private
+ //---------------------------------------------------------------------------
+
+ private String getDefaultDiskStoreName() { // TODO: move
+ String vmid = System.getProperty("vmid");
+ return "DiskStore-" + vmid + "-"+ testClassName + "." + getTestName();
+ }
+
+ //---------------------------------------------------------------------------
+ // deprecated static methods
+ //---------------------------------------------------------------------------
+
+ /**
+ * Returns a <code>LogWriter</code> for logging information
+ * @deprecated Use a static logger from the log4j2 LogService.getLogger instead.
+ */
+ @Deprecated
+ public static InternalLogWriter getLogWriter() { // TODO: delete
+ return oldLogger;
+ }
+
+ //---------------------------------------------------------------------------
+ // private static methods
+ //---------------------------------------------------------------------------
+
+ 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());
+ }
+ });
+ }
+
+ private static void tearDownCreationStackGenerator() {
+ InternalDistributedSystem.TEST_CREATION_STACK_GENERATOR.set(InternalDistributedSystem.DEFAULT_CREATION_STACK_GENERATOR);
+ }
+
+ //---------------------------------------------------------------------------
+ // tearDown methods
+ //---------------------------------------------------------------------------
+
+ public static void cleanupAllVms() {
+ cleanupThisVM();
+ invokeInEveryVM(DistributedTestCase.class, "cleanupThisVM");
+ invokeInLocator(new SerializableRunnable() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void run() {
+ DistributionMessageObserver.setInstance(null);
+ unregisterInstantiatorsInThisVM();
+ }
+ });
+ DUnitLauncher.closeAndCheckForSuspects();
+ }
+
+ public static void unregisterAllDataSerializersFromAllVms() {
+ unregisterDataSerializerInThisVM();
+ invokeInEveryVM(new SerializableRunnable() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void run() {
+ unregisterDataSerializerInThisVM();
+ }
+ });
+ invokeInLocator(new SerializableRunnable() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void run() {
+ unregisterDataSerializerInThisVM();
+ }
+ });
+ }
+
+ public static void unregisterInstantiatorsInThisVM() {
+ // unregister all the instantiators
+ InternalInstantiator.reinitialize();
+ assertEquals(0, InternalInstantiator.getInstantiators().length);
+ }
+
+ public static void unregisterDataSerializerInThisVM() {
+ DataSerializerPropogationDUnitTest.successfullyLoadedTestDataSerializer = false;
+ // unregister all the Dataserializers
+ InternalDataSerializer.reinitialize();
+ // ensure that all are unregistered
+ assertEquals(0, InternalDataSerializer.getSerializers().length);
+ }
+
+ protected static void disconnectAllFromDS() {
+ disconnectFromDS();
+ invokeInEveryVM(DistributedTestCase.class, "disconnectFromDS");
+ }
+
+ /**
+ * Disconnects this VM from the distributed system
+ */
+ public static void disconnectFromDS() {
+ 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();
+ }
+ }
+
+ private static void cleanupThisVM() {
+ IpAddress.resolve_dns = true;
+ SocketCreator.resolve_dns = true;
+ InitialImageOperation.slowImageProcessing = 0;
+ DistributionMessageObserver.setInstance(null);
+ QueryTestUtils.setCache(null);
+ CacheServerTestUtil.clearCacheReference();
+ RegionTestCase.preSnapshotRegion = null;
+ GlobalLockingDUnitTest.region_testBug32356 = null;
+ LogWrapper.close();
+ ClientProxyMembershipID.system = null;
+ MultiVMRegionTestCase.CCRegion = null;
+ InternalBridgeMembership.unregisterAllListeners();
+ ClientStatsManager.cleanupForTests();
+ unregisterInstantiatorsInThisVM();
+ GemFireTracer.DEBUG = Boolean.getBoolean("DistributionManager.DEBUG_JAVAGROUPS");
+ Protocol.trace = GemFireTracer.DEBUG;
+ DistributionMessageObserver.setInstance(null);
+ QueryObserverHolder.reset();
+ if (InternalDistributedSystem.systemAttemptingReconnect != null) {
+ InternalDistributedSystem.systemAttemptingReconnect.stopReconnecting();
+ }
+ ExpectedExceptionString ex;
+ while((ex = ExpectedExceptionString.poll()) != null) {
+ ex.remove();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/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 abb0a95..2557368 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
@@ -64,10 +64,10 @@ public abstract class DistributedTestCase implements java.io.Serializable {
private static volatile String testName;
private static InternalDistributedSystem system;
- private static Class previousSystemCreatedInTestClass;
- private static Properties previousProperties;
+ protected static Class previousSystemCreatedInTestClass;
+ protected static Properties previousProperties;
- private final boolean logPerTest = Boolean.getBoolean("dunitLogPerTest");
+ protected volatile boolean logPerTest = Boolean.getBoolean("dunitLogPerTest");
/**
* Creates a new <code>DistributedTestCase</code> test.
@@ -99,7 +99,7 @@ public abstract class DistributedTestCase implements java.io.Serializable {
//System.out.println("\n\n[setup] START TEST " + getClass().getSimpleName()+"."+testName+"\n\n");
}
- private void setUpInVM(final VM vm, final String testNameToUse, final String diskStoreNameToUse) {
+ private static void setUpInVM(final VM vm, final String testNameToUse, final String diskStoreNameToUse) {
vm.invoke(new SerializableRunnable() {
private static final long serialVersionUID = 1L;
@@ -137,7 +137,7 @@ public abstract class DistributedTestCase implements java.io.Serializable {
tearDownInEveryVM();
}
- private void tearDownInEveryVM() {
+ private static void tearDownInEveryVM() {
invokeInEveryVM(new SerializableRunnable() {
private static final long serialVersionUID = 1L;
@@ -240,10 +240,6 @@ public abstract class DistributedTestCase implements java.io.Serializable {
if (!getTestClass().equals(previousSystemCreatedInTestClass)) {
// previous system was created in a previous test class
final Properties newProperties = getAllDistributedSystemProperties(properties);
- if (logPerTest) {
- newProperties.put(DistributionConfig.LOG_FILE_NAME, getUniqueName() + ".log");
- newProperties.put(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME, getUniqueName() + ".gfs");
- }
needNewSystem = !newProperties.equals(previousProperties);
if (needNewSystem) {
logger.info(
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ChildVM.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ChildVM.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ChildVM.java
index 297016e..36849dd 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ChildVM.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/ChildVM.java
@@ -7,9 +7,6 @@
*/
package com.gemstone.gemfire.test.dunit.standalone;
-import hydra.HydraRuntimeException;
-import hydra.Log;
-
import java.rmi.Naming;
import org.apache.logging.log4j.Logger;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
index f15fe23..67c1e42 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/BasicDUnitTest.java
@@ -28,8 +28,8 @@ import com.gemstone.gemfire.test.junit.categories.DistributedTest;
* test framework.
*/
@Category(DistributedTest.class)
+@SuppressWarnings("serial")
public class BasicDUnitTest extends DistributedTestCase {
- private static final long serialVersionUID = 1L;
private static final String REMOTE_THROW_EXCEPTION_MESSAGE = "Throwing remoteThrowException";
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/DistributedTestNameDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/DistributedTestNameDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/DistributedTestNameDUnitTest.java
index d6afc02..304257d 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/DistributedTestNameDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/DistributedTestNameDUnitTest.java
@@ -10,7 +10,6 @@ import org.junit.experimental.categories.Category;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
-import com.gemstone.gemfire.internal.lang.reflect.ReflectionUtils;
import com.gemstone.gemfire.test.dunit.DistributedTestCase;
import com.gemstone.gemfire.test.dunit.SerializableRunnable;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;
@@ -22,20 +21,16 @@ import com.gemstone.gemfire.test.junit.categories.DistributedTest;
* @author Kirk Lund
*/
@Category(DistributedTest.class)
+@SuppressWarnings("serial")
public class DistributedTestNameDUnitTest extends DistributedTestCase {
- private static final long serialVersionUID = 1L;
- // TODO: remove transient and fix bug so test FAILs fast
-
@Rule
public transient TestWatcher watchman = new TestWatcher() {
protected void starting(final Description description) {
- testClassName = description.getClassName();
testMethodName = description.getMethodName();
}
};
- private String testClassName;
private String testMethodName;
@Test
@@ -49,7 +44,6 @@ public class DistributedTestNameDUnitTest extends DistributedTestCase {
assertThat(getTestName(), is(methodName));
invokeInEveryVM(new SerializableRunnable(getMethodName()) {
- private static final long serialVersionUID = 1L;
@Override
public void run() {
assertThat(getTestName(), is(methodName));
@@ -59,13 +53,11 @@ public class DistributedTestNameDUnitTest extends DistributedTestCase {
@Test
public void uniqueNameShouldBeConsistentInAllJVMs() throws Exception {
- //final String uniqueName = testClassName + "_" + testMethodName;
final String uniqueName = getClass().getSimpleName() + "_" + testMethodName;
assertThat(getUniqueName(), is(uniqueName));
invokeInEveryVM(new SerializableRunnable(getMethodName()) {
- private static final long serialVersionUID = 1L;
@Override
public void run() {
assertThat(getUniqueName(), is(uniqueName));
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/DistributedTestNameWithRuleDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/DistributedTestNameWithRuleDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/DistributedTestNameWithRuleDUnitTest.java
new file mode 100755
index 0000000..a0a2b2e
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/DistributedTestNameWithRuleDUnitTest.java
@@ -0,0 +1,66 @@
+package com.gemstone.gemfire.test.dunit.tests;
+
+import static com.gemstone.gemfire.test.dunit.Invoke.invokeInEveryVM;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.io.Serializable;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+import com.gemstone.gemfire.test.dunit.DUnitTestRule;
+import com.gemstone.gemfire.test.dunit.SerializableRunnable;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+@Category(DistributedTest.class)
+@SuppressWarnings("serial")
+public class DistributedTestNameWithRuleDUnitTest implements Serializable {
+
+ @Rule
+ public final DUnitTestRule dunitTestRule = new DUnitTestRule();
+
+ @Rule
+ public transient TestWatcher watchman = new TestWatcher() {
+ protected void starting(final Description description) {
+ testMethodName = description.getMethodName();
+ }
+ };
+
+ private transient String testMethodName;
+
+ @Test
+ public void testNameShouldBeConsistentInAllJVMs() throws Exception {
+ final String methodName = this.testMethodName;
+
+ // JUnit Rule provides getMethodName in Controller JVM
+ assertThat(this.dunitTestRule.getMethodName(), is(methodName));
+
+ // Controller JVM sets testName = getMethodName in itself and all 4 other JVMs
+ assertThat(DUnitTestRule.getTestMethodName(), is(methodName));
+
+ invokeInEveryVM(new SerializableRunnable(this.dunitTestRule.getMethodName()) {
+ @Override
+ public void run() {
+ assertThat(DUnitTestRule.getTestMethodName(), is(methodName));
+ }
+ });
+ }
+
+ @Test
+ public void uniqueNameShouldBeConsistentInAllJVMs() throws Exception {
+ final String uniqueName = getClass().getName() + "_" + testMethodName;
+
+ assertThat(this.dunitTestRule.getUniqueName(), is(uniqueName));
+
+ invokeInEveryVM(new SerializableRunnable(this.dunitTestRule.getMethodName()) {
+ @Override
+ public void run() {
+ assertThat(dunitTestRule.getUniqueName(), is(uniqueName));
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestOneDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestOneDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestOneDUnitTest.java
new file mode 100755
index 0000000..80a2e9d
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestOneDUnitTest.java
@@ -0,0 +1,39 @@
+package com.gemstone.gemfire.test.dunit.tests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
+import com.gemstone.gemfire.test.dunit.DistributedTestCase;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+@Category(DistributedTest.class)
+@SuppressWarnings("serial")
+public class LogPerTestOneDUnitTest extends DistributedTestCase {
+
+ @Before
+ public void before() {
+ super.logPerTest = true;
+ }
+
+ @After
+ public void after() {
+ super.logPerTest = false;
+ }
+
+ @Test
+ public void logPerTestShouldUseUniqueName() {
+ InternalDistributedSystem mySystem = getSystem();
+ assertThat(mySystem).isNotNull();
+
+ assertThat(previousSystemCreatedInTestClass).isEqualTo(getClass());
+
+ assertThat(previousProperties).containsEntry(DistributionConfig.LOG_FILE_NAME, getUniqueName() + ".log");
+ assertThat(previousProperties).containsEntry(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME, getUniqueName() + ".gfs");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestSuite.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestSuite.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestSuite.java
new file mode 100755
index 0000000..317b348
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestSuite.java
@@ -0,0 +1,12 @@
+package com.gemstone.gemfire.test.dunit.tests;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ LogPerTestOneDUnitTest.class,
+ LogPerTestTwoDUnitTest.class,
+})
+public class LogPerTestSuite {
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestTwoDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestTwoDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestTwoDUnitTest.java
new file mode 100755
index 0000000..28621ad
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/LogPerTestTwoDUnitTest.java
@@ -0,0 +1,39 @@
+package com.gemstone.gemfire.test.dunit.tests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
+import com.gemstone.gemfire.test.dunit.DistributedTestCase;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+
+@Category(DistributedTest.class)
+@SuppressWarnings("serial")
+public class LogPerTestTwoDUnitTest extends DistributedTestCase {
+
+ @Before
+ public void before() {
+ super.logPerTest = true;
+ }
+
+ @After
+ public void after() {
+ super.logPerTest = false;
+ }
+
+ @Test
+ public void logPerTestShouldUseUniqueName() {
+ InternalDistributedSystem mySystem = getSystem();
+ assertThat(mySystem).isNotNull();
+
+ assertThat(previousSystemCreatedInTestClass).isEqualTo(getClass());
+
+ assertThat(previousProperties).containsEntry(DistributionConfig.LOG_FILE_NAME, getUniqueName() + ".log");
+ assertThat(previousProperties).containsEntry(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME, getUniqueName() + ".gfs");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/MyTestSuite.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/MyTestSuite.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/MyTestSuite.java
index ec90a36..9d9b2a4 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/MyTestSuite.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/MyTestSuite.java
@@ -12,7 +12,12 @@ import com.gemstone.gemfire.test.catchexception.CatchExceptionExampleDUnitTest;
@Suite.SuiteClasses({
BasicDUnitTest.class,
DistributedTestNameDUnitTest.class,
+ DistributedTestNameWithRuleDUnitTest.class,
+ SerializableTemporaryFolderDUnitTest.class,
+ SerializableTestNameDUnitTest.class,
+ SerializableTestWatcherDUnitTest.class,
VMDUnitTest.class,
+ VMMoreDUnitTest.class,
CatchExceptionExampleDUnitTest.class,
DistributedMemberDUnitTest.class,
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTemporaryFolderDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTemporaryFolderDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTemporaryFolderDUnitTest.java
new file mode 100755
index 0000000..0fe0e3c
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTemporaryFolderDUnitTest.java
@@ -0,0 +1,49 @@
+package com.gemstone.gemfire.test.dunit.tests;
+
+import static com.gemstone.gemfire.test.dunit.Invoke.invokeInEveryVM;
+import static org.assertj.core.api.Assertions.*;
+
+import java.io.File;
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.internal.lang.reflect.ReflectionUtils;
+import com.gemstone.gemfire.test.dunit.DUnitTestRule;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.SerializableRunnable;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import com.gemstone.gemfire.test.junit.rules.SerializableTemporaryFolder;
+
+@Category(DistributedTest.class)
+@SuppressWarnings("serial")
+public class SerializableTemporaryFolderDUnitTest implements Serializable {
+
+ @Rule
+ public final DUnitTestRule dunitTestRule = new DUnitTestRule();
+
+ @Rule
+ public final SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
+
+ @Before
+ public void preconditions() {
+ assertThat(Host.getHostCount()).isEqualTo(1);
+ assertThat(Host.getHost(0).getVMCount()).isEqualTo(4);
+ }
+
+ @Test
+ public void temporaryFolderShouldBeSerializable() throws Exception {
+ final File root = this.temporaryFolder.getRoot();
+
+ invokeInEveryVM(new SerializableRunnable(ReflectionUtils.getMethodName()) {
+ @Override
+ public void run() {
+ assertThat(temporaryFolder.getRoot()).exists();
+ assertThat(temporaryFolder.getRoot()).isEqualTo(root);
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTestNameDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTestNameDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTestNameDUnitTest.java
new file mode 100755
index 0000000..19c00c3
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTestNameDUnitTest.java
@@ -0,0 +1,49 @@
+package com.gemstone.gemfire.test.dunit.tests;
+
+import static com.gemstone.gemfire.test.dunit.Invoke.invokeInEveryVM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.internal.lang.reflect.ReflectionUtils;
+import com.gemstone.gemfire.test.dunit.DUnitTestRule;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.SerializableRunnable;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import com.gemstone.gemfire.test.junit.rules.SerializableTestName;
+
+@Category(DistributedTest.class)
+@SuppressWarnings("serial")
+public class SerializableTestNameDUnitTest implements Serializable {
+
+ @Rule
+ public final DUnitTestRule dunitTestRule = new DUnitTestRule();
+
+ @Rule
+ public final SerializableTestName testName = new SerializableTestName();
+
+ @Before
+ public void preconditions() {
+ assertThat(Host.getHostCount()).isEqualTo(1);
+ assertThat(Host.getHost(0).getVMCount()).isEqualTo(4);
+ }
+
+ @Test
+ public void testNameShouldBeSerializable() {
+ final String methodName = ReflectionUtils.getMethodName();
+
+ assertThat(this.testName.getMethodName()).isEqualTo(methodName);
+
+ invokeInEveryVM(new SerializableRunnable(methodName) {
+ @Override
+ public void run() {
+ assertThat(testName.getMethodName()).isEqualTo(methodName);
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTestWatcherDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTestWatcherDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTestWatcherDUnitTest.java
new file mode 100755
index 0000000..c574aaf
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/SerializableTestWatcherDUnitTest.java
@@ -0,0 +1,67 @@
+package com.gemstone.gemfire.test.dunit.tests;
+
+import static com.gemstone.gemfire.test.dunit.Invoke.invokeInEveryVM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.Description;
+
+import com.gemstone.gemfire.internal.lang.reflect.ReflectionUtils;
+import com.gemstone.gemfire.test.dunit.DUnitTestRule;
+import com.gemstone.gemfire.test.dunit.Host;
+import com.gemstone.gemfire.test.dunit.SerializableRunnable;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import com.gemstone.gemfire.test.junit.rules.SerializableTestWatcher;
+
+@Category(DistributedTest.class)
+@SuppressWarnings("serial")
+public class SerializableTestWatcherDUnitTest implements Serializable {
+
+ @Rule
+ public final DUnitTestRule dunitTestRule = new DUnitTestRule();
+
+ @Rule
+ public final SerializableTestWatcher watchman = new SerializableTestWatcher() {
+ @Override
+ protected void starting(final Description description) {
+ testClassName = description.getClassName();
+ testMethodName = description.getMethodName();
+ }
+ };
+
+ private String testClassName;
+ private String testMethodName;
+
+ @Before
+ public void preconditions() {
+ assertThat(Host.getHostCount()).isEqualTo(1);
+ assertThat(Host.getHost(0).getVMCount()).isEqualTo(4);
+ }
+
+ @Test
+ public void testWatcherShouldBeSerializable() {
+ final String methodName = ReflectionUtils.getMethodName();
+ final String className = getClass().getName();
+
+ invokeInEveryVM(new SerializableRunnable(this.testMethodName) {
+ @Override
+ public void run() {
+ assertThat(getTestMethodName()).isEqualTo(methodName);
+ assertThat(getTestClassName()).isEqualTo(className);
+ }
+ });
+ }
+
+ private String getTestMethodName() {
+ return this.testMethodName;
+ }
+
+ private String getTestClassName() {
+ return this.testClassName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java
index 904da4f..a6784b8 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMDUnitTest.java
@@ -28,8 +28,8 @@ import com.gemstone.gemfire.test.junit.categories.DistributedTest;
* This class tests the functionality of the {@link VM} class.
*/
@Category(DistributedTest.class)
+@SuppressWarnings("serial")
public class VMDUnitTest extends DistributedTestCase {
- private static final long serialVersionUID = 1L;
private static final boolean BOOLEAN_VALUE = true;
private static final byte BYTE_VALUE = (byte) 40;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMMoreDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMMoreDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMMoreDUnitTest.java
new file mode 100755
index 0000000..6f2a2fa
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/tests/VMMoreDUnitTest.java
@@ -0,0 +1,65 @@
+package com.gemstone.gemfire.test.dunit.tests;
+
+import static org.assertj.core.api.Assertions.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
+import com.gemstone.gemfire.test.dunit.DistributedTestCase;
+import com.gemstone.gemfire.test.dunit.SerializableRunnable;
+import com.gemstone.gemfire.test.junit.categories.DistributedTest;
+import com.gemstone.gemfire.test.junit.rules.SerializableTestName;
+
+@Category(DistributedTest.class)
+@SuppressWarnings("serial")
+public class VMMoreDUnitTest extends DistributedTestCase {
+
+ @Rule
+ public final SerializableTestName testName = new SerializableTestName();
+
+ @Before
+ public void before() {
+ super.logPerTest = true;
+ }
+
+ @After
+ public void after() {
+ super.logPerTest = false;
+ }
+
+ @Test
+ public void foo() {
+ InternalDistributedSystem mySystem = getSystem();
+
+ assertThat(previousSystemCreatedInTestClass).isEqualTo(getClass());
+
+ assertThat(previousProperties).containsEntry(DistributionConfig.LOG_FILE_NAME, getUniqueName() + ".log");
+ assertThat(previousProperties).containsEntry(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME, getUniqueName() + ".gfs");
+ }
+
+ @Test
+ public void bar() {
+ InternalDistributedSystem mySystem = getSystem();
+
+ assertThat(previousSystemCreatedInTestClass).isEqualTo(getClass());
+
+ assertThat(previousProperties).containsEntry(DistributionConfig.LOG_FILE_NAME, getUniqueName() + ".log");
+ assertThat(previousProperties).containsEntry(DistributionConfig.STATISTIC_ARCHIVE_FILE_NAME, getUniqueName() + ".gfs");
+ }
+
+ public static class InnerClass {
+ public static SerializableRunnable staticSerializableRunnable() {
+ return new SerializableRunnable() {
+ @Override
+ public void run() {
+ System.out.println("printing from static SerializableRunnable");
+ }
+ };
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTemporaryFolder.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTemporaryFolder.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTemporaryFolder.java
new file mode 100755
index 0000000..8f22629
--- /dev/null
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTemporaryFolder.java
@@ -0,0 +1,49 @@
+package com.gemstone.gemfire.test.junit.rules;
+
+import java.io.File;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Field;
+
+import org.junit.rules.TemporaryFolder;
+
+@SuppressWarnings("serial")
+public class SerializableTemporaryFolder extends TemporaryFolder implements Serializable {
+
+ private void writeObject(final ObjectOutputStream out) throws Exception {
+ writeParentFolder(out);
+ writeFolder(out);
+ }
+
+ private void readObject(final ObjectInputStream in) throws Exception {
+ readParentFolder(in);
+ readFolder(in);
+ }
+
+ private void readParentFolder(final ObjectInputStream in) throws Exception {
+ final Field parentFolderField = TemporaryFolder.class.getDeclaredField("parentFolder");
+ parentFolderField.setAccessible(true);
+ parentFolderField.set(this, (File) in.readObject());
+ }
+
+ private void readFolder(final ObjectInputStream in) throws Exception {
+ final Field folderField = TemporaryFolder.class.getDeclaredField("folder");
+ folderField.setAccessible(true);
+ folderField.set(this, (File) in.readObject());
+ }
+
+ private void writeParentFolder(final ObjectOutputStream out) throws Exception {
+ final Field parentFolderField = TemporaryFolder.class.getDeclaredField("parentFolder");
+ parentFolderField.setAccessible(true);
+ final File parentFolderFieldValue = (File) parentFolderField.get(this);
+ out.writeObject(parentFolderFieldValue);
+ }
+
+ private void writeFolder(final ObjectOutputStream out) throws Exception {
+ final Field folderField = TemporaryFolder.class.getDeclaredField("folder");
+ folderField.setAccessible(true);
+ final File folderFieldValue = (File) folderField.get(this);
+ out.writeObject(folderFieldValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestName.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestName.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestName.java
new file mode 100755
index 0000000..38da244
--- /dev/null
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestName.java
@@ -0,0 +1,33 @@
+package com.gemstone.gemfire.test.junit.rules;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Field;
+
+import org.junit.rules.TestName;
+
+@SuppressWarnings("serial")
+public class SerializableTestName extends TestName implements Serializable {
+
+ private void writeObject(final ObjectOutputStream out) throws Exception {
+ writeName(out);
+ }
+
+ private void readObject(final ObjectInputStream in) throws Exception {
+ readName(in);
+ }
+
+ private void writeName(final ObjectOutputStream out) throws Exception {
+ final Field nameField = TestName.class.getDeclaredField("name");
+ nameField.setAccessible(true);
+ final String nameValue = (String) nameField.get(this);
+ out.writeObject(nameValue);
+ }
+
+ private void readName(final ObjectInputStream in) throws Exception {
+ Field nameField = TestName.class.getDeclaredField("name");
+ nameField.setAccessible(true);
+ nameField.set(this, (String) in.readObject());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java
new file mode 100755
index 0000000..e873b41
--- /dev/null
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java
@@ -0,0 +1,9 @@
+package com.gemstone.gemfire.test.junit.rules;
+
+import java.io.Serializable;
+
+import org.junit.rules.TestWatcher;
+
+@SuppressWarnings("serial")
+public class SerializableTestWatcher extends TestWatcher implements Serializable {
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/921ce90d/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java
new file mode 100755
index 0000000..45bd863
--- /dev/null
+++ b/gemfire-junit/src/test/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java
@@ -0,0 +1,98 @@
+package com.gemstone.gemfire.test.junit.rules;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+import org.junit.rules.Timeout;
+
+@SuppressWarnings("serial")
+public class SerializableTimeout extends Timeout implements Serializable {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public SerializableTimeout(final long timeout, final TimeUnit timeUnit) {
+ super(timeout, timeUnit);
+ }
+
+ protected SerializableTimeout(final Builder builder) {
+ super(builder);
+ }
+
+ public static class Builder extends Timeout.Builder {
+
+ protected Builder() {
+ super();
+ }
+
+ @Override
+ public SerializableTimeout build() {
+ return new SerializableTimeout(this);
+ }
+ }
+
+ private void writeObject(final ObjectOutputStream out) throws Exception {
+ writeTimeout(out);
+ writeTimeUnit(out);
+ writeLookForStuckThread(out);
+ }
+
+ private void readObject(final ObjectInputStream in) throws Exception {
+ readTimeout(in);
+ readTimeUnit(in);
+ readLookForStuckThread(in);
+ }
+
+ private void writeTimeout(final ObjectOutputStream out) throws Exception {
+ final Field timeoutField = TestName.class.getDeclaredField("timeout");
+ timeoutField.setAccessible(true);
+ final Long timeoutValue = (Long) timeoutField.get(this);
+ out.writeLong(timeoutValue);
+ }
+
+ private void writeTimeUnit(final ObjectOutputStream out) throws Exception {
+ final Field timeoutField = TestName.class.getDeclaredField("timeUnit");
+ timeoutField.setAccessible(true);
+ final TimeUnit timeoutValue = (TimeUnit) timeoutField.get(this);
+ out.writeObject(timeoutValue);
+ }
+
+ private void writeLookForStuckThread(final ObjectOutputStream out) throws Exception {
+ try {
+ final Field lookForStuckThreadField = TemporaryFolder.class.getDeclaredField("lookForStuckThread");
+ lookForStuckThreadField.setAccessible(true);
+ final Boolean lookForStuckThreadValue = (Boolean) lookForStuckThreadField.get(this);
+ out.writeBoolean(lookForStuckThreadValue);
+ } catch (NoSuchFieldException e) {
+ out.writeBoolean(false);
+ }
+ }
+
+ private void readTimeout(final ObjectInputStream in) throws Exception {
+ Field timeoutField = TestName.class.getDeclaredField("timeout");
+ timeoutField.setAccessible(true);
+ timeoutField.set(this, (Long) in.readObject());
+ }
+
+ private void readTimeUnit(final ObjectInputStream in) throws Exception {
+ Field timeUnitField = TestName.class.getDeclaredField("timeUnit");
+ timeUnitField.setAccessible(true);
+ timeUnitField.set(this, (TimeUnit) in.readObject());
+ }
+
+ private void readLookForStuckThread(final ObjectInputStream in) throws Exception {
+ try {
+ final Field lookForStuckThreadField = TemporaryFolder.class.getDeclaredField("lookForStuckThread");
+ lookForStuckThreadField.setAccessible(true);
+ lookForStuckThreadField.set(this, (Boolean) in.readObject());
+ } catch (NoSuchFieldException e) {
+ final boolean value = (Boolean) in.readObject();
+ }
+ }
+}