GEODE-1931: Refactored tests to use Awaitility and lambdas instead of 
Wait.pause and WaitCriterion


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/f0e5159c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/f0e5159c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/f0e5159c

Branch: refs/heads/feature/GEODE-2156
Commit: f0e5159c2cd3b00a3d5e43e2e9b58ca8b430adea
Parents: ef7bb32
Author: Udo Kohlmeyer <ukohlme...@pivotal.io>
Authored: Wed Nov 30 09:52:58 2016 -0800
Committer: Udo Kohlmeyer <ukohlme...@pivotal.io>
Committed: Wed Nov 30 15:31:59 2016 -0800

----------------------------------------------------------------------
 .../geode/distributed/LocatorDUnitTest.java     | 810 ++++++++-----------
 .../LocatorUDPSecurityDUnitTest.java            |  49 +-
 2 files changed, 338 insertions(+), 521 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f0e5159c/geode-core/src/test/java/org/apache/geode/distributed/LocatorDUnitTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/distributed/LocatorDUnitTest.java 
b/geode-core/src/test/java/org/apache/geode/distributed/LocatorDUnitTest.java
index 10c9238..3b8c406 100644
--- 
a/geode-core/src/test/java/org/apache/geode/distributed/LocatorDUnitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/distributed/LocatorDUnitTest.java
@@ -14,19 +14,36 @@
  */
 package org.apache.geode.distributed;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
+import static 
org.apache.geode.distributed.ConfigurationProperties.DISABLE_AUTO_RECONNECT;
+import static 
org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static 
org.apache.geode.distributed.ConfigurationProperties.ENABLE_NETWORK_PARTITION_DETECTION;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_TTL;
+import static 
org.apache.geode.distributed.ConfigurationProperties.MEMBER_TIMEOUT;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SECURITY_PEER_AUTHENTICATOR;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SECURITY_PEER_AUTH_INIT;
+import static org.apache.geode.distributed.ConfigurationProperties.SSL_CIPHERS;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SSL_ENABLED_COMPONENTS;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_PASSWORD;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_TYPE;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SSL_LOCATOR_ALIAS;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SSL_PROTOCOLS;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SSL_REQUIRE_AUTHENTICATION;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE_PASSWORD;
+import static 
org.apache.geode.distributed.ConfigurationProperties.START_LOCATOR;
+import static 
org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.jayway.awaitility.Awaitility;
 import org.apache.geode.ForcedDisconnectException;
 import org.apache.geode.GemFireConfigException;
 import org.apache.geode.LogWriter;
@@ -35,7 +52,6 @@ import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.distributed.internal.DistributionConfig;
 import org.apache.geode.distributed.internal.DistributionException;
 import org.apache.geode.distributed.internal.DistributionManager;
 import org.apache.geode.distributed.internal.InternalDistributedSystem;
@@ -63,10 +79,21 @@ import org.apache.geode.test.dunit.NetworkUtils;
 import org.apache.geode.test.dunit.SerializableRunnable;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.dunit.Wait;
-import org.apache.geode.test.dunit.WaitCriterion;
 import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.junit.categories.*;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.FlakyTest;
+import org.apache.geode.test.junit.categories.MembershipTest;
 import org.apache.geode.util.test.TestUtil;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Tests the ability of the {@link Locator} API to start and stop locators 
running in remote VMs.
@@ -190,45 +217,23 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     service.becomeLockGrantor();
     service.lock("foo0", 0, 0);
 
-    vm1.invoke(new SerializableRunnable("get the lock service and lock 
something") {
-      public void run() {
-        final DistributedLockService service =
-            DistributedLockService.create("test service", system);
-        service.lock("foo1", 0, 0);
-      }
-    });
+    vm1.invoke("get the lock service and lock something",
+        () -> DistributedLockService.create("test service", 
system).lock("foo1", 0, 0));
 
-    vm2.invoke(new SerializableRunnable("get the lock service and lock 
something") {
-      public void run() {
-        final DistributedLockService service =
-            DistributedLockService.create("test service", system);
-        service.lock("foo2", 0, 0);
-      }
-    });
+    vm2.invoke("get the lock service and lock something",
+        () -> DistributedLockService.create("test service", 
system).lock("foo2", 0, 0));
 
     // cause elder failover. vm1 will become the lock grantor
     system.disconnect();
 
     try {
-      vm1.invoke(new SerializableRunnable("ensure grantor failover") {
-        public void run() {
-          final DistributedLockService service =
-              DistributedLockService.getServiceNamed("test service");
-          service.lock("foo3", 0, 0);
-          Wait.waitForCriterion(new WaitCriterion() {
-            @Override
-            public boolean done() {
-              return service.isLockGrantor();
-            }
-
-            @Override
-            public String description() {
-              return "waiting to become lock grantor after shutting down 
locator/grantor";
-            }
-
-          }, DistributionConfig.DEFAULT_MEMBER_TIMEOUT * 2, 1000, true);
-          assertTrue(service.isLockGrantor());
-        }
+      vm1.invoke("ensure grantor failover", () -> {
+        DistributedLockService serviceNamed =
+            DistributedLockService.getServiceNamed("test service");
+        serviceNamed.lock("foo3", 0, 0);
+        Awaitility.waitAtMost(10000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+            .until(() -> serviceNamed.isLockGrantor());
+        assertTrue(serviceNamed.isLockGrantor());
       });
 
       properties.put(START_LOCATOR, locators);
@@ -248,12 +253,8 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       service = DistributedLockService.create("test service", system);
 
       // now force a non-elder VM to get a lock. This will hang if the bug is 
not fixed
-      vm2.invoke(new SerializableRunnable("get the lock service and lock 
something") {
-        public void run() {
-          final DistributedLockService service =
-              DistributedLockService.getServiceNamed("test service");
-          service.lock("foo4", 0, 0);
-        }
+      vm2.invoke("get the lock service and lock something", () -> {
+        DistributedLockService.getServiceNamed("test service").lock("foo4", 0, 
0);
       });
 
       assertFalse("should not have become lock grantor", 
service.isLockGrantor());
@@ -261,13 +262,8 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       // Now demonstrate that a new member can join and use the lock service
       properties.remove(START_LOCATOR);
       vm3.invoke(startSystem);
-      vm3.invoke(new SerializableRunnable("get the lock service and lock 
something(2)") {
-        public void run() {
-          final DistributedLockService service =
-              DistributedLockService.create("test service", system);
-          service.lock("foo5", 0, 0);
-        }
-      });
+      vm3.invoke("get the lock service and lock something(2)",
+          () -> DistributedLockService.create("test service", 
system).lock("foo5", 0, 0));
 
     } finally {
       disconnectAllFromDS();
@@ -279,8 +275,6 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
    * split-brain configuration. To work around this we have always told 
customers that they need to
    * stagger the starting of locators. This test configures two locators to 
start up simultaneously
    * and shows that they find each other and form a single system.
-   * 
-   * @throws Exception
    */
   @Category(FlakyTest.class) // GEODE-1931
   @Test
@@ -308,19 +302,7 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
     properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
     addDSProps(properties);
-    try {
-      loc2.invoke("startLocator2", () -> 
startLocatorWithPortAndProperties(port2, properties));
-      loc1.invoke("startLocator1", () -> 
startLocatorWithPortAndProperties(port1, properties));
-    } finally {
-      try {
-        // verify that they found each other
-        loc2.invoke("verifyLocatorNotInSplitBrain", () -> 
verifyLocatorNotInSplitBrain(2));
-        loc1.invoke("verifyLocatorNotInSplitBrain", () -> 
verifyLocatorNotInSplitBrain(2));
-      } finally {
-        loc2.invoke("stop locator", () -> stopLocator());
-        loc1.invoke("stop locator", () -> stopLocator());
-      }
-    }
+    startVerifyAndStopLocator(loc1, loc2, port1, port2, properties);
   }
 
   private Boolean startLocatorWithPortAndProperties(final int port, final 
Properties properties)
@@ -384,19 +366,7 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     properties.put(SSL_TRUSTSTORE_PASSWORD, "password");
     properties.put(SSL_ENABLED_COMPONENTS, 
SecurableCommunicationChannel.LOCATOR.getConstant());
 
-    try {
-      loc2.invoke("startLocator2", () -> 
startLocatorWithPortAndProperties(port2, properties));
-      loc1.invoke("startLocator1", () -> 
startLocatorWithPortAndProperties(port1, properties));
-    } finally {
-      try {
-        // verify that they found each other
-        loc2.invoke("verifyLocatorNotInSplitBrain", () -> 
verifyLocatorNotInSplitBrain(2));
-        loc1.invoke("verifyLocatorNotInSplitBrain", () -> 
verifyLocatorNotInSplitBrain(2));
-      } finally {
-        loc2.invoke("stop locator", () -> stopLocator());
-        loc1.invoke("stop locator", () -> stopLocator());
-      }
-    }
+    startVerifyAndStopLocator(loc1, loc2, port1, port2, properties);
   }
 
   @Test
@@ -433,7 +403,11 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     properties.put(SSL_LOCATOR_ALIAS, "locatorkey");
     properties.put(SSL_ENABLED_COMPONENTS, 
SecurableCommunicationChannel.LOCATOR.getConstant());
 
+    startVerifyAndStopLocator(loc1, loc2, port1, port2, properties);
+  }
 
+  private void startVerifyAndStopLocator(VM loc1, VM loc2, int port1, int 
port2,
+      Properties properties) {
     try {
       loc2.invoke("startLocator2", () -> 
startLocatorWithPortAndProperties(port2, properties));
       loc1.invoke("startLocator1", () -> 
startLocatorWithPortAndProperties(port1, properties));
@@ -500,13 +474,6 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     }
   }
 
-  private void stopLocator() {
-    Locator loc = Locator.getLocator();
-    if (loc != null) {
-      loc.stop();
-    }
-  }
-
   @Test
   public void testStartTwoLocatorsOneWithNonSSLAndTheOtherSSL() throws 
Exception {
     IgnoredException.addIgnoredException("Remote host closed connection during 
handshake");
@@ -538,7 +505,6 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     properties.put(SSL_CIPHERS, "any");
     properties.put(SSL_PROTOCOLS, "any");
 
-
     try {
       loc1.invoke("start Locator1", () -> startLocator(port1, properties));
       loc1.invoke("verifyLocatorNotInSplitBrain", () -> 
verifyLocatorNotInSplitBrain(1));
@@ -691,7 +657,7 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       assertLeadMember(mem1, sys, 5000);
 
       // after disconnecting the first vm, the second one should become the 
leader
-      vm1.invoke(getDisconnectRunnable(locators));
+      vm1.invoke(() -> disconnectDistributedSystem());
       MembershipManagerHelper.getMembershipManager(sys).waitForDeparture(mem1);
       assertLeadMember(mem2, sys, 5000);
 
@@ -699,15 +665,15 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       mem1 = (DistributedMember) vm1.invoke(this.getClass(), 
"getDistributedMember", connectArgs);
       assertLeadMember(mem2, sys, 5000);
 
-      vm2.invoke(getDisconnectRunnable(locators));
+      vm2.invoke(() -> disconnectDistributedSystem());
       MembershipManagerHelper.getMembershipManager(sys).waitForDeparture(mem2);
       assertLeadMember(mem3, sys, 5000);
 
-      vm1.invoke(getDisconnectRunnable(locators));
+      vm1.invoke(() -> disconnectDistributedSystem());
       MembershipManagerHelper.getMembershipManager(sys).waitForDeparture(mem1);
       assertLeadMember(mem3, sys, 5000);
 
-      vm3.invoke(getDisconnectRunnable(locators));
+      vm3.invoke(() -> disconnectDistributedSystem());
       MembershipManagerHelper.getMembershipManager(sys).waitForDeparture(mem3);
       assertLeadMember(null, sys, 5000);
 
@@ -718,20 +684,14 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
 
   private void assertLeadMember(final DistributedMember member, final 
DistributedSystem sys,
       long timeout) {
-    WaitCriterion ev = new WaitCriterion() {
-      public boolean done() {
-        DistributedMember lead = MembershipManagerHelper.getLeadMember(sys);
-        if (member != null) {
-          return member.equals(lead);
-        }
-        return (lead == null);
-      }
-
-      public String description() {
-        return null;
-      }
-    };
-    Wait.waitForCriterion(ev, timeout, 200, true);
+    Awaitility.waitAtMost(timeout, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+        .until(() -> {
+          DistributedMember lead = MembershipManagerHelper.getLeadMember(sys);
+          if (member != null) {
+            return member.equals(lead);
+          }
+          return (lead == null);
+        });
   }
 
   /**
@@ -843,16 +803,12 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
 
       org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
           .info("waiting for my distributed system to disconnect due to 
partition detection");
-      WaitCriterion ev = new WaitCriterion() {
-        public boolean done() {
-          return !sys.isConnected();
-        }
 
-        public String description() {
-          return null;
-        }
-      };
-      Wait.waitForCriterion(ev, 12 * 2000, 200, true);
+      Awaitility.waitAtMost(24000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+          .until(() -> {
+            return !sys.isConnected();
+          });
+
       if (sys.isConnected()) {
         fail(
             "Distributed system did not disconnect as expected - network 
partition detection is broken");
@@ -912,7 +868,6 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
 
     addDSProps(properties);
-    SerializableRunnable stopLocator = getStopLocatorRunnable();
 
     try {
       final String uname = getUniqueName();
@@ -962,7 +917,8 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       // crash the lead vm. Should be okay
       vm1.invoke(crashSystem);
 
-      Wait.pause(4 * 2000); // 4 x the member-timeout
+      Awaitility.waitAtMost(4 * 2000, TimeUnit.MILLISECONDS)
+          .pollInterval(200, TimeUnit.MILLISECONDS).until(() -> 
isSystemConnected());
 
       assertTrue("Distributed system should not have disconnected", 
isSystemConnected());
 
@@ -1005,15 +961,15 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
 
       // disconnect the first vm and demonstrate that the third vm and the
       // locator notice the failure and exit
-      vm2.invoke(getDisconnectRunnable(locators));
-      locvm.invoke(stopLocator);
+      vm2.invoke(() -> disconnectDistributedSystem());
+      locvm.invoke(() -> stopLocator());
     } finally {
       MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
       if (locator != null) {
         locator.stop();
       }
       try {
-        locvm.invoke(stopLocator);
+        locvm.invoke(() -> stopLocator());
       } catch (Exception e) {
         org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
             .severe("failed to stop locator in vm 3", e);
@@ -1061,21 +1017,18 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
 
     addDSProps(properties);
-    SerializableRunnable stopLocator = getStopLocatorRunnable();
 
     try {
       final String uname = getUniqueName();
       File logFile = new File("");
       locator = Locator.startLocatorAndDS(port1, logFile, properties);
       DistributedSystem sys = locator.getDistributedSystem();
-      locvm.invoke(new SerializableRunnable() {
-        public void run() {
-          File lf = new File("");
-          try {
-            Locator.startLocatorAndDS(port2, lf, properties);
-          } catch (IOException ios) {
-            org.apache.geode.test.dunit.Assert.fail("Unable to start 
locator2", ios);
-          }
+      locvm.invoke(() -> {
+        File lf = new File("");
+        try {
+          Locator.startLocatorAndDS(port2, lf, properties);
+        } catch (IOException ios) {
+          org.apache.geode.test.dunit.Assert.fail("Unable to start locator2", 
ios);
         }
       });
 
@@ -1161,7 +1114,7 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       if (locator != null) {
         locator.stop();
       }
-      locvm.invoke(stopLocator);
+      locvm.invoke(() -> stopLocator());
       assertTrue("locator is not stopped", Locator.getLocators().isEmpty());
     }
   }
@@ -1199,30 +1152,14 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
 
     addDSProps(properties);
-    SerializableRunnable disconnect = new SerializableRunnable("Disconnect 
from " + locators) {
-      public void run() {
-        DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
-        if (sys != null && sys.isConnected()) {
-          sys.disconnect();
-        }
-        MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
-      }
-    };
-    SerializableRunnable expectedException = new SerializableRunnable("Add 
expected exceptions") {
-      public void run() {
-        MembershipManagerHelper.inhibitForcedDisconnectLogging(true);
-      }
-    };
     try {
       final String uname = getUniqueName();
-      locvm.invoke(new SerializableRunnable() {
-        public void run() {
-          File lf = new File("");
-          try {
-            Locator.startLocatorAndDS(port2, lf, properties);
-          } catch (IOException ios) {
-            org.apache.geode.test.dunit.Assert.fail("Unable to start 
locator1", ios);
-          }
+      locvm.invoke(() -> {
+        File lf = new File("");
+        try {
+          Locator.startLocatorAndDS(port2, lf, properties);
+        } catch (IOException ios) {
+          org.apache.geode.test.dunit.Assert.fail("Unable to start locator1", 
ios);
         }
       });
 
@@ -1233,39 +1170,38 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
           "<ExpectedException 
action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
       Object[] connectArgs = new Object[] {properties};
 
-      SerializableRunnable crashLocator = new SerializableRunnable("Crash 
locator") {
-        public void run() {
-          Locator loc = Locator.getLocators().iterator().next();
-          DistributedSystem msys = loc.getDistributedSystem();
-          msys.getLogWriter()
-              .info("<ExpectedException action=add>service 
failure</ExpectedException>");
-          msys.getLogWriter().info(
-              "<ExpectedException 
action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
-          msys.getLogWriter().info(
-              "<ExpectedException 
action=add>org.apache.geode.ConnectException</ExpectedException>");
-          MembershipManagerHelper.crashDistributedSystem(msys);
-          loc.stop();
-        }
-      };
-
       assertTrue(MembershipManagerHelper.getLeadMember(sys) == null);
 
       DistributedMember mem1 =
           (DistributedMember) vm1.invoke(this.getClass(), 
"getDistributedMember", connectArgs);
-      vm1.invoke(expectedException);
+
+      vm1.invoke(() -> 
MembershipManagerHelper.inhibitForcedDisconnectLogging(true));
+
       DistributedMember mem2 =
           (DistributedMember) vm2.invoke(this.getClass(), 
"getDistributedMember", connectArgs);
 
-      DistributedMember loc1Mbr =
-          (DistributedMember) locvm.invoke(() -> 
this.getLocatorDistributedMember());
+      DistributedMember loc1Mbr = locvm.invoke(() -> 
this.getLocatorDistributedMember());
 
       assertLeadMember(mem1, sys, 5000);
 
       assertEquals(loc1Mbr, MembershipManagerHelper.getCoordinator(sys));
 
       // crash the lead locator. Should be okay
-      locvm.invoke(crashLocator);
-      Wait.pause(10 * 1000);
+      locvm.invoke("crash locator", () -> {
+        Locator loc = Locator.getLocators().iterator().next();
+        DistributedSystem msys = loc.getDistributedSystem();
+        msys.getLogWriter()
+            .info("<ExpectedException action=add>service 
failure</ExpectedException>");
+        msys.getLogWriter().info(
+            "<ExpectedException 
action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
+        msys.getLogWriter().info(
+            "<ExpectedException 
action=add>org.apache.geode.ConnectException</ExpectedException>");
+        MembershipManagerHelper.crashDistributedSystem(msys);
+        loc.stop();
+      });
+
+      Awaitility.waitAtMost(10000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+          .until(() -> sys.isConnected());
 
       assertTrue("Distributed system should not have disconnected", 
sys.isConnected());
 
@@ -1277,8 +1213,10 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
 
       // disconnect the first vm and demonstrate that the non-lead vm and the
       // locator notice the failure and continue to run
-      vm1.invoke(disconnect);
-      Wait.pause(10 * 1000);
+      vm1.invoke(() -> disconnectDistributedSystem());
+
+      Awaitility.waitAtMost(10, TimeUnit.SECONDS).pollInterval(1000, 
TimeUnit.MILLISECONDS)
+          .until(() -> vm2.invoke(() -> LocatorDUnitTest.isSystemConnected()));
 
       assertTrue("Distributed system should not have disconnected",
           vm2.invoke(() -> LocatorDUnitTest.isSystemConnected()));
@@ -1287,12 +1225,12 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       assertEquals(mem2, MembershipManagerHelper.getLeadMember(sys));
 
     } finally {
-      vm2.invoke(disconnect);
+      vm2.invoke(() -> disconnectDistributedSystem());
 
       if (locator != null) {
         locator.stop();
       }
-      locvm.invoke(getStopLocatorRunnable());
+      locvm.invoke(() -> stopLocator());
     }
   }
 
@@ -1371,22 +1309,7 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     final String locators = NetworkUtils.getServerHostName(host) + "[" + port 
+ "]";
     final String uniqueName = getUniqueName();
 
-    vm0.invoke(new SerializableRunnable("Start locator " + locators) {
-      public void run() {
-        File logFile = new File("");
-        try {
-          Properties locProps = new Properties();
-          locProps.setProperty(MCAST_PORT, "0");
-          locProps.setProperty(MEMBER_TIMEOUT, "1000");
-          locProps.put(ENABLE_CLUSTER_CONFIGURATION, "false");
-
-          addDSProps(locProps);
-          Locator.startLocatorAndDS(port, logFile, locProps);
-        } catch (IOException ex) {
-          org.apache.geode.test.dunit.Assert.fail("While starting locator on 
port " + port, ex);
-        }
-      }
-    });
+    vm0.invoke("Start locator " + locators, () -> startLocator(port));
     try {
 
       SerializableRunnable connect = new SerializableRunnable("Connect to " + 
locators) {
@@ -1415,34 +1338,41 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
           .info("coordinator before termination of locator is " + coord);
 
-      vm0.invoke(getStopLocatorRunnable());
+      vm0.invoke(() -> stopLocator());
 
       // now ensure that one of the remaining members became the coordinator
-      WaitCriterion ev = new WaitCriterion() {
-        public boolean done() {
-          return !coord.equals(MembershipManagerHelper.getCoordinator(system));
-        }
 
-        public String description() {
-          return "expected the coordinator to not be " + coord + " but it is "
-              + MembershipManagerHelper.getCoordinator(system);
-        }
-      };
-      Wait.waitForCriterion(ev, 15 * 1000, 200, false);
+      Awaitility.waitAtMost(15000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+          .until(() -> 
!coord.equals(MembershipManagerHelper.getCoordinator(system)));
+
       DistributedMember newCoord = 
MembershipManagerHelper.getCoordinator(system);
-      org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
-          .info("coordinator after shutdown of locator was " + newCoord);
+      LogWriterUtils.getLogWriter().info("coordinator after shutdown of 
locator was " + newCoord);
       if (coord.equals(newCoord)) {
         fail("another member should have become coordinator after the locator 
was stopped");
       }
 
       system.disconnect();
 
-      vm1.invoke(getDisconnectRunnable(locators));
-      vm2.invoke(getDisconnectRunnable(locators));
+      vm1.invoke(() -> disconnectDistributedSystem());
+      vm2.invoke(() -> disconnectDistributedSystem());
 
     } finally {
-      vm0.invoke(getStopLocatorRunnable());
+      vm0.invoke(() -> stopLocator());
+    }
+  }
+
+  protected void startLocator(int port) {
+    File logFile = new File("");
+    try {
+      Properties locProps = new Properties();
+      locProps.setProperty(MCAST_PORT, "0");
+      locProps.setProperty(MEMBER_TIMEOUT, "1000");
+      locProps.put(ENABLE_CLUSTER_CONFIGURATION, "false");
+
+      addDSProps(locProps);
+      Locator.startLocatorAndDS(port, logFile, locProps);
+    } catch (IOException ex) {
+      org.apache.geode.test.dunit.Assert.fail("While starting locator on port 
" + port, ex);
     }
   }
 
@@ -1469,7 +1399,7 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     DistributedTestUtils.deleteLocatorStateFile(port1);
     final String locators = NetworkUtils.getServerHostName(host) + "[" + port 
+ "]";
 
-    vm0.invoke(getStartSBLocatorRunnable(port, getUniqueName() + "1"));
+    vm0.invoke(getUniqueName() + 1, () -> getStartSBLocatorRunnable(port));
     try {
 
       final Properties props = new Properties();
@@ -1478,15 +1408,14 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       props.put(ENABLE_CLUSTER_CONFIGURATION, "false");
 
       addDSProps(props);
-      SerializableRunnable connect = new SerializableRunnable("Connect to " + 
locators) {
-        public void run() {
-          // System.setProperty("p2p.joinTimeout", "5000");
-          DistributedSystem sys = getSystem(props);
-          sys.getLogWriter().info(addExpected);
-        }
-      };
-      vm1.invoke(connect);
-      vm2.invoke(connect);
+      vm1.invoke(() -> {
+        DistributedSystem sys = getSystem(props);
+        sys.getLogWriter().info(addExpected);
+      });
+      vm2.invoke(() -> {
+        DistributedSystem sys = getSystem(props);
+        sys.getLogWriter().info(addExpected);
+      });
 
       system = (InternalDistributedSystem) getSystem(props);
 
@@ -1494,23 +1423,14 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
           .info("coordinator before termination of locator is " + coord);
 
-      vm0.invoke(getStopLocatorRunnable());
+      vm0.invoke(() -> stopLocator());
 
       // now ensure that one of the remaining members became the coordinator
-      WaitCriterion ev = new WaitCriterion() {
-        public boolean done() {
-          return !coord.equals(MembershipManagerHelper.getCoordinator(system));
-        }
+      Awaitility.waitAtMost(15000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+          .until(() -> 
!coord.equals(MembershipManagerHelper.getCoordinator(system)));
 
-        public String description() {
-          return "expected the coordinator to be " + coord + " but it is "
-              + MembershipManagerHelper.getCoordinator(system);
-        }
-      };
-      Wait.waitForCriterion(ev, 15000, 200, true);
       DistributedMember newCoord = 
MembershipManagerHelper.getCoordinator(system);
-      org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
-          .info("coordinator after shutdown of locator was " + newCoord);
+      LogWriterUtils.getLogWriter().info("coordinator after shutdown of 
locator was " + newCoord);
       if (newCoord == null || coord.equals(newCoord)) {
         fail("another member should have become coordinator after the locator 
was stopped: "
             + newCoord);
@@ -1519,19 +1439,12 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
       // restart the locator to demonstrate reconnection & make disconnects 
faster
       // it should also regain the role of coordinator, so we check to make 
sure
       // that the coordinator has changed
-      vm0.invoke(getStartSBLocatorRunnable(port, getUniqueName() + "2"));
+      vm0.invoke(getUniqueName() + "2", () -> getStartSBLocatorRunnable(port));
 
       final DistributedMember tempCoord = newCoord;
-      ev = new WaitCriterion() {
-        public boolean done() {
-          return 
!tempCoord.equals(MembershipManagerHelper.getCoordinator(system));
-        }
 
-        public String description() {
-          return null;
-        }
-      };
-      Wait.waitForCriterion(ev, 5000, 200, true);
+      Awaitility.waitAtMost(5000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+          .until(() -> 
!tempCoord.equals(MembershipManagerHelper.getCoordinator(system)));
 
       system.disconnect();
       LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, 
System.out);
@@ -1539,21 +1452,32 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
 
       SerializableRunnable disconnect = new SerializableRunnable("Disconnect 
from " + locators) {
         public void run() {
-          DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
-          if (sys != null && sys.isConnected()) {
-            sys.disconnect();
-          }
-          // connectExceptions occur during disconnect, so we need the
-          // expectedexception hint to be in effect until this point
-          LogWriter bLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, 
System.out);
-          bLogger.info(removeExpected);
+
         }
       };
-      vm1.invoke(disconnect);
-      vm2.invoke(disconnect);
-      vm0.invoke(getStopLocatorRunnable());
+      vm1.invoke(() -> {
+        DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
+        if (sys != null && sys.isConnected()) {
+          sys.disconnect();
+        }
+        // connectExceptions occur during disconnect, so we need the
+        // expectedexception hint to be in effect until this point
+        LogWriter bLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, 
System.out);
+        bLogger.info(removeExpected);
+      });
+      vm2.invoke(() -> {
+        DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
+        if (sys != null && sys.isConnected()) {
+          sys.disconnect();
+        }
+        // connectExceptions occur during disconnect, so we need the
+        // expectedexception hint to be in effect until this point
+        LogWriter bLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, 
System.out);
+        bLogger.info(removeExpected);
+      });
+      vm0.invoke(() -> stopLocator());
     } finally {
-      vm0.invoke(getStopLocatorRunnable());
+      vm0.invoke(() -> stopLocator());
     }
 
   }
@@ -1635,48 +1559,31 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
         addDSProps(props);
         system = (InternalDistributedSystem) DistributedSystem.connect(props);
 
-        WaitCriterion ev = new WaitCriterion() {
-          public boolean done() {
-            try {
-              return system.getDM().getViewMembers().size() >= 3;
-            } catch (Exception e) {
-              e.printStackTrace();
-              fail("unexpected exception");
-            }
-            return false; // NOTREACHED
-          }
-
-          public String description() {
-            return null;
-          }
-        };
-        Wait.waitForCriterion(ev, 10 * 1000, 200, true);
+        Awaitility.waitAtMost(10000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+            .until(() -> system.getDM().getViewMembers().size() >= 3);
 
         // three applications plus
         assertEquals(5, system.getDM().getViewMembers().size());
 
         system.disconnect();
 
-        vm1.invoke(getDisconnectRunnable(locators));
-        vm2.invoke(getDisconnectRunnable(locators));
+        vm1.invoke(() -> disconnectDistributedSystem());
+        vm2.invoke(() -> disconnectDistributedSystem());
 
       } finally {
-        vm3.invoke(getStopLocatorRunnable());
+        vm3.invoke(() -> stopLocator());
       }
     } finally {
-      vm0.invoke(getStopLocatorRunnable());
+      vm0.invoke(() -> stopLocator());
     }
   }
 
-  SerializableRunnable getDisconnectRunnable(final String locators) {
-    return new SerializableRunnable("Disconnect from " + locators) {
-      public void run() {
-        DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
-        if (sys != null && sys.isConnected()) {
-          sys.disconnect();
-        }
-      }
-    };
+  private void disconnectDistributedSystem() {
+    DistributedSystem sys = InternalDistributedSystem.getAnyInstance();
+    if (sys != null && sys.isConnected()) {
+      sys.disconnect();
+    }
+    MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
   }
 
   /**
@@ -1710,9 +1617,10 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     dsProps.setProperty(MCAST_PORT, "0");
 
     addDSProps(dsProps);
-    startLocatorSync(vm0, new Object[] {port1, dsProps});
-    startLocatorSync(vm1, new Object[] {port2, dsProps});
-    startLocatorSync(vm2, new Object[] {port3, dsProps});
+    vm0.invoke(() -> startLocatorAsync(new Object[] {port1, dsProps}));
+    vm1.invoke(() -> startLocatorAsync(new Object[] {port2, dsProps}));
+    vm2.invoke(() -> startLocatorAsync(new Object[] {port3, dsProps}));
+
     try {
       try {
         vm3.invoke(() -> {
@@ -1726,46 +1634,34 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
 
         system = (InternalDistributedSystem) 
DistributedSystem.connect(dsProps);
 
-        WaitCriterion waitCriterion = new WaitCriterion() {
-          public boolean done() {
-            try {
-              return system.getDM().getViewMembers().size() == 6;
-            } catch (Exception e) {
-              e.printStackTrace();
-              org.apache.geode.test.dunit.Assert.fail("unexpected exception", 
e);
-            }
-            return false; // NOTREACHED
-          }
-
-          public String description() {
-            return null;
-          }
-        };
-        Wait.waitForCriterion(waitCriterion, 10 * 1000, 200, true);
+        Awaitility.waitAtMost(10000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+            .until(() -> {
+              try {
+                return system.getDM().getViewMembers().size() == 6;
+              } catch (Exception e) {
+                e.printStackTrace();
+                org.apache.geode.test.dunit.Assert.fail("unexpected 
exception", e);
+              }
+              return false; // NOTREACHED
+            });
 
         // three applications plus
         assertEquals(6, system.getDM().getViewMembers().size());
 
-        vm0.invoke(getStopLocatorRunnable());
-        vm1.invoke(getStopLocatorRunnable());
-        vm2.invoke(getStopLocatorRunnable());
-
-        waitCriterion = new WaitCriterion() {
-          public boolean done() {
-            try {
-              return system.getDM().getMembershipManager().getView().size() <= 
3;
-            } catch (Exception e) {
-              e.printStackTrace();
-              org.apache.geode.test.dunit.Assert.fail("unexpected exception", 
e);
-            }
-            return false; // NOTREACHED
-          }
-
-          public String description() {
-            return null;
-          }
-        };
-        Wait.waitForCriterion(waitCriterion, 10 * 1000, 200, true);
+        vm0.invoke(() -> stopLocator());
+        vm1.invoke(() -> stopLocator());
+        vm2.invoke(() -> stopLocator());
+
+        Awaitility.waitAtMost(10000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+            .until(() -> {
+              try {
+                return system.getDM().getMembershipManager().getView().size() 
<= 3;
+              } catch (Exception e) {
+                e.printStackTrace();
+                org.apache.geode.test.dunit.Assert.fail("unexpected 
exception", e);
+              }
+              return false; // NOTREACHED
+            });
 
         final String newLocators = host0 + "[" + port2 + "]," + host0 + "[" + 
port3 + "]";
         dsProps.setProperty(LOCATORS, newLocators);
@@ -1778,34 +1674,33 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
             + " and vm3's ID is " + vm3ID,
             vm3.invoke(() -> GMSJoinLeaveTestHelper.isViewCreator()));
 
-        startLocatorAsync(vm1, new Object[] {port2, dsProps});
-        startLocatorAsync(vm2, new Object[] {port3, dsProps});
-
-        waitCriterion = new WaitCriterion() {
-          public boolean done() {
-            try {
-              InternalDistributedMember c = 
GMSJoinLeaveTestHelper.getCurrentCoordinator();
-              if (c.equals(currentCoordinator)) {
-                // now locator should be new coordinator
-                return false;
+        vm1.invoke(() -> startLocatorAsync(new Object[] {port2, dsProps}));
+        vm2.invoke(() -> startLocatorAsync(new Object[] {port3, dsProps}));
+
+        Awaitility.waitAtMost(30000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+            .until(() -> {
+              try {
+                InternalDistributedMember c = 
GMSJoinLeaveTestHelper.getCurrentCoordinator();
+                if (c.equals(currentCoordinator)) {
+                  // now locator should be new coordinator
+                  return false;
+                }
+                return system.getDM().getAllHostedLocators().size() == 2;
+              } catch (Exception e) {
+                e.printStackTrace();
+                org.apache.geode.test.dunit.Assert.fail("unexpected 
exception", e);
               }
-              return system.getDM().getAllHostedLocators().size() == 2;
-            } catch (Exception e) {
-              e.printStackTrace();
-              org.apache.geode.test.dunit.Assert.fail("unexpected exception", 
e);
-            }
-            return false; // NOTREACHED
-          }
-
-          public String description() {
-            return null;
-          }
-        };
-        Wait.waitForCriterion(waitCriterion, 30 * 1000, 1000, true);
-        waitUntilLocatorBecomesCoordinator(vm1);
-        waitUntilLocatorBecomesCoordinator(vm2);
-        waitUntilLocatorBecomesCoordinator(vm3);
-        waitUntilLocatorBecomesCoordinator(vm4);
+              return false; // NOTREACHED
+            });
+
+        vm1.invoke("waitUntilLocatorBecomesCoordinator",
+            () -> waitUntilLocatorBecomesCoordinator());
+        vm2.invoke("waitUntilLocatorBecomesCoordinator",
+            () -> waitUntilLocatorBecomesCoordinator());
+        vm3.invoke("waitUntilLocatorBecomesCoordinator",
+            () -> waitUntilLocatorBecomesCoordinator());
+        vm4.invoke("waitUntilLocatorBecomesCoordinator",
+            () -> waitUntilLocatorBecomesCoordinator());
 
         int netviewId =
             vm1.invoke("Checking ViewCreator", () -> 
GMSJoinLeaveTestHelper.getViewId());
@@ -1830,66 +1725,45 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
 
       } finally {
         system.disconnect();
-        vm3.invoke(getDisconnectRunnable(locators));
-        vm4.invoke(getDisconnectRunnable(locators));
-        vm2.invoke(getStopLocatorRunnable());
-        vm1.invoke(getStopLocatorRunnable());
+        vm3.invoke(() -> disconnectDistributedSystem());
+        vm4.invoke(() -> disconnectDistributedSystem());
+        vm2.invoke(() -> stopLocator());
+        vm1.invoke(() -> stopLocator());
       }
     } finally {
     }
   }
 
-  private void waitUntilLocatorBecomesCoordinator(VM vm) {
-    SerializableRunnable sr = new 
SerializableRunnable("waitUntilLocatorBecomesCoordinator") {
-
-      @Override
-      public void run() throws Exception {
-        final WaitCriterion waitCriterion = new WaitCriterion() {
-          public boolean done() {
-            try {
-              InternalDistributedMember c = 
GMSJoinLeaveTestHelper.getCurrentCoordinator();
-              return c.getVmKind() == DistributionManager.LOCATOR_DM_TYPE;
-            } catch (Exception e) {
-              e.printStackTrace();
-              org.apache.geode.test.dunit.Assert.fail("unexpected exception", 
e);
-            }
-            return false; // NOTREACHED
-          }
-
-          public String description() {
-            return null;
+  private void waitUntilLocatorBecomesCoordinator() {
+    Awaitility.waitAtMost(15000, TimeUnit.MILLISECONDS).pollInterval(200, 
TimeUnit.MILLISECONDS)
+        .until(() -> {
+          try {
+            InternalDistributedMember c = 
GMSJoinLeaveTestHelper.getCurrentCoordinator();
+            return c.getVmKind() == DistributionManager.LOCATOR_DM_TYPE;
+          } catch (Exception e) {
+            e.printStackTrace();
+            org.apache.geode.test.dunit.Assert.fail("unexpected exception", e);
           }
-        };
-        Wait.waitForCriterion(waitCriterion, 15 * 1000, 200, true);
-      }
-    };
-    vm.invoke(sr);
+          return false; // NOTREACHED
+        });
   }
 
-  private void startLocatorSync(VM vm, Object[] args) {
-    vm.invoke(new SerializableRunnable("Starting locator process on " + 
args[0], args) {
-      public void run() {
-        File logFile = new File("");
-        try {
-          Locator.startLocatorAndDS((int) args[0], logFile, (Properties) 
args[1]);
-        } catch (IOException ex) {
-          org.apache.geode.test.dunit.Assert.fail("While starting process on 
port " + args[0], ex);
-        }
-      }
-    });
+  private void startLocatorSync(Object[] args) {
+    File logFile = new File("");
+    try {
+      Locator.startLocatorAndDS((int) args[0], logFile, (Properties) args[1]);
+    } catch (IOException ex) {
+      org.apache.geode.test.dunit.Assert.fail("While starting process on port 
" + args[0], ex);
+    }
   }
 
-  private void startLocatorAsync(VM vm, Object[] args) {
-    vm.invokeAsync(new SerializableRunnable("Starting Locator process async on 
" + args[0], args) {
-      public void run() {
-        File logFile = new File("");
-        try {
-          Locator.startLocatorAndDS((int) args[0], logFile, (Properties) 
args[1]);
-        } catch (IOException ex) {
-          org.apache.geode.test.dunit.Assert.fail("While starting process on 
port " + args[0], ex);
-        }
-      }
-    });
+  private void startLocatorAsync(Object[] args) {
+    File logFile = new File("");
+    try {
+      Locator.startLocatorAndDS((int) args[0], logFile, (Properties) args[1]);
+    } catch (IOException ex) {
+      org.apache.geode.test.dunit.Assert.fail("While starting process on port 
" + args[0], ex);
+    }
   }
 
   /**
@@ -1899,8 +1773,8 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
   public void testMultipleMcastLocators() throws Exception {
     disconnectAllFromDS();
     IgnoredException.addIgnoredException("Could not stop  Distribution 
Locator"); // shutdown timing
-                                                                               
   // issue in
-                                                                               
   // InternalLocator
+    // issue in
+    // InternalLocator
     Host host = Host.getHost(0);
     VM vm0 = host.getVM(0);
     VM vm1 = host.getVM(1);
@@ -1938,8 +1812,7 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
         }
       }
     });
-    vm3.invoke(new SerializableRunnable("Start locator on " + port2) {
-      public void run() {
+    vm3.invoke("Start locator on " + port2,()->{
         File logFile = new File("");
         try {
           Properties props = new Properties();
@@ -1954,7 +1827,6 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
         } catch (IOException ex) {
           org.apache.geode.test.dunit.Assert.fail("While starting locator on 
port " + port2, ex);
         }
-      }
     });
 
     SerializableRunnable connect = new SerializableRunnable("Connect to " + 
locators) {
@@ -1982,29 +1854,23 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
 
       addDSProps(props);
       system = (InternalDistributedSystem) DistributedSystem.connect(props);
-      WaitCriterion ev = new WaitCriterion() {
-        public boolean done() {
-          try {
-            return system.getDM().getViewMembers().size() == 5;
-          } catch (Exception e) {
-            org.apache.geode.test.dunit.Assert.fail("unexpected exception", e);
-          }
-          return false; // NOTREACHED
-        }
 
-        public String description() {
-          return "waiting for 5 members - have " + 
system.getDM().getViewMembers().size();
-        }
-      };
-      Wait.waitForCriterion(ev, WAIT2_MS, 200, true);
+      Awaitility.waitAtMost(WAIT2_MS, TimeUnit.MILLISECONDS)
+          .pollInterval(200, TimeUnit.MILLISECONDS).until(() -> {
+            try {
+              return system.getDM().getViewMembers().size() == 5;
+            } catch (Exception e) {
+              org.apache.geode.test.dunit.Assert.fail("unexpected exception", 
e);
+            }
+            return false; // NOTREACHED
+          });
       system.disconnect();
 
-      vm1.invoke(getDisconnectRunnable(locators));
-      vm2.invoke(getDisconnectRunnable(locators));
+      vm1.invoke(() -> disconnectDistributedSystem());
+      vm2.invoke(() -> disconnectDistributedSystem());
     } finally {
-      SerializableRunnable stop = getStopLocatorRunnable();
-      vm0.invoke(stop);
-      vm3.invoke(stop);
+      vm0.invoke(() -> stopLocator());
+      vm3.invoke(() -> stopLocator());
       if (system != null) {
         system.disconnect();
       }
@@ -2045,8 +1911,6 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
   public void testHostingMultipleLocators() throws Exception {
     disconnectAllFromDS();
     Host host = Host.getHost(0);
-    // VM vm = host.getVM(0);
-    // VM vm1 = host.getVM(1);
     int[] randomAvailableTCPPorts = 
AvailablePortHelper.getRandomAvailableTCPPorts(2);
     port1 = randomAvailableTCPPorts[0];
     File logFile1 = new File("");
@@ -2079,12 +1943,8 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
         }
       };
       connect.run();
-      // vm1.invoke(connect);
-
-      SerializableRunnable disconnect = getDisconnectRunnable(locators);
 
-      disconnect.run();
-      // vm1.invoke(disconnect);
+      disconnectDistributedSystem();
 
     } finally {
       locator1.stop();
@@ -2117,25 +1977,15 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     Locator locator = Locator.startLocatorAndDS(port1, logFile, p);
     try {
 
-      SerializableRunnable connect =
-          new SerializableRunnable("Connect to locator on port " + port1) {
-            public void run() {
-              DistributedSystem.connect(p);
-            }
-          };
-      vm0.invoke(connect);
+      vm0.invoke(()->DistributedSystem.connect(p));
 
-      org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Stopping 
locator");
+      LogWriterUtils.getLogWriter().info("Stopping locator");
       locator.stop();
 
-      org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Starting 
locator");
+      LogWriterUtils.getLogWriter().info("Starting locator");
       locator = Locator.startLocatorAndDS(port1, logFile, p);
 
-      vm0.invoke(new SerializableRunnable("disconnect") {
-        public void run() {
-          DistributedSystem.connect(p).disconnect();
-        }
-      });
+      vm0.invoke("disconnect",()->DistributedSystem.connect(p).disconnect());
 
     } finally {
       locator.stop();
@@ -2172,39 +2022,31 @@ public class LocatorDUnitTest extends 
JUnit4DistributedTestCase {
     return MembershipManagerHelper.getLeadMember(sys);
   }
 
-  SerializableRunnable getStopLocatorRunnable() {
-    return new SerializableRunnable("stop locator") {
-      public void run() {
-        MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
-        Locator loc = Locator.getLocator();
-        if (loc != null) {
-          loc.stop();
-          assertFalse(Locator.hasLocator());
-        }
-      }
-    };
+  protected void stopLocator() {
+    MembershipManagerHelper.inhibitForcedDisconnectLogging(false);
+    Locator loc = Locator.getLocator();
+    if (loc != null) {
+      loc.stop();
+      assertFalse(Locator.hasLocator());
+    }
   }
 
-  private SerializableRunnable getStartSBLocatorRunnable(final int port, final 
String name) {
-    return new SerializableRunnable("Start locator on port " + port) {
-      public void run() {
-        File logFile = new File("");
-        try {
-          
System.setProperty(InternalLocator.LOCATORS_PREFERRED_AS_COORDINATORS, "true");
-          System.setProperty("p2p.joinTimeout", "1000");
-          Properties locProps = new Properties();
-          locProps.put(MCAST_PORT, "0");
-          locProps.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
-          addDSProps(locProps);
-          Locator.startLocatorAndDS(port, logFile, locProps);
-        } catch (IOException ex) {
-          org.apache.geode.test.dunit.Assert.fail("While starting locator on 
port " + port, ex);
-        } finally {
-          
System.getProperties().remove(InternalLocator.LOCATORS_PREFERRED_AS_COORDINATORS);
-          System.getProperties().remove("p2p.joinTimeout");
-        }
-      }
-    };
+  private void getStartSBLocatorRunnable(final int port) {
+    File logFile = new File("");
+    try {
+      System.setProperty(InternalLocator.LOCATORS_PREFERRED_AS_COORDINATORS, 
"true");
+      System.setProperty("p2p.joinTimeout", "1000");
+      Properties locProps = new Properties();
+      locProps.put(MCAST_PORT, "0");
+      locProps.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
+      addDSProps(locProps);
+      Locator.startLocatorAndDS(port, logFile, locProps);
+    } catch (IOException ex) {
+      org.apache.geode.test.dunit.Assert.fail("While starting locator on port 
" + port, ex);
+    } finally {
+      
System.getProperties().remove(InternalLocator.LOCATORS_PREFERRED_AS_COORDINATORS);
+      System.getProperties().remove("p2p.joinTimeout");
+    }
   }
 
   protected void nukeJChannel(DistributedSystem sys) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f0e5159c/geode-core/src/test/java/org/apache/geode/distributed/LocatorUDPSecurityDUnitTest.java
----------------------------------------------------------------------
diff --git 
a/geode-core/src/test/java/org/apache/geode/distributed/LocatorUDPSecurityDUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/distributed/LocatorUDPSecurityDUnitTest.java
index 3246f85..2539fc7 100644
--- 
a/geode-core/src/test/java/org/apache/geode/distributed/LocatorUDPSecurityDUnitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/distributed/LocatorUDPSecurityDUnitTest.java
@@ -14,45 +14,38 @@
  */
 package org.apache.geode.distributed;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.MembershipTest;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static 
org.apache.geode.distributed.ConfigurationProperties.MEMBER_TIMEOUT;
+import static 
org.apache.geode.distributed.ConfigurationProperties.SECURITY_UDP_DHALGO;
 
 import org.apache.geode.GemFireConfigException;
-import org.apache.geode.distributed.internal.DistributionConfig;
 import org.apache.geode.distributed.internal.InternalDistributedSystem;
-import 
org.apache.geode.distributed.internal.membership.gms.MembershipManagerHelper;
 import org.apache.geode.internal.AvailablePort;
 import org.apache.geode.test.dunit.DistributedTestUtils;
 import org.apache.geode.test.dunit.Host;
 import org.apache.geode.test.dunit.NetworkUtils;
-import org.apache.geode.test.dunit.SerializableRunnable;
 import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.Wait;
-import org.apache.geode.test.dunit.WaitCriterion;
+import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.FlakyTest;
+import org.apache.geode.test.junit.categories.MembershipTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
-import static org.apache.geode.distributed.ConfigurationProperties.*;
+import java.util.Properties;
 
 @Category({DistributedTest.class, MembershipTest.class})
 public class LocatorUDPSecurityDUnitTest extends LocatorDUnitTest {
 
   public LocatorUDPSecurityDUnitTest() {}
 
-
   @Override
   protected void addDSProps(Properties p) {
     p.setProperty(SECURITY_UDP_DHALGO, "AES:128");
   }
 
   @Override
-  @Category(FlakyTest.class)
   @Test
   public void testStartTwoLocators() throws Exception {
     super.testStartTwoLocators();
@@ -63,30 +56,12 @@ public class LocatorUDPSecurityDUnitTest extends 
LocatorDUnitTest {
     disconnectAllFromDS();
     Host host = Host.getHost(0);
     VM vm0 = host.getVM(0);
-    VM vm1 = host.getVM(1);
-    VM vm2 = host.getVM(2);
 
     final int port = 
AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
     DistributedTestUtils.deleteLocatorStateFile(port1);
     final String locators = NetworkUtils.getServerHostName(host) + "[" + port 
+ "]";
-    final String uniqueName = getUniqueName();
-
-    vm0.invoke(new SerializableRunnable("Start locator " + locators) {
-      public void run() {
-        File logFile = new File("");
-        try {
-          Properties locProps = new Properties();
-          locProps.setProperty(MCAST_PORT, "0");
-          locProps.setProperty(MEMBER_TIMEOUT, "1000");
-          locProps.put(ENABLE_CLUSTER_CONFIGURATION, "false");
 
-          addDSProps(locProps);
-          Locator.startLocatorAndDS(port, logFile, locProps);
-        } catch (IOException ex) {
-          org.apache.geode.test.dunit.Assert.fail("While starting locator on 
port " + port, ex);
-        }
-      }
-    });
+    vm0.invoke("Start locator " + locators, () -> startLocator(port));
     try {
 
       Properties props = new Properties();
@@ -99,7 +74,7 @@ public class LocatorUDPSecurityDUnitTest extends 
LocatorDUnitTest {
     } catch (GemFireConfigException gce) {
       Assert.assertTrue(gce.getMessage().contains("Rejecting 
findCoordinatorRequest"));
     } finally {
-      vm0.invoke(getStopLocatorRunnable());
+      vm0.invoke(() -> stopLocator());
     }
   }
 }

Reply via email to