This is an automated email from the ASF dual-hosted git repository.

klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new ae0d6bc  GEODE-8550: Rename DistributedCloseableReference (#5579)
ae0d6bc is described below

commit ae0d6bcdbc41a364b21bc5c55bd982271ad1284b
Author: Kirk Lund <[email protected]>
AuthorDate: Fri Oct 2 15:26:17 2020 -0700

    GEODE-8550: Rename DistributedCloseableReference (#5579)
    
    Rename DistributedReference as DistributedCloseableReference.
---
 .../ReplicateRegionNetsearchDistributedTest.java   |   8 +-
 .../fixed/FixedPartitioningDUnitTest.java          |   4 +-
 ...ributedCloseableReferenceCacheExampleTest.java} |  18 +-
 ...seableReferenceLocatorLauncherExampleTest.java} |  19 +-
 ...oseableReferenceServerLauncherExampleTest.java} |  21 +-
 ...ibutedCloseableReferenceSystemExampleTest.java} |  19 +-
 ...java => DistributedCloseableReferenceTest.java} | 244 +++++++++++----------
 .../geode/test/dunit/DistributedTestUtils.java     |  71 +++---
 ...nce.java => DistributedCloseableReference.java} | 100 ++++++---
 .../geode/test/dunit/rules/DistributedRule.java    |  13 +-
 .../geode/test/junit/rules/CloseableReference.java |  17 +-
 11 files changed, 293 insertions(+), 241 deletions(-)

diff --git 
a/geode-core/src/distributedTest/java/org/apache/geode/cache/ReplicateRegionNetsearchDistributedTest.java
 
b/geode-core/src/distributedTest/java/org/apache/geode/cache/ReplicateRegionNetsearchDistributedTest.java
index e9a6ed3..ab4d7b8 100644
--- 
a/geode-core/src/distributedTest/java/org/apache/geode/cache/ReplicateRegionNetsearchDistributedTest.java
+++ 
b/geode-core/src/distributedTest/java/org/apache/geode/cache/ReplicateRegionNetsearchDistributedTest.java
@@ -36,7 +36,7 @@ import org.apache.geode.distributed.ServerLauncher;
 import org.apache.geode.internal.cache.CachePerfStats;
 import org.apache.geode.internal.cache.InternalRegion;
 import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.rules.DistributedReference;
+import org.apache.geode.test.dunit.rules.DistributedCloseableReference;
 import org.apache.geode.test.dunit.rules.DistributedRule;
 import 
org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
 
@@ -60,9 +60,11 @@ public class ReplicateRegionNetsearchDistributedTest 
implements Serializable {
   @Rule
   public DistributedRule distributedRule = new DistributedRule();
   @Rule
-  public DistributedReference<ServerLauncher> serverLauncher = new 
DistributedReference<>();
+  public DistributedCloseableReference<ServerLauncher> serverLauncher =
+      new DistributedCloseableReference<>();
   @Rule
-  public DistributedReference<ClientCache> clientCache = new 
DistributedReference<>();
+  public DistributedCloseableReference<ClientCache> clientCache =
+      new DistributedCloseableReference<>();
   @Rule
   public SerializableTemporaryFolder temporaryFolder = new 
SerializableTemporaryFolder();
 
diff --git 
a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/fixed/FixedPartitioningDUnitTest.java
 
b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/fixed/FixedPartitioningDUnitTest.java
index 90d3863..8bf9c91 100644
--- 
a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/fixed/FixedPartitioningDUnitTest.java
+++ 
b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/fixed/FixedPartitioningDUnitTest.java
@@ -75,9 +75,9 @@ import org.apache.geode.test.dunit.AsyncInvocation;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.dunit.Wait;
 import org.apache.geode.test.dunit.rules.DistributedBlackboard;
+import org.apache.geode.test.dunit.rules.DistributedCloseableReference;
 import org.apache.geode.test.dunit.rules.DistributedDiskDirRule;
 import org.apache.geode.test.dunit.rules.DistributedErrorCollector;
-import org.apache.geode.test.dunit.rules.DistributedReference;
 import org.apache.geode.test.dunit.rules.DistributedRestoreSystemProperties;
 import org.apache.geode.test.dunit.rules.DistributedRule;
 import org.apache.geode.test.junit.categories.PartitioningTest;
@@ -105,7 +105,7 @@ public class FixedPartitioningDUnitTest implements 
Serializable {
   @Rule
   public DistributedRule distributedRule = new DistributedRule();
   @Rule
-  public DistributedReference<Cache> cache = new DistributedReference<>();
+  public DistributedCloseableReference<Cache> cache = new 
DistributedCloseableReference<>();
   @Rule
   public DistributedDiskDirRule diskDirRule = new DistributedDiskDirRule();
   @Rule
diff --git 
a/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceCacheExampleTest.java
 
b/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceCacheExampleTest.java
similarity index 72%
rename from 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceCacheExampleTest.java
rename to 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceCacheExampleTest.java
index f7f2df0..945e82e 100644
--- 
a/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceCacheExampleTest.java
+++ 
b/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceCacheExampleTest.java
@@ -16,10 +16,11 @@
  */
 package org.apache.geode.test.dunit.examples;
 
+import static java.util.Arrays.asList;
 import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
 import static org.apache.geode.test.dunit.VM.getController;
 import static org.apache.geode.test.dunit.VM.getVM;
-import static org.apache.geode.test.dunit.VM.toArray;
+import static org.apache.geode.test.dunit.rules.DistributedRule.getLocators;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.Serializable;
@@ -31,22 +32,21 @@ import org.junit.Test;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.test.dunit.DistributedTestUtils;
 import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.rules.DistributedReference;
+import org.apache.geode.test.dunit.rules.DistributedCloseableReference;
 
 @SuppressWarnings("serial")
-public class DistributedReferenceCacheExampleTest implements Serializable {
+public class DistributedCloseableReferenceCacheExampleTest implements 
Serializable {
 
   @Rule
-  public DistributedReference<Cache> cache = new DistributedReference<>();
+  public DistributedCloseableReference<Cache> cache = new 
DistributedCloseableReference<>();
 
   @Before
   public void setUp() {
     Properties configProperties = new Properties();
-    configProperties.setProperty(LOCATORS, DistributedTestUtils.getLocators());
+    configProperties.setProperty(LOCATORS, getLocators());
 
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
         cache.set(new CacheFactory(configProperties).create());
       });
@@ -55,9 +55,9 @@ public class DistributedReferenceCacheExampleTest implements 
Serializable {
 
   @Test
   public void eachVmHasItsOwnCache() {
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
-        assertThat(cache.get()).isInstanceOf(Cache.class);
+        assertThat(cache.get()).isNotNull();
       });
     }
   }
diff --git 
a/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceLocatorLauncherExampleTest.java
 
b/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceLocatorLauncherExampleTest.java
similarity index 83%
rename from 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceLocatorLauncherExampleTest.java
rename to 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceLocatorLauncherExampleTest.java
index 21dc524..43b6d17 100644
--- 
a/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceLocatorLauncherExampleTest.java
+++ 
b/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceLocatorLauncherExampleTest.java
@@ -14,15 +14,15 @@
  */
 package org.apache.geode.test.dunit.examples;
 
+import static java.util.Arrays.asList;
 import static 
org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
 import static 
org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
 import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.test.dunit.DistributedTestUtils.getLocatorPort;
 import static org.apache.geode.test.dunit.VM.getController;
 import static org.apache.geode.test.dunit.VM.getHostName;
 import static org.apache.geode.test.dunit.VM.getVM;
 import static org.apache.geode.test.dunit.VM.getVMId;
-import static org.apache.geode.test.dunit.VM.toArray;
+import static org.apache.geode.test.dunit.rules.DistributedRule.getLocatorPort;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.Serializable;
@@ -36,14 +36,15 @@ import 
org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.internal.AvailablePortHelper;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.rules.DistributedReference;
+import org.apache.geode.test.dunit.rules.DistributedCloseableReference;
 import 
org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
 
 @SuppressWarnings("serial")
-public class DistributedReferenceLocatorLauncherExampleTest implements 
Serializable {
+public class DistributedCloseableReferenceLocatorLauncherExampleTest 
implements Serializable {
 
   @Rule
-  public DistributedReference<LocatorLauncher> locatorLauncher = new 
DistributedReference<>();
+  public DistributedCloseableReference<LocatorLauncher> locatorLauncher =
+      new DistributedCloseableReference<>();
 
   @Rule
   public SerializableTemporaryFolder temporaryFolder = new 
SerializableTemporaryFolder();
@@ -62,10 +63,10 @@ public class DistributedReferenceLocatorLauncherExampleTest 
implements Serializa
         .append(hostName).append('[').append(randomPorts[4]).append(']');
 
     int index = 0;
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       int whichPort = index++;
       vm.invoke(() -> {
-        String name = getClass().getSimpleName() + "-vm-" + getVMId();
+        String name = "locator-" + getVMId();
         LocatorLauncher locatorLauncher = new LocatorLauncher.Builder()
             
.setWorkingDirectory(temporaryFolder.newFolder(name).getAbsolutePath())
             .setMemberName(name)
@@ -82,9 +83,9 @@ public class DistributedReferenceLocatorLauncherExampleTest 
implements Serializa
 
   @Test
   public void eachVmHasItsOwnLocatorLauncher() {
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
-        assertThat(locatorLauncher.get()).isInstanceOf(LocatorLauncher.class);
+        assertThat(locatorLauncher.get()).isNotNull();
 
         InternalCache cache = (InternalCache) locatorLauncher.get().getCache();
         InternalDistributedSystem system = 
cache.getInternalDistributedSystem();
diff --git 
a/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceServerLauncherExampleTest.java
 
b/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceServerLauncherExampleTest.java
similarity index 78%
rename from 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceServerLauncherExampleTest.java
rename to 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceServerLauncherExampleTest.java
index 7b18a2f..77682e4 100644
--- 
a/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceServerLauncherExampleTest.java
+++ 
b/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceServerLauncherExampleTest.java
@@ -14,13 +14,14 @@
  */
 package org.apache.geode.test.dunit.examples;
 
+import static java.util.Arrays.asList;
 import static 
org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
 import static 
org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT;
 import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
 import static org.apache.geode.test.dunit.VM.getController;
 import static org.apache.geode.test.dunit.VM.getVM;
 import static org.apache.geode.test.dunit.VM.getVMId;
-import static org.apache.geode.test.dunit.VM.toArray;
+import static org.apache.geode.test.dunit.rules.DistributedRule.getLocators;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.Serializable;
@@ -32,27 +33,27 @@ import org.junit.Test;
 import org.apache.geode.distributed.ServerLauncher;
 import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.test.dunit.DistributedTestUtils;
 import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.rules.DistributedReference;
+import org.apache.geode.test.dunit.rules.DistributedCloseableReference;
 import 
org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
 
 @SuppressWarnings("serial")
-public class DistributedReferenceServerLauncherExampleTest implements 
Serializable {
+public class DistributedCloseableReferenceServerLauncherExampleTest implements 
Serializable {
 
   @Rule
-  public DistributedReference<ServerLauncher> serverLauncher = new 
DistributedReference<>();
+  public DistributedCloseableReference<ServerLauncher> serverLauncher =
+      new DistributedCloseableReference<>();
 
   @Rule
   public SerializableTemporaryFolder temporaryFolder = new 
SerializableTemporaryFolder();
 
   @Before
   public void setUp() {
-    String locators = DistributedTestUtils.getLocators();
+    String locators = getLocators();
 
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
-        String name = getClass().getSimpleName() + "-vm-" + getVMId();
+        String name = "server-" + getVMId();
         ServerLauncher serverLauncher = new ServerLauncher.Builder()
             
.setWorkingDirectory(temporaryFolder.newFolder(name).getAbsolutePath())
             .setMemberName(name)
@@ -69,9 +70,9 @@ public class DistributedReferenceServerLauncherExampleTest 
implements Serializab
 
   @Test
   public void eachVmHasItsOwnLocatorLauncher() {
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
-        assertThat(serverLauncher.get()).isInstanceOf(ServerLauncher.class);
+        assertThat(serverLauncher.get()).isNotNull();
 
         InternalCache cache = (InternalCache) serverLauncher.get().getCache();
         InternalDistributedSystem system = 
cache.getInternalDistributedSystem();
diff --git 
a/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceSystemExampleTest.java
 
b/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceSystemExampleTest.java
similarity index 71%
rename from 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceSystemExampleTest.java
rename to 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceSystemExampleTest.java
index 3e3e4ca..bc08aae 100644
--- 
a/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedReferenceSystemExampleTest.java
+++ 
b/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/examples/DistributedCloseableReferenceSystemExampleTest.java
@@ -16,10 +16,11 @@
  */
 package org.apache.geode.test.dunit.examples;
 
+import static java.util.Arrays.asList;
 import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
 import static org.apache.geode.test.dunit.VM.getController;
 import static org.apache.geode.test.dunit.VM.getVM;
-import static org.apache.geode.test.dunit.VM.toArray;
+import static org.apache.geode.test.dunit.rules.DistributedRule.getLocators;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.Serializable;
@@ -30,22 +31,22 @@ import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.test.dunit.DistributedTestUtils;
 import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.rules.DistributedReference;
+import org.apache.geode.test.dunit.rules.DistributedCloseableReference;
 
 @SuppressWarnings("serial")
-public class DistributedReferenceSystemExampleTest implements Serializable {
+public class DistributedCloseableReferenceSystemExampleTest implements 
Serializable {
 
   @Rule
-  public DistributedReference<DistributedSystem> system = new 
DistributedReference<>();
+  public DistributedCloseableReference<DistributedSystem> system =
+      new DistributedCloseableReference<>();
 
   @Before
   public void setUp() {
     Properties configProperties = new Properties();
-    configProperties.setProperty(LOCATORS, DistributedTestUtils.getLocators());
+    configProperties.setProperty(LOCATORS, getLocators());
 
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
         system.set(DistributedSystem.connect(configProperties));
       });
@@ -54,9 +55,9 @@ public class DistributedReferenceSystemExampleTest implements 
Serializable {
 
   @Test
   public void eachVmHasItsOwnSystemConnection() {
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
-        assertThat(system.get()).isInstanceOf(DistributedSystem.class);
+        assertThat(system.get()).isNotNull();
       });
     }
   }
diff --git 
a/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/rules/tests/DistributedReferenceTest.java
 
b/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/rules/tests/DistributedCloseableReferenceTest.java
similarity index 55%
rename from 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/rules/tests/DistributedReferenceTest.java
rename to 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/rules/tests/DistributedCloseableReferenceTest.java
index 21989ba..55a3d74 100644
--- 
a/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/rules/tests/DistributedReferenceTest.java
+++ 
b/geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/rules/tests/DistributedCloseableReferenceTest.java
@@ -16,9 +16,9 @@
  */
 package org.apache.geode.test.dunit.rules.tests;
 
+import static java.util.Arrays.asList;
 import static org.apache.geode.test.dunit.VM.getController;
 import static org.apache.geode.test.dunit.VM.getVM;
-import static org.apache.geode.test.dunit.VM.toArray;
 import static 
org.apache.geode.test.junit.runners.TestRunner.runTestWithValidation;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -27,18 +27,20 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
 import java.io.Closeable;
+import java.io.IOException;
 import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
 import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.rules.DistributedReference;
+import org.apache.geode.test.dunit.rules.DistributedCloseableReference;
 import org.apache.geode.test.dunit.rules.DistributedRule;
 
-@SuppressWarnings({"serial", "unused"})
-public class DistributedReferenceTest {
+@SuppressWarnings({"serial", "CodeBlock2Expr"})
+public class DistributedCloseableReferenceTest {
 
   @Rule
   public DistributedRule distributedRule = new DistributedRule();
@@ -52,14 +54,14 @@ public class DistributedReferenceTest {
   public void closesAutoCloseableInLocalVm() throws Exception {
     runTestWithValidation(SetAutoCloseableInLocalVm.class);
 
-    verify(SetAutoCloseableInLocalVm.autoCloseable).close();
+    verify(SetAutoCloseableInLocalVm.autoCloseable.get()).close();
   }
 
   @Test
   public void doesNotAutoCloseIfAutoCloseIsFalse() throws Exception {
     runTestWithValidation(DisableAutoCloseInLocalVm.class);
 
-    verify(DisableAutoCloseInLocalVm.autoCloseable, times(0)).close();
+    verify(DisableAutoCloseInLocalVm.autoCloseable.get(), times(0)).close();
   }
 
   @Test
@@ -71,7 +73,7 @@ public class DistributedReferenceTest {
   public void closesAutoCloseableInRemoteVm() {
     runTestWithValidation(SetAutoCloseableInRemoteVm.class);
 
-    getVM(0).invoke(() -> 
verify(SetAutoCloseableInRemoteVm.autoCloseable).close());
+    getVM(0).invoke(() -> 
verify(SetAutoCloseableInRemoteVm.autoCloseable.get()).close());
   }
 
   @Test
@@ -83,9 +85,9 @@ public class DistributedReferenceTest {
   public void closesAutoCloseableInEachVm() {
     runTestWithValidation(SetAutoCloseableInEachVm.class);
 
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
-        verify(SetAutoCloseableInEachVm.autoCloseable).close();
+        verify(SetAutoCloseableInEachVm.autoCloseable.get()).close();
       });
     }
   }
@@ -96,10 +98,10 @@ public class DistributedReferenceTest {
   }
 
   @Test
-  public void closesCloseableInLocalVm() throws Exception {
+  public void closesCloseableInLocalVm() throws IOException {
     runTestWithValidation(SetCloseableInLocalVm.class);
 
-    verify(SetCloseableInLocalVm.closeable).close();
+    verify(SetCloseableInLocalVm.closeable.get()).close();
   }
 
   @Test
@@ -111,7 +113,7 @@ public class DistributedReferenceTest {
   public void closesCloseableInRemoteVm() {
     runTestWithValidation(SetCloseableInRemoteVm.class);
 
-    getVM(0).invoke(() -> verify(SetCloseableInRemoteVm.closeable).close());
+    getVM(0).invoke(() -> 
verify(SetCloseableInRemoteVm.closeable.get()).close());
   }
 
   @Test
@@ -123,9 +125,9 @@ public class DistributedReferenceTest {
   public void closesCloseableInEachVm() {
     runTestWithValidation(SetCloseableInEachVm.class);
 
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
-        verify(SetCloseableInEachVm.closeable).close();
+        verify(SetCloseableInEachVm.closeable.get()).close();
       });
     }
   }
@@ -139,7 +141,7 @@ public class DistributedReferenceTest {
   public void closesWithCloseInLocalVm() {
     runTestWithValidation(SetWithCloseInLocalVm.class);
 
-    verify(SetWithCloseInLocalVm.withClose).close();
+    verify(SetWithCloseInLocalVm.withClose.get()).close();
   }
 
   @Test
@@ -151,7 +153,7 @@ public class DistributedReferenceTest {
   public void closesWithCloseInRemoteVm() {
     runTestWithValidation(SetWithCloseInRemoteVm.class);
 
-    getVM(0).invoke(() -> verify(SetWithCloseInRemoteVm.withClose).close());
+    getVM(0).invoke(() -> 
verify(SetWithCloseInRemoteVm.withClose.get()).close());
   }
 
   @Test
@@ -163,9 +165,9 @@ public class DistributedReferenceTest {
   public void closesWithCloseInEachVm() {
     runTestWithValidation(SetWithCloseInEachVm.class);
 
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
-        verify(SetWithCloseInEachVm.withClose).close();
+        verify(SetWithCloseInEachVm.withClose.get()).close();
       });
     }
   }
@@ -179,7 +181,7 @@ public class DistributedReferenceTest {
   public void disconnectsWithDisconnectInLocalVm() {
     runTestWithValidation(SetWithDisconnectInLocalVm.class);
 
-    verify(SetWithDisconnectInLocalVm.withDisconnect).disconnect();
+    verify(SetWithDisconnectInLocalVm.withDisconnect.get()).disconnect();
   }
 
   @Test
@@ -191,7 +193,7 @@ public class DistributedReferenceTest {
   public void disconnectsWithDisconnectInRemoteVm() {
     runTestWithValidation(SetWithDisconnectInRemoteVm.class);
 
-    getVM(0).invoke(() -> 
verify(SetWithDisconnectInRemoteVm.withDisconnect).disconnect());
+    getVM(0).invoke(() -> 
verify(SetWithDisconnectInRemoteVm.withDisconnect.get()).disconnect());
   }
 
   @Test
@@ -203,98 +205,101 @@ public class DistributedReferenceTest {
   public void disconnectsWithDisconnectInEachVm() {
     runTestWithValidation(SetWithDisconnectInEachVm.class);
 
-    for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+    for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
       vm.invoke(() -> {
-        verify(SetWithDisconnectInEachVm.withDisconnect).disconnect();
+        verify(SetWithDisconnectInEachVm.withDisconnect.get()).disconnect();
       });
     }
   }
 
   public static class SetAutoCloseableInLocalVm implements Serializable {
 
-    private static AutoCloseable autoCloseable;
+    private static final AtomicReference<AutoCloseable> autoCloseable = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<AutoCloseable> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<AutoCloseable> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
-      autoCloseable = mock(AutoCloseable.class);
-      reference.set(autoCloseable);
+      autoCloseable.set(mock(AutoCloseable.class));
+      reference.set(autoCloseable.get());
     }
 
     @Test
     public void hasReferenceInLocalVm() {
-      assertThat(reference.get()).isSameAs(autoCloseable);
+      assertThat(reference.get()).isSameAs(autoCloseable.get());
     }
   }
 
   public static class DisableAutoCloseInLocalVm implements Serializable {
 
-    private static AutoCloseable autoCloseable;
+    private static final AtomicReference<AutoCloseable> autoCloseable = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<AutoCloseable> reference =
-        new DistributedReference<AutoCloseable>().autoClose(false);
+    public DistributedCloseableReference<AutoCloseable> reference =
+        new DistributedCloseableReference<AutoCloseable>().autoClose(false);
 
     @Before
     public void setUp() {
-      autoCloseable = mock(AutoCloseable.class);
-      reference.set(autoCloseable);
+      autoCloseable.set(mock(AutoCloseable.class));
+      reference.set(autoCloseable.get());
     }
 
     @Test
     public void hasReferenceInLocalVm() {
-      assertThat(reference.get()).isSameAs(autoCloseable);
+      assertThat(reference.get()).isSameAs(autoCloseable.get());
     }
   }
 
   public static class SetAutoCloseableInRemoteVm implements Serializable {
 
-    private static AutoCloseable autoCloseable;
+    private static final AtomicReference<AutoCloseable> autoCloseable = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<AutoCloseable> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<AutoCloseable> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
       VM vm = getVM(0);
       vm.invoke(() -> {
-        autoCloseable = mock(AutoCloseable.class, "AutoCloseable in VM-" + 
vm.getId());
-        reference.set(autoCloseable);
+        autoCloseable.set(mock(AutoCloseable.class, "AutoCloseable in VM-" + 
vm.getId()));
+        reference.set(autoCloseable.get());
       });
     }
 
     @Test
     public void hasAutoCloseableInRemoteVm() {
       getVM(0).invoke(() -> {
-        assertThat(reference.get()).isSameAs(autoCloseable);
+        assertThat(reference.get()).isSameAs(autoCloseable.get());
       });
     }
   }
 
   public static class SetAutoCloseableInEachVm implements Serializable {
 
-    private static AutoCloseable autoCloseable;
+    private static final AtomicReference<AutoCloseable> autoCloseable = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<AutoCloseable> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<AutoCloseable> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
-      for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
         vm.invoke(() -> {
-          autoCloseable = mock(AutoCloseable.class, "AutoCloseable in VM-" + 
vm.getId());
-          reference.set(autoCloseable);
+          autoCloseable.set(mock(AutoCloseable.class, "AutoCloseable in VM-" + 
vm.getId()));
+          reference.set(autoCloseable.get());
         });
       }
     }
 
     @Test
     public void hasAutoCloseableInEachVm() {
-      for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
         vm.invoke(() -> {
-          assertThat(reference.get()).isSameAs(autoCloseable);
+          assertThat(reference.get()).isSameAs(autoCloseable.get());
           assertThat(reference.get().toString()).isEqualTo("AutoCloseable in 
VM-" + vm.getId());
         });
       }
@@ -303,69 +308,72 @@ public class DistributedReferenceTest {
 
   public static class SetCloseableInLocalVm implements Serializable {
 
-    private static Closeable closeable;
+    private static final AtomicReference<Closeable> closeable = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<Closeable> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<Closeable> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
-      closeable = mock(Closeable.class);
-      reference.set(closeable);
+      closeable.set(mock(Closeable.class));
+      reference.set(closeable.get());
     }
 
     @Test
     public void hasCloseableInLocalVm() {
-      assertThat(reference.get()).isSameAs(closeable);
+      assertThat(reference.get()).isSameAs(closeable.get());
     }
   }
 
   public static class SetCloseableInRemoteVm implements Serializable {
 
-    private static Closeable closeable;
+    private static final AtomicReference<Closeable> closeable = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<Closeable> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<Closeable> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
       VM vm = getVM(0);
       vm.invoke(() -> {
-        closeable = mock(Closeable.class, "Closeable in VM-" + vm.getId());
-        reference.set(closeable);
+        closeable.set(mock(Closeable.class, "Closeable in VM-" + vm.getId()));
+        reference.set(closeable.get());
       });
     }
 
     @Test
     public void hasCloseableInRemoteVm() {
       getVM(0).invoke(() -> {
-        assertThat(reference.get()).isSameAs(closeable);
+        assertThat(reference.get()).isSameAs(closeable.get());
       });
     }
   }
 
   public static class SetCloseableInEachVm implements Serializable {
 
-    private static Closeable closeable;
+    private static final AtomicReference<Closeable> closeable = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<Closeable> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<Closeable> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
-      for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
         vm.invoke(() -> {
-          closeable = mock(Closeable.class, "Closeable in VM-" + vm.getId());
-          reference.set(closeable);
+          closeable.set(mock(Closeable.class, "Closeable in VM-" + 
vm.getId()));
+          reference.set(closeable.get());
         });
       }
     }
 
     @Test
     public void hasCloseableInEachVm() {
-      for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
         vm.invoke(() -> {
-          assertThat(reference.get()).isSameAs(closeable);
+          assertThat(reference.get()).isSameAs(closeable.get());
           assertThat(reference.get().toString()).isEqualTo("Closeable in VM-" 
+ vm.getId());
         });
       }
@@ -374,69 +382,72 @@ public class DistributedReferenceTest {
 
   public static class SetWithCloseInLocalVm implements Serializable {
 
-    private static WithClose withClose;
+    private static final AtomicReference<WithClose> withClose = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<WithClose> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<WithClose> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
-      withClose = spy(new WithClose());
-      reference.set(withClose);
+      withClose.set(spy(new WithClose()));
+      reference.set(withClose.get());
     }
 
     @Test
     public void hasWithCloseInLocalVm() {
-      assertThat(reference.get()).isSameAs(withClose);
+      assertThat(reference.get()).isSameAs(withClose.get());
     }
   }
 
   public static class SetWithCloseInRemoteVm implements Serializable {
 
-    private static WithClose withClose;
+    private static final AtomicReference<WithClose> withClose = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<WithClose> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<WithClose> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
       VM vm = getVM(0);
       vm.invoke(() -> {
-        withClose = spy(new WithClose("WithClose in VM-" + vm.getId()));
-        reference.set(withClose);
+        withClose.set(spy(new WithClose("WithClose in VM-" + vm.getId())));
+        reference.set(withClose.get());
       });
     }
 
     @Test
     public void hasWithCloseInRemoteVm() {
       getVM(0).invoke(() -> {
-        assertThat(reference.get()).isSameAs(withClose);
+        assertThat(reference.get()).isSameAs(withClose.get());
       });
     }
   }
 
   public static class SetWithCloseInEachVm implements Serializable {
 
-    private static WithClose withClose;
+    private static final AtomicReference<WithClose> withClose = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<WithClose> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<WithClose> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
-      for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
         vm.invoke(() -> {
-          withClose = spy(new WithClose("WithClose in VM-" + vm.getId()));
-          reference.set(withClose);
+          withClose.set(spy(new WithClose("WithClose in VM-" + vm.getId())));
+          reference.set(withClose.get());
         });
       }
     }
 
     @Test
     public void hasCloseableInEachVm() {
-      for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
         vm.invoke(() -> {
-          assertThat(reference.get()).isSameAs(withClose);
+          assertThat(reference.get()).isSameAs(withClose.get());
           assertThat(reference.get().toString()).isEqualTo("WithClose in VM-" 
+ vm.getId());
         });
       }
@@ -445,69 +456,72 @@ public class DistributedReferenceTest {
 
   public static class SetWithDisconnectInLocalVm implements Serializable {
 
-    private static WithDisconnect withDisconnect;
+    private static final AtomicReference<WithDisconnect> withDisconnect = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<WithDisconnect> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<WithDisconnect> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
-      withDisconnect = spy(new WithDisconnect());
-      reference.set(withDisconnect);
+      withDisconnect.set(spy(new WithDisconnect()));
+      reference.set(withDisconnect.get());
     }
 
     @Test
     public void hasWithDisconnectInLocalVm() {
-      assertThat(reference.get()).isSameAs(withDisconnect);
+      assertThat(reference.get()).isSameAs(withDisconnect.get());
     }
   }
 
   public static class SetWithDisconnectInRemoteVm implements Serializable {
 
-    private static WithDisconnect withDisconnect;
+    private static final AtomicReference<WithDisconnect> withDisconnect = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<WithDisconnect> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<WithDisconnect> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
       VM vm = getVM(0);
       vm.invoke(() -> {
-        withDisconnect = spy(new WithDisconnect("WithDisconnect in VM-" + 
vm.getId()));
-        reference.set(withDisconnect);
+        withDisconnect.set(spy(new WithDisconnect("WithDisconnect in VM-" + 
vm.getId())));
+        reference.set(withDisconnect.get());
       });
     }
 
     @Test
     public void hasWithDisconnectInRemoteVm() {
       getVM(0).invoke(() -> {
-        assertThat(reference.get()).isSameAs(withDisconnect);
+        assertThat(reference.get()).isSameAs(withDisconnect.get());
       });
     }
   }
 
   public static class SetWithDisconnectInEachVm implements Serializable {
 
-    private static WithDisconnect withDisconnect;
+    private static final AtomicReference<WithDisconnect> withDisconnect = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<WithDisconnect> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<WithDisconnect> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
-      for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
         vm.invoke(() -> {
-          withDisconnect = spy(new WithDisconnect("WithDisconnect in VM-" + 
vm.getId()));
-          reference.set(withDisconnect);
+          withDisconnect.set(spy(new WithDisconnect("WithDisconnect in VM-" + 
vm.getId())));
+          reference.set(withDisconnect.get());
         });
       }
     }
 
     @Test
     public void hasWithDisconnectInEachVm() {
-      for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
         vm.invoke(() -> {
-          assertThat(reference.get()).isSameAs(withDisconnect);
+          assertThat(reference.get()).isSameAs(withDisconnect.get());
           assertThat(reference.get().toString()).isEqualTo("WithDisconnect in 
VM-" + vm.getId());
         });
       }
@@ -516,67 +530,70 @@ public class DistributedReferenceTest {
 
   public static class SetWithStopInLocalVm implements Serializable {
 
-    private static WithStop withStop;
+    private static final AtomicReference<WithStop> withStop = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<WithStop> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<WithStop> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
-      withStop = spy(new WithStop());
-      reference.set(withStop);
+      withStop.set(spy(new WithStop()));
+      reference.set(withStop.get());
     }
 
     @Test
     public void hasWithStopInLocalVm() {
-      assertThat(reference.get()).isSameAs(withStop);
+      assertThat(reference.get()).isSameAs(withStop.get());
     }
   }
 
   public static class SetWithStopInRemoteVm implements Serializable {
 
-    private static WithStop withStop;
+    private static final AtomicReference<WithStop> withStop = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<WithStop> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<WithStop> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
       VM vm = getVM(0);
       vm.invoke(() -> {
-        withStop = spy(new WithStop("WithStop in VM-" + vm.getId()));
-        reference.set(withStop);
+        withStop.set(spy(new WithStop("WithStop in VM-" + vm.getId())));
+        reference.set(withStop.get());
       });
     }
 
     @Test
     public void hasWithStopInRemoteVm() {
       getVM(0).invoke(() -> {
-        assertThat(reference.get()).isSameAs(withStop);
+        assertThat(reference.get()).isSameAs(withStop.get());
       });
     }
   }
 
   public static class SetWithStopInEachVm implements Serializable {
 
-    private static WithStop withStop;
+    private static final AtomicReference<WithStop> withStop = new 
AtomicReference<>();
 
     @Rule
-    public DistributedReference<WithStop> reference = new 
DistributedReference<>();
+    public DistributedCloseableReference<WithStop> reference =
+        new DistributedCloseableReference<>();
 
     @Before
     public void setUp() {
-      for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
         vm.invoke(() -> {
-          withStop = spy(new WithStop("WithStop in VM-" + vm.getId()));
-          reference.set(withStop);
+          withStop.set(spy(new WithStop("WithStop in VM-" + vm.getId())));
+          reference.set(withStop.get());
         });
       }
     }
 
     @Test
     public void hasWithStopInEachVm() {
-      for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
         vm.invoke(() -> {
           assertThat(reference.get()).isSameAs(withStop);
           assertThat(reference.get().toString()).isEqualTo("WithStop in VM-" + 
vm.getId());
@@ -585,6 +602,7 @@ public class DistributedReferenceTest {
     }
   }
 
+  @SuppressWarnings("WeakerAccess")
   public static class WithClose {
 
     private final String value;
@@ -607,6 +625,7 @@ public class DistributedReferenceTest {
     }
   }
 
+  @SuppressWarnings("WeakerAccess")
   public static class WithDisconnect {
 
     private final String value;
@@ -629,6 +648,7 @@ public class DistributedReferenceTest {
     }
   }
 
+  @SuppressWarnings("unused")
   public static class WithStop {
 
     private final String value;
diff --git 
a/geode-dunit/src/main/java/org/apache/geode/test/dunit/DistributedTestUtils.java
 
b/geode-dunit/src/main/java/org/apache/geode/test/dunit/DistributedTestUtils.java
index 087d25e..4c6b31e 100755
--- 
a/geode-dunit/src/main/java/org/apache/geode/test/dunit/DistributedTestUtils.java
+++ 
b/geode-dunit/src/main/java/org/apache/geode/test/dunit/DistributedTestUtils.java
@@ -15,33 +15,31 @@
 package org.apache.geode.test.dunit;
 
 import static 
org.apache.geode.distributed.ConfigurationProperties.DISABLE_AUTO_RECONNECT;
-import static org.apache.geode.test.dunit.VM.getHostName;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.File;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
 
-import org.apache.geode.distributed.ConfigurationProperties;
 import org.apache.geode.distributed.DistributedSystem;
 import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import 
org.apache.geode.distributed.internal.membership.api.MembershipManagerHelper;
 import org.apache.geode.internal.InternalDataSerializer;
 import org.apache.geode.internal.InternalInstantiator;
+import org.apache.geode.test.dunit.rules.DistributedRule;
 
 /**
  * {@code DistributedTestUtils} provides static utility methods that affect 
the runtime environment
  * or artifacts generated by a DistributedTest.
  *
  * <p>
- * These methods can be used directly: {@code 
DistributedTestUtils.forceDisconnect(...)},
+ * These methods can be used directly: {@code 
DistributedTestUtils.crashDistributedSystem(...)},
  * however, they are intended to be referenced through static import:
  *
  * <pre>
- * import static org.apache.geode.test.dunit.DistributedTestUtils.*;
+ * import static 
org.apache.geode.test.dunit.DistributedTestUtils.crashDistributedSystem;
  *    ...
- *    forceDisconnect(...);
+ *    crashDistributedSystem(...);
  * </pre>
  *
  * Extracted from DistributedTestCase.
@@ -53,25 +51,6 @@ public class DistributedTestUtils {
   }
 
   /**
-   * Fetches the GemFireDescription for this test and adds its 
DistributedSystem properties to the
-   * provided props parameter.
-   *
-   * @param properties the properties to add hydra's test properties to
-   */
-  public static void addHydraProperties(final Properties properties) {
-    Properties dsProperties = DUnitEnv.get().getDistributedSystemProperties();
-    for (Iterator<Map.Entry<Object, Object>> iter = 
dsProperties.entrySet().iterator(); iter
-        .hasNext();) {
-      Map.Entry<Object, Object> entry = iter.next();
-      String key = (String) entry.getKey();
-      String value = (String) entry.getValue();
-      if (properties.getProperty(key) == null) {
-        properties.setProperty(key, value);
-      }
-    }
-  }
-
-  /**
    * Crash the cache in the given VM in such a way that it immediately stops 
communicating with
    * peers. This forces the VM's membership manager to throw a 
ForcedDisconnectException by forcibly
    * terminating the JGroups protocol stack with a fake EXIT event.
@@ -107,8 +86,8 @@ public class DistributedTestUtils {
    * state file isn't picked up by the new locator you're starting.
    */
   public static void deleteLocatorStateFile(final int... ports) {
-    for (int index = 0; index < ports.length; index++) {
-      File stateFile = new File("locator" + ports[index] + "view.dat");
+    for (int port : ports) {
+      File stateFile = new File("locator" + port + "view.dat");
       if (stateFile.exists()) {
         stateFile.delete();
       }
@@ -120,7 +99,7 @@ public class DistributedTestUtils {
 
     // our tests do not expect auto-reconnect to be on by default
     if (!dsProperties.contains(DISABLE_AUTO_RECONNECT)) {
-      dsProperties.put(DISABLE_AUTO_RECONNECT, "true");
+      dsProperties.setProperty(DISABLE_AUTO_RECONNECT, "true");
     }
 
     for (Map.Entry<Object, Object> entry : properties.entrySet()) {
@@ -133,46 +112,46 @@ public class DistributedTestUtils {
   }
 
   /**
-   * Returns the port that the standard dunit locator is listening on.
-   *
-   * @deprecated Please use {@link #getLocatorPort()} instead.
+   * @deprecated Please use {@link DistributedRule#getLocatorPort()} instead.
    */
   @Deprecated
   public static int getDUnitLocatorPort() {
-    return getLocatorPort();
+    return DistributedRule.getLocatorPort();
   }
 
   /**
-   * Returns the port that the standard dunit locator is listening on.
+   * @deprecated Please use {@link DistributedRule#getLocatorPort()} instead.
    */
+  @Deprecated
   public static int getLocatorPort() {
-    return DUnitEnv.get().getLocatorPort();
+    return DistributedRule.getLocatorPort();
   }
 
   /**
-   * Returns a {@link ConfigurationProperties#LOCATORS} string for the 
standard dunit locator.
+   * @deprecated Please use {@link DistributedRule#getLocators()} instead.
    */
+  @Deprecated
   public static String getLocators() {
-    return getHostName() + "[" + getLocatorPort() + "]";
+    return DistributedRule.getLocators();
   }
 
   public static void unregisterAllDataSerializersFromAllVms() {
-    DistributedTestUtils.unregisterDataSerializerInThisVM();
+    unregisterDataSerializerInThisVM();
     Invoke.invokeInEveryVM(() -> unregisterDataSerializerInThisVM());
     Invoke.invokeInLocator(() -> unregisterDataSerializerInThisVM());
   }
 
-  public static void unregisterDataSerializerInThisVM() {
+  public static void unregisterInstantiatorsInThisVM() {
+    // unregister all the instantiators
+    InternalInstantiator.reinitialize();
+    assertThat(InternalInstantiator.getInstantiators()).isEmpty();
+  }
+
+  private static void unregisterDataSerializerInThisVM() {
     // TODO: delete 
DataSerializerPropogationDUnitTest.successfullyLoadedTestDataSerializer = false;
     // unregister all the Dataserializers
     InternalDataSerializer.reinitialize();
     // ensure that all are unregistered
-    assertEquals(0, InternalDataSerializer.getSerializers().length);
-  }
-
-  public static void unregisterInstantiatorsInThisVM() {
-    // unregister all the instantiators
-    InternalInstantiator.reinitialize();
-    assertEquals(0, InternalInstantiator.getInstantiators().length);
+    assertThat(InternalDataSerializer.getSerializers()).isEmpty();
   }
 }
diff --git 
a/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedReference.java
 
b/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedCloseableReference.java
similarity index 58%
rename from 
geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedReference.java
rename to 
geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedCloseableReference.java
index 3f2f9bb..600a9f4 100644
--- 
a/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedReference.java
+++ 
b/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedCloseableReference.java
@@ -17,6 +17,7 @@
 package org.apache.geode.test.dunit.rules;
 
 import static org.apache.geode.test.dunit.VM.DEFAULT_VM_COUNT;
+import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -25,31 +26,68 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 /**
- * JUnit Rule that provides a static reference in every distributed test 
{@code VM}s including the
- * main JUnit controller {@code VM}. If the referenced value is an {@code 
AutoCloseable} or
- * {@code Closeable} then it will be auto-closed in every {@code VM} during 
tear down.
+ * DistributedCloseableReference is a JUnit Rule that provides automated 
tearDown for a static
+ * reference in every distributed test {@code VM}s including the main JUnit 
controller {@code VM}.
+ * If the referenced value is an {@code AutoCloseable} or {@code Closeable} 
then it will be
+ * auto-closed and set to null in every {@code VM} during tear down.
  *
  * <p>
  * If the referenced value is not an {@code AutoCloseable} or {@code 
Closeable}, the
- * {@code DistributedReference} will use reflection to invoke any method named 
{@code close} or
- * {@code disconnect} regardless of what interfaces are implemented.
+ * {@code DistributedCloseableReference} will use reflection to invoke any 
method named
+ * {@code close}, {@code disconnect}, or {@code stop} regardless of what 
interfaces are implemented
+ * unless {@code autoClose} is set to false.
  *
  * <p>
  * If the referenced value is null in any {@code VM} then it will be ignored 
in that {@code VM}
  * during tear down.
  *
  * <p>
- * In the following example, every {@code VM} has a {@code Cache} which will 
be auto-closed during
- * tear down:
+ * In the following example, every {@code VM} has a {@code ServerLauncher} 
which will be
+ * auto-stopped and set to null during tear down:
  *
  * <pre>
  * {@literal @}Rule
- * public DistributedReference&lt;Cache&gt; cache = new 
DistributedReference&lt;&gt;();
+ * public DistributedCloseableReference&lt;ServerLauncher&gt; server = new 
DistributedCloseableReference&lt;&gt;();
+ *
+ * {@literal @}Before
+ * public void setUp() throws IOException {
+ *   Properties configProperties = new Properties();
+ *   configProperties.setProperty(LOCATORS, DistributedRule.getLocators());
+ *
+ *   for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+ *     vm.invoke(() -> {
+ *       server.set(new ServerLauncher.Builder()
+ *           .setMemberName("server" + getVMId())
+ *           .setDisableDefaultServer(true)
+ *           .setWorkingDirectory(temporaryFolder.newFolder("server" + 
getVMId()).getAbsolutePath())
+ *           .build());
+ *
+ *       server.get().start();
+ *     });
+ *   }
+ * }
+ *
+ * {@literal @}Test
+ * public void eachVmHasItsOwnServerCache() {
+ *   for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+ *     vm.invoke(() -> {
+ *       assertThat(server.get().getCache()).isNotNull();
+ *     });
+ * }
+ * </pre>
+ *
+ * <p>
+ * In the following example, every {@code VM} has a {@code Cache} which will 
be auto-closed and set
+ * to null during tear down:
+ *
+ * <pre>
+ * {@literal @}Rule
+ * public DistributedCloseableReference&lt;Cache&gt; cache = new 
DistributedCloseableReference&lt;&gt;();
  *
  * {@literal @}Before
  * public void setUp() {
  *   Properties configProperties = new Properties();
- *   configProperties.setProperty(LOCATORS, 
DistributedTestUtils.getLocators());
+ *   configProperties.setProperty(LOCATORS, DistributedRule.getLocators());
  *
  *   for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
  *     vm.invoke(() -> {
@@ -62,7 +100,7 @@ import java.util.concurrent.atomic.AtomicReference;
  * public void eachVmHasItsOwnCache() {
  *   for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
  *     vm.invoke(() -> {
- *       assertThat(cache.get()).isInstanceOf(Cache.class);
+ *       assertThat(cache.get()).isNotNull();
  *     });
  *   }
  * }
@@ -70,16 +108,16 @@ import java.util.concurrent.atomic.AtomicReference;
  *
  * <p>
  * In the following example, every {@code VM} has a {@code DistributedSystem} 
which will be
- * auto-disconnected during tear down:
+ * auto-disconnected and set to null during tear down:
  *
  * <pre>
  * {@literal @}Rule
- * public DistributedReference&lt;DistributedSystem&gt; system = new 
DistributedReference&lt;&gt;();
+ * public DistributedCloseableReference&lt;DistributedSystem&gt; system = new 
DistributedCloseableReference&lt;&gt;();
  *
  * {@literal @}Before
  * public void setUp() {
  *   Properties configProperties = new Properties();
- *   configProperties.setProperty(LOCATORS, 
DistributedTestUtils.getLocators());
+ *   configProperties.setProperty(LOCATORS, DistributedRule.getLocators());
  *
  *   for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
  *     vm.invoke(() -> {
@@ -89,43 +127,47 @@ import java.util.concurrent.atomic.AtomicReference;
  * }
  *
  * {@literal @}Test
- * public void eachVmHasItsOwnSystemConnection() {
+ * public void eachVmHasItsOwnDistributedSystemConnection() {
  *   for (VM vm : toArray(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
  *     vm.invoke(() -> {
- *       assertThat(system.get()).isInstanceOf(DistributedSystem.class);
+ *       assertThat(system.get()).isNotNull();
  *     });
  *   }
  * }
  * </pre>
  *
  * <p>
- * To disable autoClose in a test, specify {@code autoClose(false)}:
+ * To disable auto-closing in a test, specify {@code autoClose(false)}:
  *
  * <pre>
  * {@literal @}Rule
- * public DistributedReference&lt;DistributedSystem&gt; system =
- *     new DistributedReference&lt;&gt;().autoClose(false);
+ * public DistributedCloseableReference&lt;ServerLauncher&gt; serverLauncher =
+ *     new DistributedCloseableReference&lt;&gt;().autoClose(false);
  * </pre>
+ *
+ * <p>
+ * The {@code DistributedCloseableReference} value will still be set to null 
during tear down even
+ * if auto-closing is disabled.
  */
-@SuppressWarnings({"serial", "unused"})
-public class DistributedReference<V> extends AbstractDistributedRule {
+@SuppressWarnings({"serial", "unused", "WeakerAccess"})
+public class DistributedCloseableReference<V> extends AbstractDistributedRule {
 
-  private static final AtomicReference<Object> reference = new 
AtomicReference<>();
+  private static final AtomicReference<Object> REFERENCE = new 
AtomicReference<>();
 
   private final AtomicBoolean autoClose = new AtomicBoolean(true);
 
-  public DistributedReference() {
+  public DistributedCloseableReference() {
     this(DEFAULT_VM_COUNT);
   }
 
-  public DistributedReference(int vmCount) {
+  public DistributedCloseableReference(int vmCount) {
     super(vmCount);
   }
 
   /**
    * Set false to disable autoClose during tearDown. Default is true.
    */
-  public DistributedReference<V> autoClose(boolean value) {
+  public DistributedCloseableReference<V> autoClose(boolean value) {
     autoClose.set(value);
     return this;
   }
@@ -135,9 +177,8 @@ public class DistributedReference<V> extends 
AbstractDistributedRule {
    *
    * @return the current value
    */
-  @SuppressWarnings("unchecked")
   public V get() {
-    return (V) reference.get();
+    return uncheckedCast(REFERENCE.get());
   }
 
   /**
@@ -145,8 +186,9 @@ public class DistributedReference<V> extends 
AbstractDistributedRule {
    *
    * @param newValue the new value
    */
-  public void set(V newValue) {
-    reference.set(newValue);
+  public DistributedCloseableReference<V> set(V newValue) {
+    REFERENCE.set(newValue);
+    return this;
   }
 
   @Override
@@ -159,7 +201,7 @@ public class DistributedReference<V> extends 
AbstractDistributedRule {
     if (value == null) {
       return;
     }
-    reference.set(null);
+    REFERENCE.set(null);
 
     if (autoClose.get()) {
       autoClose(value);
diff --git 
a/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedRule.java
 
b/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedRule.java
index 84872dc..cc46fd9 100644
--- 
a/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedRule.java
+++ 
b/geode-dunit/src/main/java/org/apache/geode/test/dunit/rules/DistributedRule.java
@@ -40,7 +40,7 @@ import org.apache.geode.internal.net.SocketCreator;
 import org.apache.geode.internal.net.SocketCreatorFactory;
 import org.apache.geode.management.internal.cli.LogWrapper;
 import org.apache.geode.pdx.internal.TypeRegistry;
-import org.apache.geode.test.dunit.DistributedTestUtils;
+import org.apache.geode.test.dunit.DUnitEnv;
 import org.apache.geode.test.dunit.IgnoredException;
 import org.apache.geode.test.dunit.internal.DUnitLauncher;
 import 
org.apache.geode.test.junit.rules.serializable.SerializableExternalResource;
@@ -114,7 +114,7 @@ import org.apache.geode.util.internal.GeodeGlossary;
  * }
  * </pre>
  */
-@SuppressWarnings("unused")
+@SuppressWarnings({"serial", "unused"})
 public class DistributedRule extends AbstractDistributedRule {
 
   /**
@@ -154,7 +154,11 @@ public class DistributedRule extends 
AbstractDistributedRule {
   }
 
   public static int getLocatorPort() {
-    return DistributedTestUtils.getLocatorPort();
+    return DUnitEnv.get().getLocatorPort();
+  }
+
+  public static String getLocators() {
+    return "localhost[" + getLocatorPort() + "]";
   }
 
   /**
@@ -201,6 +205,7 @@ public class DistributedRule extends 
AbstractDistributedRule {
    * <p>
    * Note: {@link CacheRule} handles its own cleanup of Cache and Regions.
    */
+  @SuppressWarnings("serial")
   public static class TearDown extends SerializableExternalResource {
 
     @Override
@@ -213,7 +218,7 @@ public class DistributedRule extends 
AbstractDistributedRule {
       doTearDown();
     }
 
-    static void doTearDown() {
+    private static void doTearDown() {
       tearDownInVM();
       invokeInEveryVM(() -> {
         tearDownInVM();
diff --git 
a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/CloseableReference.java
 
b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/CloseableReference.java
index 8a2b015..6c6d972 100644
--- 
a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/CloseableReference.java
+++ 
b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/CloseableReference.java
@@ -25,14 +25,15 @@ import java.util.concurrent.atomic.AtomicReference;
 import 
org.apache.geode.test.junit.rules.serializable.SerializableExternalResource;
 
 /**
- * JUnit Rule that provides automated tearDown for an atomic reference. If the 
referenced value is
- * an {@code AutoCloseable} or {@code Closeable} then it will be auto-closed 
and set to null during
- * tear down.
+ * CloseableReference is a JUnit Rule that provides automated tearDown for an 
atomic reference. If
+ * the referenced value is an {@code AutoCloseable} or {@code Closeable} then 
it will be auto-closed
+ * and set to null during tear down.
  *
  * <p>
  * If the referenced value is not an {@code AutoCloseable} or {@code 
Closeable}, the
- * {@code CloseableReference} will use reflection to invoke any method named 
{@code close} or
- * {@code disconnect} regardless of what interfaces are implemented.
+ * {@code CloseableReference} will use reflection to invoke any method named 
{@code close},
+ * {@code disconnect}, or {@code stop} regardless of what interfaces are 
implemented unless
+ * {@code autoClose} is set to false.
  *
  * <p>
  * If the referenced value is null then it will be ignored during tear down.
@@ -101,7 +102,7 @@ import 
org.apache.geode.test.junit.rules.serializable.SerializableExternalResour
  * </pre>
  *
  * <p>
- * To disable autoClose in a test, specify {@code autoClose(false)}:
+ * To disable auto-closing in a test, specify {@code autoClose(false)}:
  *
  * <pre>
  * {@literal @}Rule
@@ -110,8 +111,8 @@ import 
org.apache.geode.test.junit.rules.serializable.SerializableExternalResour
  * </pre>
  *
  * <p>
- * The CloseableReference value will still be set to null during tear down 
even if autoClose is set
- * to false.
+ * The {@code CloseableReference} value will still be set to null during tear 
down even if
+ * auto-closing is disabled.
  */
 @SuppressWarnings({"serial", "WeakerAccess"})
 public class CloseableReference<V> extends SerializableExternalResource {

Reply via email to