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 2016/02/23 19:07:54 UTC
[3/5] incubator-geode git commit: Initial commit with refactored rules
Initial commit with refactored rules
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/f2487a46
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/f2487a46
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/f2487a46
Branch: refs/heads/feature/GEODE-953
Commit: f2487a46f4e7152ec3f82a39b7bfed99adafc7bc
Parents: 9899940
Author: Kirk Lund <kl...@pivotal.io>
Authored: Fri Feb 19 16:06:52 2016 -0800
Committer: Kirk Lund <kl...@pivotal.io>
Committed: Fri Feb 19 16:07:38 2016 -0800
----------------------------------------------------------------------
.../internal/process/PidFileJUnitTest.java | 4 +-
.../dunit/rules/DistributedDisconnectRule.java | 15 +-
.../rules/DistributedExternalResource.java | 27 +-
.../DistributedRestoreSystemProperties.java | 4 +-
.../dunit/rules/DistributedTestFixtureRule.java | 57 ++++
.../gemfire/test/dunit/rules/RemoteInvoker.java | 7 +-
gemfire-junit/build.gradle | 1 +
.../com/gemstone/gemfire/test/junit/Retry.java | 4 +-
.../test/junit/rules/ExpectedTimeout.java | 180 -----------
.../gemfire/test/junit/rules/RuleList.java | 92 ++++++
.../rules/SerializableExternalResource.java | 107 -------
.../test/junit/rules/SerializableRuleChain.java | 119 --------
.../rules/SerializableTemporaryFolder.java | 70 -----
.../test/junit/rules/SerializableTestName.java | 54 ----
.../test/junit/rules/SerializableTestRule.java | 33 --
.../junit/rules/SerializableTestWatcher.java | 29 --
.../test/junit/rules/SerializableTimeout.java | 119 --------
.../test/junit/rules/TestFixtureRule.java | 151 +++++++++
.../serializable/FieldSerializationUtils.java | 48 +++
.../serializable/FieldsOfTemporaryFolder.java | 26 ++
.../rules/serializable/FieldsOfTestName.java | 24 ++
.../rules/serializable/FieldsOfTimeout.java | 26 ++
.../SerializableExternalResource.java | 25 ++
.../serializable/SerializableRuleList.java | 78 +++++
.../SerializableTemporaryFolder.java | 71 +++++
.../SerializableTestFixtureRule.java | 25 ++
.../serializable/SerializableTestName.java | 65 ++++
.../serializable/SerializableTestRule.java | 31 ++
.../serializable/SerializableTestWatcher.java | 26 ++
.../rules/serializable/SerializableTimeout.java | 108 +++++++
.../junit/rules/ExpectedTimeoutJUnitTest.java | 204 -------------
.../junit/rules/ExpectedTimeoutRuleTest.java | 212 +++++++++++++
.../test/junit/rules/IgnoreUntilRuleTest.java | 119 ++++++++
.../test/junit/rules/RepeatRuleTest.java | 302 ++++++++++++++++++
.../rules/RetryRuleGlobalWithErrorTest.java | 249 +++++++++++++++
.../rules/RetryRuleGlobalWithExceptionTest.java | 253 +++++++++++++++
.../rules/RetryRuleLocalWithErrorTest.java | 206 +++++++++++++
.../rules/RetryRuleLocalWithExceptionTest.java | 214 +++++++++++++
.../gemfire/test/junit/rules/TestRunner.java | 37 +++
.../rules/examples/RetryRuleExampleTest.java | 8 +-
.../rules/examples/RuleAndClassRuleTest.java | 140 +++++++++
.../SerializableExternalResourceTest.java | 81 +++++
.../serializable/SerializableRuleListTest.java | 90 ++++++
.../SerializableTemporaryFolderTest.java | 92 ++++++
.../SerializableTestFixtureRuleTest.java | 70 +++++
.../serializable/SerializableTestNameTest.java | 83 +++++
.../SerializableTestWatcherTest.java | 81 +++++
.../serializable/SerializableTimeoutTest.java | 104 +++++++
.../rules/tests/ExpectedTimeoutRuleTest.java | 214 -------------
.../junit/rules/tests/IgnoreUntilRuleTest.java | 121 --------
.../junit/rules/tests/JUnitRuleTestSuite.java | 33 --
.../test/junit/rules/tests/RepeatRuleTest.java | 304 -------------------
.../tests/RetryRuleGlobalWithErrorTest.java | 250 ---------------
.../tests/RetryRuleGlobalWithExceptionTest.java | 254 ----------------
.../tests/RetryRuleLocalWithErrorTest.java | 207 -------------
.../tests/RetryRuleLocalWithExceptionTest.java | 213 -------------
.../junit/rules/tests/RuleAndClassRuleTest.java | 138 ---------
.../test/junit/rules/tests/TestRunner.java | 37 ---
58 files changed, 3216 insertions(+), 2726 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-core/src/test/java/com/gemstone/gemfire/internal/process/PidFileJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/process/PidFileJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/process/PidFileJUnitTest.java
index 5f81c2b..2906b0e 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/process/PidFileJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/process/PidFileJUnitTest.java
@@ -42,7 +42,7 @@ import org.junit.rules.TemporaryFolder;
import com.gemstone.gemfire.internal.util.StopWatch;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import com.gemstone.gemfire.test.junit.rules.ExpectedTimeout;
+import com.gemstone.gemfire.test.junit.rules.ExpectedTimeoutRule;
/**
* Unit tests the PidFile class.
@@ -60,7 +60,7 @@ public class PidFileJUnitTest {
public ExpectedException thrown = ExpectedException.none();
@Rule
- public ExpectedTimeout timeout = ExpectedTimeout.none();
+ public ExpectedTimeoutRule timeout = ExpectedTimeoutRule.none();
protected Mockery mockContext;
private ExecutorService futures;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedDisconnectRule.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedDisconnectRule.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedDisconnectRule.java
index 125fc06..f7a5179 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedDisconnectRule.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedDisconnectRule.java
@@ -16,12 +16,15 @@
*/
package com.gemstone.gemfire.test.dunit.rules;
-// TODO: import static com.gemstone.gemfire.test.dunit.DistributedTestRule.*;
+// TODO:uncomment: import static com.gemstone.gemfire.test.dunit.DistributedTestRule.*;
import com.gemstone.gemfire.test.dunit.SerializableRunnable;
+/**
+ * Disconnects all remote DUnit JVMs including the Locator JVM.
+ */
@SuppressWarnings("serial")
-public class DistributedDisconnectRule extends DistributedExternalResource {
+public class DistributedDisconnectRule extends DistributedTestFixtureRule {
private final boolean disconnectBefore;
private final boolean disconnectAfter;
@@ -52,7 +55,7 @@ public class DistributedDisconnectRule extends DistributedExternalResource {
}
@Override
- protected void after() throws Throwable {
+ protected void after() {
if (this.disconnectAfter) {
invoker().invokeEverywhere(serializableRunnable());
}
@@ -66,7 +69,7 @@ public class DistributedDisconnectRule extends DistributedExternalResource {
}
@Override
- protected void afterClass() throws Throwable {
+ protected void afterClass() {
if (this.disconnectAfterClass) {
invoker().invokeEverywhere(serializableRunnable());
}
@@ -76,15 +79,13 @@ public class DistributedDisconnectRule extends DistributedExternalResource {
return new SerializableRunnable() {
@Override
public void run() {
- // TODO: disconnectFromDS();
+ // TODO:uncomment: disconnectFromDS();
}
};
}
/**
* Builds an instance of DistributedDisconnectRule
- *
- * @author Kirk Lund
*/
public static class Builder {
private boolean disconnectBeforeClass;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedExternalResource.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedExternalResource.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedExternalResource.java
index d3b7319..a7c3598 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedExternalResource.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedExternalResource.java
@@ -16,9 +16,12 @@
*/
package com.gemstone.gemfire.test.dunit.rules;
-import com.gemstone.gemfire.test.junit.rules.SerializableExternalResource;
+import com.gemstone.gemfire.test.junit.rules.serializable.SerializableExternalResource;
-@SuppressWarnings("serial")
+/**
+ * Distributed version of SerializableExternalResource which affects all remote
+ * DUnit JVMs including the Locator JVM.
+ */
public class DistributedExternalResource extends SerializableExternalResource {
private final RemoteInvoker invoker;
@@ -35,24 +38,4 @@ public class DistributedExternalResource extends SerializableExternalResource {
protected RemoteInvoker invoker() {
return this.invoker;
}
-
- @Override
- protected void before() throws Throwable {
- // do nothing
- }
-
- @Override
- protected void after() throws Throwable {
- // do nothing
- }
-
- @Override
- protected void beforeClass() throws Throwable {
- // do nothing
- }
-
- @Override
- protected void afterClass() throws Throwable {
- // do nothing
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java
index 1711b21..061cb42 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedRestoreSystemProperties.java
@@ -24,13 +24,11 @@ import java.util.Properties;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import com.gemstone.gemfire.test.dunit.SerializableRunnable;
-import com.gemstone.gemfire.test.junit.rules.SerializableTestRule;
+import com.gemstone.gemfire.test.junit.rules.serializable.SerializableTestRule;
/**
* Distributed version of RestoreSystemProperties which affects all DUnit
* JVMs including the Locator JVM.
- *
- * @author Kirk Lund
*/
@SuppressWarnings("serial")
public class DistributedRestoreSystemProperties extends RestoreSystemProperties implements SerializableTestRule {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedTestFixtureRule.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedTestFixtureRule.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedTestFixtureRule.java
new file mode 100755
index 0000000..86e93f3
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/DistributedTestFixtureRule.java
@@ -0,0 +1,57 @@
+/*
+ * 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.rules;
+
+import com.gemstone.gemfire.test.junit.rules.serializable.SerializableTestFixtureRule;
+
+/**
+ * Distributed version of SerializableTestFixtureRule which affects all
+ * DUnit JVMs including the Locator JVM. TODO: make which JVMs configurable
+ */
+public class DistributedTestFixtureRule extends SerializableTestFixtureRule {
+
+ private final RemoteInvoker invoker;
+
+ public DistributedTestFixtureRule() {
+ this(new RemoteInvoker());
+ }
+
+ public DistributedTestFixtureRule(final RemoteInvoker invoker) {
+ super();
+ this.invoker = invoker;
+ }
+
+ protected RemoteInvoker invoker() {
+ return this.invoker;
+ }
+
+ @Override
+ protected void before() throws Throwable {
+ }
+
+ @Override
+ protected void after() {
+ }
+
+ @Override
+ protected void beforeClass() throws Throwable {
+ }
+
+ @Override
+ protected void afterClass() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
index 9e3c5b2..278250b 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/rules/RemoteInvoker.java
@@ -23,8 +23,13 @@ import java.io.Serializable;
import com.gemstone.gemfire.test.dunit.SerializableRunnable;
+/**
+ * Provides remote invocation support to a <code>TestRule</code>. These
+ * methods will invoke a SerializableRunnable in all remote DUnit JVMs
+ * including the Locator JVM.
+ */
@SuppressWarnings("serial")
-public class RemoteInvoker implements Serializable {
+class RemoteInvoker implements Serializable {
public void invokeEverywhere(final SerializableRunnable runnable) {
try {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/build.gradle
----------------------------------------------------------------------
diff --git a/gemfire-junit/build.gradle b/gemfire-junit/build.gradle
index 112d112..7aa6562 100755
--- a/gemfire-junit/build.gradle
+++ b/gemfire-junit/build.gradle
@@ -16,6 +16,7 @@
*/
dependencies {
+ testCompile 'commons-lang:commons-lang:' + project.'commons-lang.version'
compile 'junit:junit:' + project.'junit.version'
compile 'org.hamcrest:hamcrest-all:' + project.'hamcrest-all.version'
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/Retry.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/Retry.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/Retry.java
index 65f3cf6..6039943 100755
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/Retry.java
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/Retry.java
@@ -23,8 +23,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
- * Java Annotation used to annotate a test suite class test case method in order to
- * retry it in case of failure up to the specified maximum attempts.
+ * Java Annotation used to annotate a test method in order to retry failures
+ * up to the specified maximum attempts. Default maximum attempts is one retry.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeout.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeout.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeout.java
deleted file mode 100755
index 2f53811..0000000
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/ExpectedTimeout.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * 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.junit.rules;
-
-import static org.junit.Assert.assertThat;
-
-import java.util.concurrent.TimeUnit;
-
-import org.hamcrest.Matcher;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-/**
- * Expect an Exception within a specified timeout.
- *
- * @author Kirk Lund
- * @since 8.2
- */
-public class ExpectedTimeout implements TestRule {
-
- /**
- * @return a Rule that expects no timeout (identical to behavior without this Rule)
- */
- public static ExpectedTimeout none() {
- return new ExpectedTimeout();
- }
-
- private ExpectedException delegate;
- private boolean expectsThrowable;
- private long minDuration;
- private long maxDuration;
- private TimeUnit timeUnit;
-
- private ExpectedTimeout() {
- this.delegate = ExpectedException.none();
- }
-
- public ExpectedTimeout expectMinimumDuration(final long minDuration) {
- this.minDuration = minDuration;
- return this;
- }
- public ExpectedTimeout expectMaximumDuration(final long maxDuration) {
- this.maxDuration = maxDuration;
- return this;
- }
- public ExpectedTimeout expectTimeUnit(final TimeUnit timeUnit) {
- this.timeUnit = timeUnit;
- return this;
- }
-
- public ExpectedTimeout handleAssertionErrors() {
- this.delegate.handleAssertionErrors();
- return this;
- }
-
- public ExpectedTimeout handleAssumptionViolatedExceptions() {
- this.delegate.handleAssumptionViolatedExceptions();
- return this;
- }
-
- /**
- * Adds {@code matcher} to the list of requirements for any thrown
- * exception.
- */
- public void expect(final Matcher<?> matcher) {
- this.delegate.expect(matcher);
- }
-
- /**
- * Adds to the list of requirements for any thrown exception that it should
- * be an instance of {@code type}
- */
- public void expect(final Class<? extends Throwable> type) {
- this.delegate.expect(type);
- this.expectsThrowable = true;
- }
-
- /**
- * Adds to the list of requirements for any thrown exception that it should
- * <em>contain</em> string {@code substring}
- */
- public void expectMessage(final String substring) {
- this.delegate.expectMessage(substring);
- }
-
- /**
- * Adds {@code matcher} to the list of requirements for the message returned
- * from any thrown exception.
- */
- public void expectMessage(final Matcher<String> matcher) {
- this.delegate.expectMessage(matcher);
- }
-
- /**
- * Adds {@code matcher} to the list of requirements for the cause of
- * any thrown exception.
- */
- public void expectCause(final Matcher<? extends Throwable> expectedCause) {
- this.delegate.expectCause(expectedCause);
- }
-
- public boolean expectsTimeout() {
- return minDuration > 0 || maxDuration > 0;
- }
-
- public boolean expectsThrowable() {
- return expectsThrowable = true;
- }
-
- @Override
- public Statement apply(final Statement base, final Description description) {
- Statement next = delegate.apply(base, description);
- return new ExpectedTimeoutStatement(next);
- }
-
- private void handleTime(final Long duration) {
- if (expectsTimeout()) {
- assertThat(timeUnit.convert(duration, TimeUnit.NANOSECONDS), new TimeMatcher(timeUnit, minDuration, maxDuration));
- }
- }
-
- private static class TimeMatcher extends org.hamcrest.TypeSafeMatcher<Long> {
-
- private final TimeUnit timeUnit;
- private final long minDuration;
- private final long maxDuration;
-
- public TimeMatcher(final TimeUnit timeUnit, final long minDuration, final long maxDuration) {
- this.timeUnit = timeUnit;
- this.minDuration = minDuration;
- this.maxDuration = maxDuration;
- }
-
- @Override
- public boolean matchesSafely(final Long duration) {
- return duration >= this.minDuration && duration <= this.maxDuration;
- }
-
- @Override
- public void describeTo(final org.hamcrest.Description description) {
- description.appendText("expects duration to be greater than or equal to ")
- .appendValue(this.minDuration)
- .appendText(" and less than or equal to ")
- .appendValue(this.maxDuration)
- .appendText(" ")
- .appendValue(this.timeUnit);
- }
- }
-
- private class ExpectedTimeoutStatement extends Statement {
- private final Statement next;
-
- public ExpectedTimeoutStatement(final Statement base) {
- next = base;
- }
-
- @Override
- public void evaluate() throws Throwable {
- long start = System.nanoTime();
- next.evaluate();
- handleTime(System.nanoTime() - start);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/RuleList.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/RuleList.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/RuleList.java
new file mode 100755
index 0000000..08446b0
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/RuleList.java
@@ -0,0 +1,92 @@
+/*
+ * 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.junit.rules;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The {@code RuleList} rule enables ordering of TestRules.
+ *
+ * <p>Example:
+ *
+ * <pre>
+ * public class SomeTest {
+ *
+ * \@Rule
+ * public RuleList rules = new RuleList().add(new FirstRule()
+ * .add(new SecondRule()
+ * .add(new ThirdRule();
+ * </pre>
+ *
+ * @author Kirk Lund
+ */
+public class RuleList implements TestRule {
+
+ private final List<TestRule> rules = new ArrayList<>();
+
+ /**
+ * Creates an empty {@code RuleList}.
+ */
+ public RuleList() {
+ }
+
+ /**
+ * Creates a {@code RuleList} containing a single {@link TestRule}.
+ *
+ * @param rule the first rule of the {@code RuleList}
+ */
+ public RuleList(final TestRule rule) {
+ this.rules.add(rule);
+ }
+
+ /**
+ * Creates a new {@code RuleList} containing the specified {@link TestRule}s.
+ *
+ * @param rules the list of {@code TestRule}s to add
+ */
+ protected RuleList(final List<TestRule> rules) {
+ this.rules.addAll(rules);
+ }
+
+ /**
+ * Adds a new {@code TestRule} to the end of the current {@code RuleList}.
+ *
+ * @param rule the rule to add.
+ * @return the {@code RuleList} with a new TestRule added
+ */
+ public RuleList add(final TestRule rule) {
+ this.rules.add(rule);
+ return this;
+ }
+
+ @Override
+ public Statement apply(Statement base, final Description description) {
+ for (TestRule each : this.rules) {
+ base = each.apply(base, description);
+ }
+ return base;
+ }
+
+ protected List<TestRule> rules() {
+ return new ArrayList<>(this.rules);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableExternalResource.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableExternalResource.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableExternalResource.java
deleted file mode 100755
index 37d8eb5..0000000
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableExternalResource.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.junit.rules;
-
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-/**
- * Serializable version of ExternalResource JUnit Rule. JUnit lifecycle is not
- * executed in remote JVMs. The <tt>after()</tt> callback has a throws-clause
- * that matches <tt>before()</tt>.
- *
- * Implementation copied from <tt>org.junit.rules.ExternalResource</tt>.
- *
- * @author Kirk Lund
- */
-@SuppressWarnings("serial")
-public abstract class SerializableExternalResource implements SerializableTestRule {
-
- @Override
- public Statement apply(final Statement base, final Description description) {
- if (description.isTest()) {
- return statement(base);
- } else if (description.isSuite()) {
- return statementClass(base);
- }
- return base;
- }
-
- private Statement statement(final Statement base) {
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- before();
- try {
- base.evaluate();
- } finally {
- after();
- }
- }
- };
- }
-
- private Statement statementClass(final Statement base) {
- return new Statement() {
- @Override
- public void evaluate() throws Throwable {
- beforeClass();
- try {
- base.evaluate();
- } finally {
- afterClass();
- }
- }
- };
- }
-
- /**
- * Override to set up your specific external resource.
- *
- * @throws Throwable if setup fails (which will disable {@code after}
- */
- protected void before() throws Throwable {
- // do nothing
- }
-
- /**
- * Override to tear down your specific external resource.
- *
- * @throws Throwable if teardown fails (which will disable {@code after}
- */
- protected void after() throws Throwable {
- // do nothing
- }
-
- /**
- * Override to set up your specific external resource.
- *
- * @throws Throwable if setup fails (which will disable {@code after}
- */
- protected void beforeClass() throws Throwable {
- // do nothing
- }
-
- /**
- * Override to tear down your specific external resource.
- *
- * @throws Throwable if teardown fails (which will disable {@code after}
- */
- protected void afterClass() throws Throwable {
- // do nothing
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableRuleChain.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableRuleChain.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableRuleChain.java
deleted file mode 100755
index 936345e..0000000
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableRuleChain.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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.junit.rules;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-/**
- * Serializable version of TemporaryFolder JUnit Rule. JUnit lifecycle is not
- * executed in remote JVMs.
- *
- * Implementation copied from <tt>org.junit.rules.RuleChain</tt>.
- *
- * The SerializableRuleChain rule allows ordering of TestRules. You create a
- * {@code RuleChain} with {@link #outerRule(TestRule)} and subsequent calls of
- * {@link #around(TestRule)}:
- *
- * <pre>
- * public static class UseRuleChain {
- * @Rule
- * public RuleChain chain= RuleChain
- * .outerRule(new LoggingRule("outer rule")
- * .around(new LoggingRule("middle rule")
- * .around(new LoggingRule("inner rule");
- *
- * @Test
- * public void example() {
- * assertTrue(true);
- * }
- * }
- * </pre>
- *
- * writes the log
- *
- * <pre>
- * starting outer rule
- * starting middle rule
- * starting inner rule
- * finished inner rule
- * finished middle rule
- * finished outer rule
- * </pre>
- *
- * @author Kirk Lund
- */
-@SuppressWarnings("serial")
-public class SerializableRuleChain implements SerializableTestRule {
- private static final SerializableRuleChain EMPTY_CHAIN = new SerializableRuleChain(Collections.<TestRule>emptyList());
-
- private transient List<TestRule> rulesStartingWithInnerMost;
-
- /**
- * Returns a {@code SerializableRuleChain} without a {@link TestRule}. This method may
- * be the starting point of a {@code SerializableRuleChain}.
- *
- * @return a {@code SerializableRuleChain} without a {@link TestRule}.
- */
- public static SerializableRuleChain emptyRuleChain() {
- return EMPTY_CHAIN;
- }
-
- /**
- * Returns a {@code SerializableRuleChain} with a single {@link TestRule}. This method
- * is the usual starting point of a {@code SerializableRuleChain}.
- *
- * @param outerRule the outer rule of the {@code SerializableRuleChain}.
- * @return a {@code SerializableRuleChain} with a single {@link TestRule}.
- */
- public static SerializableRuleChain outerRule(TestRule outerRule) {
- return emptyRuleChain().around(outerRule);
- }
-
- private SerializableRuleChain(List<TestRule> rules) {
- this.rulesStartingWithInnerMost = rules;
- }
-
- /**
- * Create a new {@code SerializableRuleChain}, which encloses the {@code nextRule} with
- * the rules of the current {@code SerializableRuleChain}.
- *
- * @param enclosedRule the rule to enclose.
- * @return a new {@code SerializableRuleChain}.
- */
- public SerializableRuleChain around(TestRule enclosedRule) {
- List<TestRule> rulesOfNewChain = new ArrayList<TestRule>();
- rulesOfNewChain.add(enclosedRule);
- rulesOfNewChain.addAll(rulesStartingWithInnerMost);
- return new SerializableRuleChain(rulesOfNewChain);
- }
-
- /**
- * {@inheritDoc}
- */
- public Statement apply(Statement base, Description description) {
- for (TestRule each : rulesStartingWithInnerMost) {
- base = each.apply(base, description);
- }
- return base;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTemporaryFolder.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTemporaryFolder.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTemporaryFolder.java
deleted file mode 100755
index 0e796b3..0000000
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTemporaryFolder.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.junit.rules;
-
-import java.io.File;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.reflect.Field;
-
-import org.junit.rules.TemporaryFolder;
-
-/**
- * Serializable version of TemporaryFolder JUnit Rule. JUnit lifecycle is not
- * executed in remote JVMs.
- *
- * @author Kirk Lund
- */
-@SuppressWarnings("serial")
-public class SerializableTemporaryFolder extends TemporaryFolder implements SerializableTestRule {
-
- 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/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestName.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestName.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestName.java
deleted file mode 100755
index 1fd255f..0000000
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestName.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.junit.rules;
-
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.reflect.Field;
-
-import org.junit.rules.TestName;
-
-/**
- * Serializable version of TestName JUnit Rule. JUnit lifecycle is not
- * executed in remote JVMs.
- *
- * @author Kirk Lund
- */
-@SuppressWarnings("serial")
-public class SerializableTestName extends TestName implements SerializableTestRule {
-
- 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/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestRule.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestRule.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestRule.java
deleted file mode 100755
index 354c38a..0000000
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestRule.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.junit.rules;
-
-import java.io.Serializable;
-
-import org.junit.rules.TestRule;
-
-/**
- * Serializable version of JUnit TestRule. JUnit lifecycle is not
- * executed in remote JVMs.
- *
- * The simplest way to satisfy this interface is to apply <tt>transient</tt>
- * to every instance field.
- *
- * @author Kirk Lund
- */
-public interface SerializableTestRule extends Serializable, TestRule {
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java
deleted file mode 100755
index 5bcf686..0000000
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTestWatcher.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.junit.rules;
-
-import org.junit.rules.TestWatcher;
-
-/**
- * Serializable version of TestWatcher JUnit Rule. JUnit lifecycle is not
- * executed in remote JVMs.
- *
- * @author Kirk Lund
- */
-@SuppressWarnings("serial")
-public class SerializableTestWatcher extends TestWatcher implements SerializableTestRule {
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java
deleted file mode 100755
index 3136a1c..0000000
--- a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/SerializableTimeout.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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.junit.rules;
-
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-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;
-
-/**
- * Serializable version of Timeout JUnit Rule. JUnit lifecycle is not
- * executed in remote JVMs.
- *
- * @author Kirk Lund
- */
-@SuppressWarnings("serial")
-public class SerializableTimeout extends Timeout implements SerializableTestRule {
-
- 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();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/TestFixtureRule.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/TestFixtureRule.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/TestFixtureRule.java
new file mode 100755
index 0000000..21e5eb9
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/TestFixtureRule.java
@@ -0,0 +1,151 @@
+/*
+ * 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.junit.rules;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * An abstract base class for test rules that combine {@code ClassRule} and
+ * method {@code Rule} test fixture lifecycle callbacks. Subclasses may
+ * override any or all of these methods:
+ * <p><ul>
+ * <li></li>{@link #beforeClass()}
+ * <li></li>{@link #afterClass()}
+ * <li></li>{@link #before()}
+ * <li></li>{@link #after()}
+ * </ul>
+ *
+ * <p>The rule variable does not have to be static in order to implement
+ * {@link #beforeClass()} and {@link #afterClass()}.
+ *
+ * <p>Example:
+ *
+ * <pre>
+ * public class SomeTest {
+ *
+ * \@Rule
+ * public TestFixtureRule testFixtureRule = new TestFixtureRule() {
+ * \@Override
+ * protected void beforeClass() throws Throwable {
+ * // setup executed once before all tests in SomeTest
+ * }
+ * \@Override
+ * protected void afterClass() {
+ * // teardown executed once after all tests in SomeTest
+ * }
+ * \@Override
+ * protected void before() throws Throwable {
+ * // setup executed before each test in SomeTest
+ * }
+ * \@Override
+ * protected void after() {
+ * // teardown executed after each test in SomeTest
+ * }
+ * }
+ * }
+ * </pre>
+ *
+ * @author Kirk Lund
+ */
+public class TestFixtureRule implements TestRule {
+
+ @Override
+ public Statement apply(final Statement base, final Description description) {
+ if (description.isSuite()) {
+ return createClassStatement(base);
+ } else if (description.isTest()) {
+ return createMethodStatement(base);
+ }
+ return base;
+ }
+
+ /**
+ * Returns new <code>Statement</code> for invoking <code>beforeClass</code>
+ * and <code>afterClass</code>.
+ */
+ protected Statement createClassStatement(final Statement base) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ beforeClass();
+ try {
+ base.evaluate();
+ } finally {
+ afterClass();
+ }
+ }
+ };
+ }
+
+ /**
+ * Returns new <code>Statement</code> for invoking <code>before</code>
+ * and <code>after</code>.
+ */
+ protected Statement createMethodStatement(final Statement base) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ before();
+ try {
+ base.evaluate();
+ } finally {
+ after();
+ }
+ }
+ };
+ }
+
+ /**
+ * Override to perform custom setup during <code>beforeClass</code> which
+ * is invoked prior to {@link #before()} and all test methods.
+ *
+ * If any <code>Throwable</code> is thrown, then <code>afterClass</code> will
+ * be disabled.
+ *
+ * @throws Throwable if setup fails
+ */
+ protected void beforeClass() throws Throwable {
+ }
+
+ /**
+ * Override to perform custom tearDown during <code>afterClass</code> which
+ * is invoked following {@link #after()} and all test methods.
+ */
+ protected void afterClass() {
+ }
+
+ /**
+ * Override to perform custom setup before each test method.
+ *
+ * If any <code>Throwable</code> is thrown, then <code>after</code> will
+ * be disabled.
+ *
+ * @throws Throwable if setup fails
+ */
+ protected void before() throws Throwable {
+ // do nothing
+ }
+
+ /**
+ * Override to perform custom tearDown during after each test method.
+ */
+ protected void after() {
+ // do nothing
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldSerializationUtils.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldSerializationUtils.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldSerializationUtils.java
new file mode 100755
index 0000000..97e9265
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldSerializationUtils.java
@@ -0,0 +1,48 @@
+/*
+ * 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.junit.rules.serializable;
+
+import java.lang.reflect.Field;
+
+/**
+ * Provides support for serialization of private fields by reflection.
+ */
+public class FieldSerializationUtils {
+
+ protected FieldSerializationUtils() {
+ }
+
+ public static Object readField(final Class targetClass, final Object targetInstance, final String fieldName) {
+ try {
+ Field assureDeletionField = targetClass.getDeclaredField(fieldName);
+ assureDeletionField.setAccessible(true);
+ return assureDeletionField.get(targetInstance);
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ throw new Error(e);
+ }
+ }
+
+ public static void writeField(final Class targetClass, final Object targetInstance, final String fieldName, final Object value) {
+ try {
+ Field folderField = targetClass.getDeclaredField(fieldName);
+ folderField.setAccessible(true);
+ folderField.set(targetInstance, value);
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ throw new Error(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTemporaryFolder.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTemporaryFolder.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTemporaryFolder.java
new file mode 100755
index 0000000..3dd5ebd
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTemporaryFolder.java
@@ -0,0 +1,26 @@
+/*
+ * 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.junit.rules.serializable;
+
+/**
+ * Names of member fields in {@link org.junit.rules.TemporaryFolder}.
+ */
+interface FieldsOfTemporaryFolder {
+ static final String FIELD_PARENT_FOLDER = "parentFolder"; // java.io.File
+ static final String FIELD_ASSURE_DELETION = "assureDeletion"; // boolean (since JUnit 4.13)
+ static final String FIELD_FOLDER = "folder"; // java.io.File
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTestName.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTestName.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTestName.java
new file mode 100755
index 0000000..3a2e4bb
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTestName.java
@@ -0,0 +1,24 @@
+/*
+ * 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.junit.rules.serializable;
+
+/**
+ * Names of member fields in {@link org.junit.rules.TestName}.
+ */
+public interface FieldsOfTestName {
+ static final String FIELD_NAME = "name"; // String
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTimeout.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTimeout.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTimeout.java
new file mode 100755
index 0000000..fab28ed
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/FieldsOfTimeout.java
@@ -0,0 +1,26 @@
+/*
+ * 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.junit.rules.serializable;
+
+/**
+ * Names of member fields in {@link org.junit.rules.Timeout}.
+ */
+interface FieldsOfTimeout {
+ static final String FIELD_TIMEOUT = "timeout"; // long
+ static final String FIELD_TIME_UNIT = "timeUnit"; // java.util.concurrent.TimeUnit
+ static final String FIELD_LOOK_FOR_STUCK_THREAD = "lookForStuckThread"; // boolean
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableExternalResource.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableExternalResource.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableExternalResource.java
new file mode 100755
index 0000000..772891f
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableExternalResource.java
@@ -0,0 +1,25 @@
+/*
+ * 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.junit.rules.serializable;
+
+import org.junit.rules.ExternalResource;
+
+/**
+ * Serializable subclass of {@link org.junit.rules.ExternalResource ExternalResource}.
+ */
+public abstract class SerializableExternalResource extends ExternalResource implements SerializableTestRule {
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableRuleList.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableRuleList.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableRuleList.java
new file mode 100755
index 0000000..b1bbf83
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableRuleList.java
@@ -0,0 +1,78 @@
+/*
+ * 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.junit.rules.serializable;
+
+import com.gemstone.gemfire.test.junit.rules.RuleList;
+import org.junit.rules.TestRule;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Serializable version of {@link RuleList}.
+ */
+public class SerializableRuleList extends RuleList implements SerializableTestRule {
+
+ public SerializableRuleList() {
+ super();
+ }
+
+ public SerializableRuleList(final TestRule rule) {
+ super(rule);
+ }
+
+ public SerializableRuleList(final List<TestRule> rules) {
+ super(rules);
+ }
+
+ @Override
+ public SerializableRuleList add(final TestRule rule) {
+ super.add(rule);
+ return this;
+ }
+
+ @Override
+ protected List<TestRule> rules() {
+ return super.rules();
+ }
+
+ private void readObject(final ObjectInputStream stream) throws InvalidObjectException {
+ throw new InvalidObjectException("SerializationProxy required");
+ }
+
+ private Object writeReplace() {
+ return new SerializationProxy(this);
+ }
+
+ /**
+ * Serialization proxy for {@code SerializableRuleList}.
+ */
+ private static class SerializationProxy implements Serializable {
+
+ private final List<TestRule> rules;
+
+ SerializationProxy(final SerializableRuleList instance) {
+ this.rules = instance.rules();
+ }
+
+ private Object readResolve() {
+ return new SerializableRuleList(this.rules);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTemporaryFolder.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTemporaryFolder.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTemporaryFolder.java
new file mode 100755
index 0000000..6fb01cd
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTemporaryFolder.java
@@ -0,0 +1,71 @@
+/*
+ * 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.junit.rules.serializable;
+
+import static com.gemstone.gemfire.test.junit.rules.serializable.FieldSerializationUtils.*;
+import static com.gemstone.gemfire.test.junit.rules.serializable.FieldsOfTemporaryFolder.*;
+
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+
+/**
+ * Serializable subclass of {@link org.junit.rules.TemporaryFolder TemporaryFolder}.
+ * Instance variables of TemporaryFolder are serialized by reflection.
+ */
+public class SerializableTemporaryFolder extends TemporaryFolder implements SerializableTestRule {
+
+ public SerializableTemporaryFolder() {
+ super();
+ }
+
+ public SerializableTemporaryFolder(final File parentFolder) {
+ super(parentFolder);
+ }
+
+ private void readObject(final ObjectInputStream stream) throws InvalidObjectException {
+ throw new InvalidObjectException("SerializationProxy required");
+ }
+
+ private Object writeReplace() {
+ return new SerializationProxy(this);
+ }
+
+ /**
+ * Serialization proxy for {@code SerializableTemporaryFolder}.
+ */
+ private static class SerializationProxy implements Serializable {
+
+ private static final long serialVersionUID = 1905526044015078240L;
+ private final File parentFolder;
+ private final File folder;
+
+ SerializationProxy(final SerializableTemporaryFolder instance) {
+ this.parentFolder = (File) readField(TemporaryFolder.class, instance, FIELD_PARENT_FOLDER);
+ this.folder =(File) readField(TemporaryFolder.class, instance, FIELD_FOLDER);
+ }
+
+ private Object readResolve() {
+ SerializableTemporaryFolder instance = new SerializableTemporaryFolder(this.parentFolder);
+ writeField(TemporaryFolder.class, instance, FIELD_FOLDER, this.folder);
+ return instance;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestFixtureRule.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestFixtureRule.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestFixtureRule.java
new file mode 100755
index 0000000..182b370
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestFixtureRule.java
@@ -0,0 +1,25 @@
+/*
+ * 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.junit.rules.serializable;
+
+import com.gemstone.gemfire.test.junit.rules.TestFixtureRule;
+
+/**
+ * Serializable version of {@link TestFixtureRule}.
+ */
+public abstract class SerializableTestFixtureRule extends TestFixtureRule implements SerializableTestRule {
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestName.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestName.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestName.java
new file mode 100755
index 0000000..cb87882
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestName.java
@@ -0,0 +1,65 @@
+/*
+ * 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.junit.rules.serializable;
+
+import static com.gemstone.gemfire.test.junit.rules.serializable.FieldSerializationUtils.*;
+import static com.gemstone.gemfire.test.junit.rules.serializable.FieldsOfTestName.*;
+
+import org.junit.rules.TestName;
+import org.junit.runner.Description;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+
+/**
+ * Serializable subclass of {@link org.junit.rules.TestName TestName}. All
+ * instance variables of {@code TestName} are serialized by reflection.
+ */
+public class SerializableTestName extends TestName implements SerializableTestRule {
+
+ @Override
+ protected void starting(final Description description) {
+ super.starting(description);
+ }
+
+ private void readObject(final ObjectInputStream stream) throws InvalidObjectException {
+ throw new InvalidObjectException("SerializationProxy required");
+ }
+
+ private Object writeReplace() {
+ return new SerializationProxy(this);
+ }
+
+ /**
+ * Serialization proxy for {@code SerializableTestName}.
+ */
+ private static class SerializationProxy implements Serializable {
+
+ private final String name;
+
+ SerializationProxy(final SerializableTestName instance) {
+ this.name = (String) readField(TestName.class, instance, FIELD_NAME);
+ }
+
+ private Object readResolve() {
+ SerializableTestName instance = new SerializableTestName();
+ writeField(TestName.class, instance, FIELD_NAME, this.name);
+ return instance;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestRule.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestRule.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestRule.java
new file mode 100755
index 0000000..f910c14
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestRule.java
@@ -0,0 +1,31 @@
+/*
+ * 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.junit.rules.serializable;
+
+import java.io.Serializable;
+
+import org.junit.rules.TestRule;
+
+/**
+ * Specifies that a {@link org.junit.rules.TestRule TestRule} is
+ * {@code Serializable}.
+ *
+ * The simplest way to satisfy this interface is to apply {@code transient} to
+ * every instance field.
+ */
+public interface SerializableTestRule extends Serializable, TestRule {
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestWatcher.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestWatcher.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestWatcher.java
new file mode 100755
index 0000000..6292d7c
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTestWatcher.java
@@ -0,0 +1,26 @@
+/*
+ * 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.junit.rules.serializable;
+
+import org.junit.rules.TestWatcher;
+
+/**
+ * Serializable subclass of {@link org.junit.rules.TestWatcher TestWatcher}. No
+ * instance variables are serialized.
+ */
+public abstract class SerializableTestWatcher extends TestWatcher implements SerializableTestRule {
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f2487a46/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTimeout.java
----------------------------------------------------------------------
diff --git a/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTimeout.java b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTimeout.java
new file mode 100755
index 0000000..e77120d
--- /dev/null
+++ b/gemfire-junit/src/main/java/com/gemstone/gemfire/test/junit/rules/serializable/SerializableTimeout.java
@@ -0,0 +1,108 @@
+/*
+ * 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.junit.rules.serializable;
+
+import static com.gemstone.gemfire.test.junit.rules.serializable.FieldSerializationUtils.*;
+import static com.gemstone.gemfire.test.junit.rules.serializable.FieldsOfTimeout.*;
+
+import org.junit.rules.Timeout;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Serializable subclass of {@link org.junit.rules.Timeout Timeout}. All
+ * instance variables of {@code Timeout} are serialized by reflection.
+ */
+public class SerializableTimeout extends Timeout implements SerializableTestRule {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public SerializableTimeout() {
+ this(builder());
+ }
+
+ public SerializableTimeout(final long timeout, final TimeUnit timeUnit) {
+ super(timeout, timeUnit);
+ }
+
+ protected SerializableTimeout(final Builder builder) {
+ super(builder);
+ }
+
+ private void readObject(final ObjectInputStream stream) throws InvalidObjectException {
+ throw new InvalidObjectException("SerializationProxy required");
+ }
+
+ private Object writeReplace() {
+ return new SerializationProxy(this);
+ }
+
+ /**
+ * Builder for {@code SerializableTimeout}.
+ */
+ public static class Builder extends Timeout.Builder {
+
+ protected Builder() {
+ super();
+ }
+
+ @Override
+ public Builder withTimeout(final long timeout, final TimeUnit unit) {
+ super.withTimeout(timeout, unit);
+ return this;
+ }
+
+ @Override
+ public Builder withLookingForStuckThread(boolean enable) {
+ super.withLookingForStuckThread(enable);
+ return this;
+ }
+
+ @Override
+ public SerializableTimeout build() {
+ return new SerializableTimeout(this);
+ }
+ }
+
+ /**
+ * Serialization proxy for {@code SerializableTimeout}.
+ */
+ private static class SerializationProxy implements Serializable {
+
+ private final long timeout;
+ private final TimeUnit timeUnit;
+ private final boolean lookForStuckThread;
+
+ SerializationProxy(SerializableTimeout instance) {
+ this.timeout = (long) readField(Timeout.class, instance, FIELD_TIMEOUT);
+ this.timeUnit =(TimeUnit) readField(Timeout.class, instance, FIELD_TIME_UNIT);
+ this.lookForStuckThread =(boolean) readField(Timeout.class, instance, FIELD_LOOK_FOR_STUCK_THREAD);
+ }
+
+ private Object readResolve() {
+ return new SerializableTimeout.Builder()
+ .withTimeout(this.timeout, this.timeUnit)
+ .withLookingForStuckThread(this.lookForStuckThread)
+ .build();
+ }
+ }
+}