You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/01/25 06:40:10 UTC

[GitHub] [geode] nabarunnag opened a new pull request #7303: GEODE-9987: Refactored/Removal of deprecated APIs

nabarunnag opened a new pull request #7303:
URL: https://github.com/apache/geode/pull/7303


   	* The tests were refactored to remove deprecated functions.
   	* The second test was removed as using 0 as port numbers may result in port already in use and may cause flakiness.
   
   <!-- Thank you for submitting a contribution to Apache Geode. -->
   
   <!-- In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken: 
   -->
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced in the commit message?
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically `develop`)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   - [ ] Does `gradlew build` run cleanly?
   
   - [ ] Have you written or updated unit tests to verify your changes?
   
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   
   <!-- Note:
   Please ensure that once the PR is submitted, check Concourse for build issues and
   submit an update to your PR as soon as possible. If you need help, please send an
   email to dev@geode.apache.org.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] upthewaterspout commented on pull request #7303: GEODE-9987: Refactored/Removal of deprecated APIs

Posted by GitBox <gi...@apache.org>.
upthewaterspout commented on pull request #7303:
URL: https://github.com/apache/geode/pull/7303#issuecomment-1039422049


   It's not clear to me how these changes relate to GEODE-9987. That bug was a failure saying "Member isn't responding to heartbeat requests". I don't think this refactoring is going to affect that type of failure - usually that would indicate resource issues on the CI machine or perhaps the need for a larger membership-timeout for this test? It does look like this test probably doesn't need to start so many locators, maybe that would help?
   
   I'm not sure how I feel about removing the port 0 test. It looks like it was trying to test that members that start up with port 0 as the locator port correctly distribute the *actual* port of the locator to other members, rather than 0? Is the reason you think port 0 is going to cause port conflicts because other tests are using AvailablePortHelper? Seems like we still need a way to write tests that using port 0 actually works.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #7303: GEODE-9987: Refactored/Removal of deprecated APIs

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #7303:
URL: https://github.com/apache/geode/pull/7303#discussion_r834669004



##########
File path: geode-core/src/distributedTest/java/org/apache/geode/distributed/HostedLocatorsDUnitTest.java
##########
@@ -54,277 +45,163 @@
  * @since GemFire 8.0
  */
 @Category({ClientServerTest.class})
-public class HostedLocatorsDUnitTest extends JUnit4DistributedTestCase {
-
-  protected static final int TIMEOUT_MILLISECONDS = 5 * 60 * 1000; // 5 minutes
-
-  protected transient volatile int locatorPort;
-  protected transient volatile LocatorLauncher launcher;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    disconnectAllFromDS();
-  }
+@SuppressWarnings("serial")
+public class HostedLocatorsDUnitTest implements Serializable {
 
-  private String getUniqueLocatorName() {
-    String uniqueLocatorName = Host.getHost(0).getHostName() + "_"
-        + getUniqueName();
-    return uniqueLocatorName;
-  }
+  @Rule
+  public ClusterStartupRule clusterStartupRule = new ClusterStartupRule();

Review comment:
       can't be private and use the `@Rule` annotation




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] upthewaterspout commented on pull request #7303: GEODE-9987: Refactored/Removal of deprecated APIs

Posted by GitBox <gi...@apache.org>.
upthewaterspout commented on pull request #7303:
URL: https://github.com/apache/geode/pull/7303#issuecomment-1039422049


   It's not clear to me how these changes relate to GEODE-9987. That bug was a failure saying "Member isn't responding to heartbeat requests". I don't think this refactoring is going to affect that type of failure - usually that would indicate resource issues on the CI machine or perhaps the need for a larger membership-timeout for this test? It does look like this test probably doesn't need to start so many locators, maybe that would help?
   
   I'm not sure how I feel about removing the port 0 test. It looks like it was trying to test that members that start up with port 0 as the locator port correctly distribute the *actual* port of the locator to other members, rather than 0? Is the reason you think port 0 is going to cause port conflicts because other tests are using AvailablePortHelper? Seems like we still need a way to write tests that using port 0 actually works.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] Bill commented on a change in pull request #7303: GEODE-9987: Refactored/Removal of deprecated APIs

Posted by GitBox <gi...@apache.org>.
Bill commented on a change in pull request #7303:
URL: https://github.com/apache/geode/pull/7303#discussion_r834655698



##########
File path: geode-core/src/distributedTest/java/org/apache/geode/distributed/HostedLocatorsDUnitTest.java
##########
@@ -54,277 +45,163 @@
  * @since GemFire 8.0
  */
 @Category({ClientServerTest.class})
-public class HostedLocatorsDUnitTest extends JUnit4DistributedTestCase {
-
-  protected static final int TIMEOUT_MILLISECONDS = 5 * 60 * 1000; // 5 minutes
-
-  protected transient volatile int locatorPort;
-  protected transient volatile LocatorLauncher launcher;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    disconnectAllFromDS();
-  }
+@SuppressWarnings("serial")
+public class HostedLocatorsDUnitTest implements Serializable {
 
-  private String getUniqueLocatorName() {
-    String uniqueLocatorName = Host.getHost(0).getHostName() + "_"
-        + getUniqueName();
-    return uniqueLocatorName;
-  }
+  @Rule
+  public ClusterStartupRule clusterStartupRule = new ClusterStartupRule();

Review comment:
       make private

##########
File path: geode-core/src/distributedTest/java/org/apache/geode/distributed/HostedLocatorsDUnitTest.java
##########
@@ -54,277 +45,163 @@
  * @since GemFire 8.0
  */
 @Category({ClientServerTest.class})
-public class HostedLocatorsDUnitTest extends JUnit4DistributedTestCase {
-
-  protected static final int TIMEOUT_MILLISECONDS = 5 * 60 * 1000; // 5 minutes
-
-  protected transient volatile int locatorPort;
-  protected transient volatile LocatorLauncher launcher;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    disconnectAllFromDS();
-  }
+@SuppressWarnings("serial")
+public class HostedLocatorsDUnitTest implements Serializable {
 
-  private String getUniqueLocatorName() {
-    String uniqueLocatorName = Host.getHost(0).getHostName() + "_"
-        + getUniqueName();
-    return uniqueLocatorName;
-  }
+  @Rule
+  public ClusterStartupRule clusterStartupRule = new ClusterStartupRule();
 
   @Test
   public void testGetAllHostedLocators() throws Exception {
-    final InternalDistributedSystem system = getSystem();
-    final String dunitLocator = system.getConfig().getLocators();
-    assertNotNull(dunitLocator);
-    assertFalse(dunitLocator.isEmpty());
-
-    final int[] ports = getRandomAvailableTCPPorts(4);
-
-    final String uniqueName = getUniqueLocatorName();
-    for (int i = 0; i < 4; i++) {
-      final int whichvm = i;
-      getHost(0).getVM(whichvm).invoke(new SerializableCallable() {
-        @Override
-        public Object call() throws Exception {
-          final String name = uniqueName + "-" + whichvm;
-          final File subdir = new File(name);
-          if (subdir.exists()) {
-            FileUtils.deleteRecursively(subdir);
-          }
-          subdir.mkdir();
-          assertTrue(subdir.exists() && subdir.isDirectory());
-
-          final Builder builder = new Builder().setMemberName(name).setPort(ports[whichvm])
-              .set(LOCATORS, dunitLocator)
-              .setRedirectOutput(true).setWorkingDirectory(name);
-
-          launcher = builder.build();
-          assertEquals(Status.ONLINE, launcher.start().getStatus());
-          waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
-          return null;
-        }
-      });
-    }
-
-    final String host = LocalHostUtil.getLocalHost().getHostAddress();
+    // Get the localhost IP address
+    String ipAddress = getIPAddress().getHostAddress();
 
+    // Collection of expected locator addresses.
     final Set<String> locators = new HashSet<>();
-    locators.add(host + "["
-        + dunitLocator.substring(dunitLocator.indexOf("[") + 1, dunitLocator.indexOf("]")) + "]");
-    for (int port : ports) {
-      locators.add(host + "[" + port + "]");
-    }
-
+    // Starting 4 locators
+    MemberVM locator1 = clusterStartupRule.startLocatorVM(0);
+    int locator1Port = locator1.getPort();
+    locators.add(ipAddress + "[" + locator1Port + "]");
+
+    MemberVM locator2 =
+        clusterStartupRule.startLocatorVM(1, l -> l.withConnectionToLocator(locator1Port));
+    int locator2Port = locator2.getPort();
+    locators.add(ipAddress + "[" + locator2Port + "]");
+
+    MemberVM locator3 =
+        clusterStartupRule.startLocatorVM(2,
+            l -> l.withConnectionToLocator(locator1Port, locator2Port));
+    int locator3Port = locator3.getPort();
+    locators.add(ipAddress + "[" + locator3Port + "]");
+
+    MemberVM locator4 =
+        clusterStartupRule.startLocatorVM(3,
+            l -> l.withConnectionToLocator(locator1Port, locator2Port, locator3Port));
+    int locator4Port = locator4.getPort();
+    locators.add(ipAddress + "[" + locator4Port + "]");
+
+    MemberVM server1 =
+        clusterStartupRule.startServerVM(4,
+            s -> s.withConnectionToLocator(locator1Port, locator2Port, locator3Port, locator4Port));
     // validation within non-locator
-    final ClusterDistributionManager dm =
-        (ClusterDistributionManager) system.getDistributionManager();
-
-    final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-    assertEquals(5, locatorIds.size());
+    server1.invoke(() -> {
+      ClusterDistributionManager dm =
+          (ClusterDistributionManager) ClusterStartupRule.getCache().getDistributionManager();
+      final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
+
+      assertThat(locatorIds.size()).isEqualTo(4);
+      final Map<InternalDistributedMember, Collection<String>> hostedLocators =
+          dm.getAllHostedLocators();
+      assertThat(hostedLocators).isNotEmpty();
+      assertThat(hostedLocators.size()).isEqualTo(4);
+      for (InternalDistributedMember member : hostedLocators.keySet()) {
+        assertThat(hostedLocators.get(member).size()).isEqualTo(1);
+        final String hostedLocator = hostedLocators.get(member).iterator().next();
+        assertThat(locators).contains(hostedLocator);
+      }
+    });
+
+    // validations within the locators
+    locator1.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator2.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator3.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator4.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+  }
 
+  private void validateHostedLocators(Set<String> locators) {
+    ClusterDistributionManager dm =
+        (ClusterDistributionManager) ClusterStartupRule.getCache().getDistributionManager();
+    final InternalDistributedMember self = dm.getDistributionManagerId();
+    final Set<InternalDistributedMember> locatorIDs = dm.getLocatorDistributionManagerIds();
+    assertThat(locatorIDs.size()).isEqualTo(4);
+    assertThat(locatorIDs).contains(self);
     final Map<InternalDistributedMember, Collection<String>> hostedLocators =
         dm.getAllHostedLocators();
-    assertTrue(!hostedLocators.isEmpty());
-    assertEquals(5, hostedLocators.size());
-
+    assertThat(hostedLocators).isNotEmpty();
+    assertThat(hostedLocators.size()).isEqualTo(4);
+    assertThat(hostedLocators).containsKey(self);
     for (InternalDistributedMember member : hostedLocators.keySet()) {
-      assertEquals(1, hostedLocators.get(member).size());
+      assertThat(hostedLocators.get(member).size()).isEqualTo(1);
       final String hostedLocator = hostedLocators.get(member).iterator().next();
-      assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
+      assertThat(locators).contains(hostedLocator);
     }
+  }
 
-    // validate fix for #46324
-    for (int whichvm = 0; whichvm < 4; whichvm++) {
-      getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
-        @Override
-        public void run() {
-          final ClusterDistributionManager dm =
-              (ClusterDistributionManager) InternalDistributedSystem.getAnyInstance()
-                  .getDistributionManager();
-          final InternalDistributedMember self = dm.getDistributionManagerId();
-
-          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-          assertTrue(locatorIds.contains(self));
+  public static InetAddress getIPAddress() {

Review comment:
       make private

##########
File path: geode-core/src/distributedTest/java/org/apache/geode/distributed/HostedLocatorsDUnitTest.java
##########
@@ -54,277 +45,163 @@
  * @since GemFire 8.0
  */
 @Category({ClientServerTest.class})
-public class HostedLocatorsDUnitTest extends JUnit4DistributedTestCase {
-
-  protected static final int TIMEOUT_MILLISECONDS = 5 * 60 * 1000; // 5 minutes
-
-  protected transient volatile int locatorPort;
-  protected transient volatile LocatorLauncher launcher;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    disconnectAllFromDS();
-  }
+@SuppressWarnings("serial")
+public class HostedLocatorsDUnitTest implements Serializable {
 
-  private String getUniqueLocatorName() {
-    String uniqueLocatorName = Host.getHost(0).getHostName() + "_"
-        + getUniqueName();
-    return uniqueLocatorName;
-  }
+  @Rule
+  public ClusterStartupRule clusterStartupRule = new ClusterStartupRule();
 
   @Test
   public void testGetAllHostedLocators() throws Exception {
-    final InternalDistributedSystem system = getSystem();
-    final String dunitLocator = system.getConfig().getLocators();
-    assertNotNull(dunitLocator);
-    assertFalse(dunitLocator.isEmpty());
-
-    final int[] ports = getRandomAvailableTCPPorts(4);
-
-    final String uniqueName = getUniqueLocatorName();
-    for (int i = 0; i < 4; i++) {
-      final int whichvm = i;
-      getHost(0).getVM(whichvm).invoke(new SerializableCallable() {
-        @Override
-        public Object call() throws Exception {
-          final String name = uniqueName + "-" + whichvm;
-          final File subdir = new File(name);
-          if (subdir.exists()) {
-            FileUtils.deleteRecursively(subdir);
-          }
-          subdir.mkdir();
-          assertTrue(subdir.exists() && subdir.isDirectory());
-
-          final Builder builder = new Builder().setMemberName(name).setPort(ports[whichvm])
-              .set(LOCATORS, dunitLocator)
-              .setRedirectOutput(true).setWorkingDirectory(name);
-
-          launcher = builder.build();
-          assertEquals(Status.ONLINE, launcher.start().getStatus());
-          waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
-          return null;
-        }
-      });
-    }
-
-    final String host = LocalHostUtil.getLocalHost().getHostAddress();
+    // Get the localhost IP address
+    String ipAddress = getIPAddress().getHostAddress();
 
+    // Collection of expected locator addresses.
     final Set<String> locators = new HashSet<>();
-    locators.add(host + "["
-        + dunitLocator.substring(dunitLocator.indexOf("[") + 1, dunitLocator.indexOf("]")) + "]");
-    for (int port : ports) {
-      locators.add(host + "[" + port + "]");
-    }
-
+    // Starting 4 locators
+    MemberVM locator1 = clusterStartupRule.startLocatorVM(0);
+    int locator1Port = locator1.getPort();
+    locators.add(ipAddress + "[" + locator1Port + "]");
+
+    MemberVM locator2 =
+        clusterStartupRule.startLocatorVM(1, l -> l.withConnectionToLocator(locator1Port));
+    int locator2Port = locator2.getPort();
+    locators.add(ipAddress + "[" + locator2Port + "]");
+
+    MemberVM locator3 =
+        clusterStartupRule.startLocatorVM(2,
+            l -> l.withConnectionToLocator(locator1Port, locator2Port));
+    int locator3Port = locator3.getPort();
+    locators.add(ipAddress + "[" + locator3Port + "]");
+
+    MemberVM locator4 =
+        clusterStartupRule.startLocatorVM(3,
+            l -> l.withConnectionToLocator(locator1Port, locator2Port, locator3Port));
+    int locator4Port = locator4.getPort();
+    locators.add(ipAddress + "[" + locator4Port + "]");
+
+    MemberVM server1 =
+        clusterStartupRule.startServerVM(4,
+            s -> s.withConnectionToLocator(locator1Port, locator2Port, locator3Port, locator4Port));
     // validation within non-locator
-    final ClusterDistributionManager dm =
-        (ClusterDistributionManager) system.getDistributionManager();
-
-    final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-    assertEquals(5, locatorIds.size());
+    server1.invoke(() -> {
+      ClusterDistributionManager dm =
+          (ClusterDistributionManager) ClusterStartupRule.getCache().getDistributionManager();
+      final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
+
+      assertThat(locatorIds.size()).isEqualTo(4);
+      final Map<InternalDistributedMember, Collection<String>> hostedLocators =
+          dm.getAllHostedLocators();
+      assertThat(hostedLocators).isNotEmpty();
+      assertThat(hostedLocators.size()).isEqualTo(4);
+      for (InternalDistributedMember member : hostedLocators.keySet()) {
+        assertThat(hostedLocators.get(member).size()).isEqualTo(1);
+        final String hostedLocator = hostedLocators.get(member).iterator().next();
+        assertThat(locators).contains(hostedLocator);
+      }
+    });
+
+    // validations within the locators
+    locator1.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator2.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator3.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator4.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+  }
 
+  private void validateHostedLocators(Set<String> locators) {
+    ClusterDistributionManager dm =
+        (ClusterDistributionManager) ClusterStartupRule.getCache().getDistributionManager();
+    final InternalDistributedMember self = dm.getDistributionManagerId();
+    final Set<InternalDistributedMember> locatorIDs = dm.getLocatorDistributionManagerIds();
+    assertThat(locatorIDs.size()).isEqualTo(4);
+    assertThat(locatorIDs).contains(self);
     final Map<InternalDistributedMember, Collection<String>> hostedLocators =
         dm.getAllHostedLocators();
-    assertTrue(!hostedLocators.isEmpty());
-    assertEquals(5, hostedLocators.size());
-
+    assertThat(hostedLocators).isNotEmpty();
+    assertThat(hostedLocators.size()).isEqualTo(4);
+    assertThat(hostedLocators).containsKey(self);
     for (InternalDistributedMember member : hostedLocators.keySet()) {
-      assertEquals(1, hostedLocators.get(member).size());
+      assertThat(hostedLocators.get(member).size()).isEqualTo(1);
       final String hostedLocator = hostedLocators.get(member).iterator().next();
-      assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
+      assertThat(locators).contains(hostedLocator);
     }
+  }
 
-    // validate fix for #46324
-    for (int whichvm = 0; whichvm < 4; whichvm++) {
-      getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
-        @Override
-        public void run() {
-          final ClusterDistributionManager dm =
-              (ClusterDistributionManager) InternalDistributedSystem.getAnyInstance()
-                  .getDistributionManager();
-          final InternalDistributedMember self = dm.getDistributionManagerId();
-
-          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-          assertTrue(locatorIds.contains(self));
+  public static InetAddress getIPAddress() {
+    return Boolean.getBoolean("java.net.preferIPv6Addresses") ? getIPv6Address() : getIPv4Address();
+  }
 
-          final Map<InternalDistributedMember, Collection<String>> hostedLocators =
-              dm.getAllHostedLocators();
-          assertTrue(
-              "hit bug #46324: " + hostedLocators + " is missing "
-                  + InternalLocator.getLocatorStrings() + " for " + self,
-              hostedLocators.containsKey(self));
-        }
-      });
+  protected static InetAddress getIPv4Address() {
+    InetAddress host = null;
+    try {
+      host = InetAddress.getLocalHost();
+      if (host instanceof Inet4Address && !host.isLinkLocalAddress() && !host.isLoopbackAddress()) {
+        return host;
+      }
+    } catch (UnknownHostException e) {
+      String s = "Local host not found";
+      throw new RuntimeException(s, e);
     }
-
-    // validation with locators
-    for (int whichvm = 0; whichvm < 4; whichvm++) {
-      getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
-        @Override
-        public void run() {
-          final ClusterDistributionManager dm =
-              (ClusterDistributionManager) InternalDistributedSystem.getAnyInstance()
-                  .getDistributionManager();
-
-          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-          assertEquals(5, locatorIds.size());
-
-          final Map<InternalDistributedMember, Collection<String>> hostedLocators =
-              dm.getAllHostedLocators();
-          assertTrue(!hostedLocators.isEmpty());
-          assertEquals(5, hostedLocators.size());
-
-          for (InternalDistributedMember member : hostedLocators.keySet()) {
-            assertEquals(1, hostedLocators.get(member).size());
-            final String hostedLocator = hostedLocators.get(member).iterator().next();
-            assertTrue(locators + " does not contain " + hostedLocator,
-                locators.contains(hostedLocator));
+    try {
+      Enumeration i = NetworkInterface.getNetworkInterfaces();
+      while (i.hasMoreElements()) {
+        NetworkInterface ni = (NetworkInterface) i.nextElement();
+        Enumeration j = ni.getInetAddresses();

Review comment:
       declare as `Enumeration<InetAddress> j` to eliminate the cast on line 159.

##########
File path: geode-core/src/distributedTest/java/org/apache/geode/distributed/HostedLocatorsDUnitTest.java
##########
@@ -54,277 +45,163 @@
  * @since GemFire 8.0
  */
 @Category({ClientServerTest.class})
-public class HostedLocatorsDUnitTest extends JUnit4DistributedTestCase {
-
-  protected static final int TIMEOUT_MILLISECONDS = 5 * 60 * 1000; // 5 minutes
-
-  protected transient volatile int locatorPort;
-  protected transient volatile LocatorLauncher launcher;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    disconnectAllFromDS();
-  }
+@SuppressWarnings("serial")
+public class HostedLocatorsDUnitTest implements Serializable {
 
-  private String getUniqueLocatorName() {
-    String uniqueLocatorName = Host.getHost(0).getHostName() + "_"
-        + getUniqueName();
-    return uniqueLocatorName;
-  }
+  @Rule
+  public ClusterStartupRule clusterStartupRule = new ClusterStartupRule();
 
   @Test
   public void testGetAllHostedLocators() throws Exception {
-    final InternalDistributedSystem system = getSystem();
-    final String dunitLocator = system.getConfig().getLocators();
-    assertNotNull(dunitLocator);
-    assertFalse(dunitLocator.isEmpty());
-
-    final int[] ports = getRandomAvailableTCPPorts(4);
-
-    final String uniqueName = getUniqueLocatorName();
-    for (int i = 0; i < 4; i++) {
-      final int whichvm = i;
-      getHost(0).getVM(whichvm).invoke(new SerializableCallable() {
-        @Override
-        public Object call() throws Exception {
-          final String name = uniqueName + "-" + whichvm;
-          final File subdir = new File(name);
-          if (subdir.exists()) {
-            FileUtils.deleteRecursively(subdir);
-          }
-          subdir.mkdir();
-          assertTrue(subdir.exists() && subdir.isDirectory());
-
-          final Builder builder = new Builder().setMemberName(name).setPort(ports[whichvm])
-              .set(LOCATORS, dunitLocator)
-              .setRedirectOutput(true).setWorkingDirectory(name);
-
-          launcher = builder.build();
-          assertEquals(Status.ONLINE, launcher.start().getStatus());
-          waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
-          return null;
-        }
-      });
-    }
-
-    final String host = LocalHostUtil.getLocalHost().getHostAddress();
+    // Get the localhost IP address
+    String ipAddress = getIPAddress().getHostAddress();
 
+    // Collection of expected locator addresses.
     final Set<String> locators = new HashSet<>();
-    locators.add(host + "["
-        + dunitLocator.substring(dunitLocator.indexOf("[") + 1, dunitLocator.indexOf("]")) + "]");
-    for (int port : ports) {
-      locators.add(host + "[" + port + "]");
-    }
-
+    // Starting 4 locators
+    MemberVM locator1 = clusterStartupRule.startLocatorVM(0);
+    int locator1Port = locator1.getPort();
+    locators.add(ipAddress + "[" + locator1Port + "]");
+
+    MemberVM locator2 =
+        clusterStartupRule.startLocatorVM(1, l -> l.withConnectionToLocator(locator1Port));
+    int locator2Port = locator2.getPort();
+    locators.add(ipAddress + "[" + locator2Port + "]");
+
+    MemberVM locator3 =
+        clusterStartupRule.startLocatorVM(2,
+            l -> l.withConnectionToLocator(locator1Port, locator2Port));
+    int locator3Port = locator3.getPort();
+    locators.add(ipAddress + "[" + locator3Port + "]");
+
+    MemberVM locator4 =
+        clusterStartupRule.startLocatorVM(3,
+            l -> l.withConnectionToLocator(locator1Port, locator2Port, locator3Port));
+    int locator4Port = locator4.getPort();
+    locators.add(ipAddress + "[" + locator4Port + "]");
+
+    MemberVM server1 =
+        clusterStartupRule.startServerVM(4,
+            s -> s.withConnectionToLocator(locator1Port, locator2Port, locator3Port, locator4Port));
     // validation within non-locator
-    final ClusterDistributionManager dm =
-        (ClusterDistributionManager) system.getDistributionManager();
-
-    final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-    assertEquals(5, locatorIds.size());
+    server1.invoke(() -> {
+      ClusterDistributionManager dm =
+          (ClusterDistributionManager) ClusterStartupRule.getCache().getDistributionManager();
+      final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
+
+      assertThat(locatorIds.size()).isEqualTo(4);
+      final Map<InternalDistributedMember, Collection<String>> hostedLocators =
+          dm.getAllHostedLocators();
+      assertThat(hostedLocators).isNotEmpty();
+      assertThat(hostedLocators.size()).isEqualTo(4);
+      for (InternalDistributedMember member : hostedLocators.keySet()) {
+        assertThat(hostedLocators.get(member).size()).isEqualTo(1);
+        final String hostedLocator = hostedLocators.get(member).iterator().next();
+        assertThat(locators).contains(hostedLocator);
+      }
+    });
+
+    // validations within the locators
+    locator1.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator2.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator3.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator4.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+  }
 
+  private void validateHostedLocators(Set<String> locators) {
+    ClusterDistributionManager dm =
+        (ClusterDistributionManager) ClusterStartupRule.getCache().getDistributionManager();
+    final InternalDistributedMember self = dm.getDistributionManagerId();
+    final Set<InternalDistributedMember> locatorIDs = dm.getLocatorDistributionManagerIds();
+    assertThat(locatorIDs.size()).isEqualTo(4);
+    assertThat(locatorIDs).contains(self);
     final Map<InternalDistributedMember, Collection<String>> hostedLocators =
         dm.getAllHostedLocators();
-    assertTrue(!hostedLocators.isEmpty());
-    assertEquals(5, hostedLocators.size());
-
+    assertThat(hostedLocators).isNotEmpty();
+    assertThat(hostedLocators.size()).isEqualTo(4);
+    assertThat(hostedLocators).containsKey(self);
     for (InternalDistributedMember member : hostedLocators.keySet()) {
-      assertEquals(1, hostedLocators.get(member).size());
+      assertThat(hostedLocators.get(member).size()).isEqualTo(1);
       final String hostedLocator = hostedLocators.get(member).iterator().next();
-      assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
+      assertThat(locators).contains(hostedLocator);
     }
+  }
 
-    // validate fix for #46324
-    for (int whichvm = 0; whichvm < 4; whichvm++) {
-      getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
-        @Override
-        public void run() {
-          final ClusterDistributionManager dm =
-              (ClusterDistributionManager) InternalDistributedSystem.getAnyInstance()
-                  .getDistributionManager();
-          final InternalDistributedMember self = dm.getDistributionManagerId();
-
-          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-          assertTrue(locatorIds.contains(self));
+  public static InetAddress getIPAddress() {
+    return Boolean.getBoolean("java.net.preferIPv6Addresses") ? getIPv6Address() : getIPv4Address();
+  }
 
-          final Map<InternalDistributedMember, Collection<String>> hostedLocators =
-              dm.getAllHostedLocators();
-          assertTrue(
-              "hit bug #46324: " + hostedLocators + " is missing "
-                  + InternalLocator.getLocatorStrings() + " for " + self,
-              hostedLocators.containsKey(self));
-        }
-      });
+  protected static InetAddress getIPv4Address() {
+    InetAddress host = null;
+    try {
+      host = InetAddress.getLocalHost();
+      if (host instanceof Inet4Address && !host.isLinkLocalAddress() && !host.isLoopbackAddress()) {
+        return host;
+      }
+    } catch (UnknownHostException e) {
+      String s = "Local host not found";
+      throw new RuntimeException(s, e);
     }
-
-    // validation with locators
-    for (int whichvm = 0; whichvm < 4; whichvm++) {
-      getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
-        @Override
-        public void run() {
-          final ClusterDistributionManager dm =
-              (ClusterDistributionManager) InternalDistributedSystem.getAnyInstance()
-                  .getDistributionManager();
-
-          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-          assertEquals(5, locatorIds.size());
-
-          final Map<InternalDistributedMember, Collection<String>> hostedLocators =
-              dm.getAllHostedLocators();
-          assertTrue(!hostedLocators.isEmpty());
-          assertEquals(5, hostedLocators.size());
-
-          for (InternalDistributedMember member : hostedLocators.keySet()) {
-            assertEquals(1, hostedLocators.get(member).size());
-            final String hostedLocator = hostedLocators.get(member).iterator().next();
-            assertTrue(locators + " does not contain " + hostedLocator,
-                locators.contains(hostedLocator));
+    try {
+      Enumeration i = NetworkInterface.getNetworkInterfaces();
+      while (i.hasMoreElements()) {
+        NetworkInterface ni = (NetworkInterface) i.nextElement();
+        Enumeration j = ni.getInetAddresses();
+        while (j.hasMoreElements()) {
+          InetAddress addr = (InetAddress) j.nextElement();
+          // gemfire won't form connections using link-local addresses
+          if (!addr.isLinkLocalAddress() && !addr.isLoopbackAddress()
+              && (addr instanceof Inet4Address)) {
+            return addr;
           }
         }
-      });
+      }
+      String s = "IPv4 address not found";
+      throw new RuntimeException(s);
+    } catch (SocketException e) {
+      String s = "Problem reading IPv4 address";
+      throw new RuntimeException(s, e);
     }
   }
 
-  @Test
-  public void testGetAllHostedLocatorsUsingPortZero() throws Exception {
-    final InternalDistributedSystem system = getSystem();
-    final String dunitLocator = system.getConfig().getLocators();
-    assertNotNull(dunitLocator);
-    assertFalse(dunitLocator.isEmpty());
-
-    // This will eventually contain the ports used by locators
-    final int[] ports = new int[] {0, 0, 0, 0};
-
-    final String uniqueName = getUniqueLocatorName();
-    for (int i = 0; i < 4; i++) {
-      final int whichvm = i;
-      Integer port = (Integer) Host.getHost(0).getVM(whichvm).invoke(new SerializableCallable() {
-        @Override
-        public Object call() throws Exception {
-          final String name = uniqueName + "-" + whichvm;
-          final File subdir = new File(name);
-          if (subdir.exists()) {
-            FileUtils.deleteRecursively(subdir);
-          }
-          subdir.mkdir();
-          assertTrue(subdir.exists() && subdir.isDirectory());
-
-          final Builder builder = new Builder().setMemberName(name).setPort(ports[whichvm])
-              .set(LOCATORS, dunitLocator)
-              .setRedirectOutput(true).setWorkingDirectory(name);
-
-          launcher = builder.build();
-          assertEquals(Status.ONLINE, launcher.start().getStatus());
-          waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
-          return launcher.getPort();
-        }
-      });
-      ports[i] = port;
-    }
-
-    final String host = LocalHostUtil.getLocalHost().getHostAddress();
-
-    final Set<String> locators = new HashSet<>();
-    locators.add(host + "["
-        + dunitLocator.substring(dunitLocator.indexOf("[") + 1, dunitLocator.indexOf("]")) + "]");
-    for (int port : ports) {
-      locators.add(host + "[" + port + "]");
-    }
-
-    // validation within non-locator
-    final ClusterDistributionManager dm =
-        (ClusterDistributionManager) system.getDistributionManager();
-
-    final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-    assertEquals(5, locatorIds.size());
-
-    final Map<InternalDistributedMember, Collection<String>> hostedLocators =
-        dm.getAllHostedLocators();
-    assertTrue(!hostedLocators.isEmpty());
-    assertEquals(5, hostedLocators.size());
-
-    for (InternalDistributedMember member : hostedLocators.keySet()) {
-      assertEquals(1, hostedLocators.get(member).size());
-      final String hostedLocator = hostedLocators.get(member).iterator().next();
-      assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
-    }
-
-    // validate fix for #46324
-    for (int whichvm = 0; whichvm < 4; whichvm++) {
-      Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
-        @Override
-        public void run() {
-          final ClusterDistributionManager dm =
-              (ClusterDistributionManager) InternalDistributedSystem.getAnyInstance()
-                  .getDistributionManager();
-          final InternalDistributedMember self = dm.getDistributionManagerId();
-
-          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-          assertTrue(locatorIds.contains(self));
-
-          final Map<InternalDistributedMember, Collection<String>> hostedLocators =
-              dm.getAllHostedLocators();
-          assertTrue(
-              "hit bug #46324: " + hostedLocators + " is missing "
-                  + InternalLocator.getLocatorStrings() + " for " + self,
-              hostedLocators.containsKey(self));
-        }
-      });
-    }
-
-    // validation with locators
-    for (int whichvm = 0; whichvm < 4; whichvm++) {
-      Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
-        @Override
-        public void run() {
-          final ClusterDistributionManager dm =
-              (ClusterDistributionManager) InternalDistributedSystem.getAnyInstance()
-                  .getDistributionManager();
-
-          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-          assertEquals(5, locatorIds.size());
-
-          final Map<InternalDistributedMember, Collection<String>> hostedLocators =
-              dm.getAllHostedLocators();
-          assertTrue(!hostedLocators.isEmpty());
-          assertEquals(5, hostedLocators.size());
-
-          for (InternalDistributedMember member : hostedLocators.keySet()) {
-            assertEquals(1, hostedLocators.get(member).size());
-            final String hostedLocator = hostedLocators.get(member).iterator().next();
-            assertTrue(locators + " does not contain " + hostedLocator,
-                locators.contains(hostedLocator));
+  public static InetAddress getIPv6Address() {

Review comment:
       make private

##########
File path: geode-core/src/distributedTest/java/org/apache/geode/distributed/HostedLocatorsDUnitTest.java
##########
@@ -54,277 +45,163 @@
  * @since GemFire 8.0
  */
 @Category({ClientServerTest.class})
-public class HostedLocatorsDUnitTest extends JUnit4DistributedTestCase {
-
-  protected static final int TIMEOUT_MILLISECONDS = 5 * 60 * 1000; // 5 minutes
-
-  protected transient volatile int locatorPort;
-  protected transient volatile LocatorLauncher launcher;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    disconnectAllFromDS();
-  }
+@SuppressWarnings("serial")
+public class HostedLocatorsDUnitTest implements Serializable {
 
-  private String getUniqueLocatorName() {
-    String uniqueLocatorName = Host.getHost(0).getHostName() + "_"
-        + getUniqueName();
-    return uniqueLocatorName;
-  }
+  @Rule
+  public ClusterStartupRule clusterStartupRule = new ClusterStartupRule();
 
   @Test
   public void testGetAllHostedLocators() throws Exception {
-    final InternalDistributedSystem system = getSystem();
-    final String dunitLocator = system.getConfig().getLocators();
-    assertNotNull(dunitLocator);
-    assertFalse(dunitLocator.isEmpty());
-
-    final int[] ports = getRandomAvailableTCPPorts(4);
-
-    final String uniqueName = getUniqueLocatorName();
-    for (int i = 0; i < 4; i++) {
-      final int whichvm = i;
-      getHost(0).getVM(whichvm).invoke(new SerializableCallable() {
-        @Override
-        public Object call() throws Exception {
-          final String name = uniqueName + "-" + whichvm;
-          final File subdir = new File(name);
-          if (subdir.exists()) {
-            FileUtils.deleteRecursively(subdir);
-          }
-          subdir.mkdir();
-          assertTrue(subdir.exists() && subdir.isDirectory());
-
-          final Builder builder = new Builder().setMemberName(name).setPort(ports[whichvm])
-              .set(LOCATORS, dunitLocator)
-              .setRedirectOutput(true).setWorkingDirectory(name);
-
-          launcher = builder.build();
-          assertEquals(Status.ONLINE, launcher.start().getStatus());
-          waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
-          return null;
-        }
-      });
-    }
-
-    final String host = LocalHostUtil.getLocalHost().getHostAddress();
+    // Get the localhost IP address
+    String ipAddress = getIPAddress().getHostAddress();
 
+    // Collection of expected locator addresses.
     final Set<String> locators = new HashSet<>();
-    locators.add(host + "["
-        + dunitLocator.substring(dunitLocator.indexOf("[") + 1, dunitLocator.indexOf("]")) + "]");
-    for (int port : ports) {
-      locators.add(host + "[" + port + "]");
-    }
-
+    // Starting 4 locators
+    MemberVM locator1 = clusterStartupRule.startLocatorVM(0);
+    int locator1Port = locator1.getPort();
+    locators.add(ipAddress + "[" + locator1Port + "]");
+
+    MemberVM locator2 =
+        clusterStartupRule.startLocatorVM(1, l -> l.withConnectionToLocator(locator1Port));
+    int locator2Port = locator2.getPort();
+    locators.add(ipAddress + "[" + locator2Port + "]");
+
+    MemberVM locator3 =
+        clusterStartupRule.startLocatorVM(2,
+            l -> l.withConnectionToLocator(locator1Port, locator2Port));
+    int locator3Port = locator3.getPort();
+    locators.add(ipAddress + "[" + locator3Port + "]");
+
+    MemberVM locator4 =
+        clusterStartupRule.startLocatorVM(3,
+            l -> l.withConnectionToLocator(locator1Port, locator2Port, locator3Port));
+    int locator4Port = locator4.getPort();
+    locators.add(ipAddress + "[" + locator4Port + "]");
+
+    MemberVM server1 =
+        clusterStartupRule.startServerVM(4,
+            s -> s.withConnectionToLocator(locator1Port, locator2Port, locator3Port, locator4Port));
     // validation within non-locator
-    final ClusterDistributionManager dm =
-        (ClusterDistributionManager) system.getDistributionManager();
-
-    final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-    assertEquals(5, locatorIds.size());
+    server1.invoke(() -> {
+      ClusterDistributionManager dm =
+          (ClusterDistributionManager) ClusterStartupRule.getCache().getDistributionManager();
+      final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
+
+      assertThat(locatorIds.size()).isEqualTo(4);
+      final Map<InternalDistributedMember, Collection<String>> hostedLocators =
+          dm.getAllHostedLocators();
+      assertThat(hostedLocators).isNotEmpty();
+      assertThat(hostedLocators.size()).isEqualTo(4);
+      for (InternalDistributedMember member : hostedLocators.keySet()) {
+        assertThat(hostedLocators.get(member).size()).isEqualTo(1);
+        final String hostedLocator = hostedLocators.get(member).iterator().next();
+        assertThat(locators).contains(hostedLocator);
+      }
+    });
+
+    // validations within the locators
+    locator1.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator2.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator3.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator4.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+  }
 
+  private void validateHostedLocators(Set<String> locators) {
+    ClusterDistributionManager dm =
+        (ClusterDistributionManager) ClusterStartupRule.getCache().getDistributionManager();
+    final InternalDistributedMember self = dm.getDistributionManagerId();
+    final Set<InternalDistributedMember> locatorIDs = dm.getLocatorDistributionManagerIds();
+    assertThat(locatorIDs.size()).isEqualTo(4);
+    assertThat(locatorIDs).contains(self);
     final Map<InternalDistributedMember, Collection<String>> hostedLocators =
         dm.getAllHostedLocators();
-    assertTrue(!hostedLocators.isEmpty());
-    assertEquals(5, hostedLocators.size());
-
+    assertThat(hostedLocators).isNotEmpty();
+    assertThat(hostedLocators.size()).isEqualTo(4);
+    assertThat(hostedLocators).containsKey(self);
     for (InternalDistributedMember member : hostedLocators.keySet()) {
-      assertEquals(1, hostedLocators.get(member).size());
+      assertThat(hostedLocators.get(member).size()).isEqualTo(1);
       final String hostedLocator = hostedLocators.get(member).iterator().next();
-      assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
+      assertThat(locators).contains(hostedLocator);
     }
+  }
 
-    // validate fix for #46324
-    for (int whichvm = 0; whichvm < 4; whichvm++) {
-      getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
-        @Override
-        public void run() {
-          final ClusterDistributionManager dm =
-              (ClusterDistributionManager) InternalDistributedSystem.getAnyInstance()
-                  .getDistributionManager();
-          final InternalDistributedMember self = dm.getDistributionManagerId();
-
-          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-          assertTrue(locatorIds.contains(self));
+  public static InetAddress getIPAddress() {
+    return Boolean.getBoolean("java.net.preferIPv6Addresses") ? getIPv6Address() : getIPv4Address();
+  }
 
-          final Map<InternalDistributedMember, Collection<String>> hostedLocators =
-              dm.getAllHostedLocators();
-          assertTrue(
-              "hit bug #46324: " + hostedLocators + " is missing "
-                  + InternalLocator.getLocatorStrings() + " for " + self,
-              hostedLocators.containsKey(self));
-        }
-      });
+  protected static InetAddress getIPv4Address() {

Review comment:
       make private

##########
File path: geode-core/src/distributedTest/java/org/apache/geode/distributed/HostedLocatorsDUnitTest.java
##########
@@ -54,277 +45,163 @@
  * @since GemFire 8.0
  */
 @Category({ClientServerTest.class})
-public class HostedLocatorsDUnitTest extends JUnit4DistributedTestCase {
-
-  protected static final int TIMEOUT_MILLISECONDS = 5 * 60 * 1000; // 5 minutes
-
-  protected transient volatile int locatorPort;
-  protected transient volatile LocatorLauncher launcher;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    disconnectAllFromDS();
-  }
+@SuppressWarnings("serial")
+public class HostedLocatorsDUnitTest implements Serializable {
 
-  private String getUniqueLocatorName() {
-    String uniqueLocatorName = Host.getHost(0).getHostName() + "_"
-        + getUniqueName();
-    return uniqueLocatorName;
-  }
+  @Rule
+  public ClusterStartupRule clusterStartupRule = new ClusterStartupRule();
 
   @Test
   public void testGetAllHostedLocators() throws Exception {
-    final InternalDistributedSystem system = getSystem();
-    final String dunitLocator = system.getConfig().getLocators();
-    assertNotNull(dunitLocator);
-    assertFalse(dunitLocator.isEmpty());
-
-    final int[] ports = getRandomAvailableTCPPorts(4);
-
-    final String uniqueName = getUniqueLocatorName();
-    for (int i = 0; i < 4; i++) {
-      final int whichvm = i;
-      getHost(0).getVM(whichvm).invoke(new SerializableCallable() {
-        @Override
-        public Object call() throws Exception {
-          final String name = uniqueName + "-" + whichvm;
-          final File subdir = new File(name);
-          if (subdir.exists()) {
-            FileUtils.deleteRecursively(subdir);
-          }
-          subdir.mkdir();
-          assertTrue(subdir.exists() && subdir.isDirectory());
-
-          final Builder builder = new Builder().setMemberName(name).setPort(ports[whichvm])
-              .set(LOCATORS, dunitLocator)
-              .setRedirectOutput(true).setWorkingDirectory(name);
-
-          launcher = builder.build();
-          assertEquals(Status.ONLINE, launcher.start().getStatus());
-          waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
-          return null;
-        }
-      });
-    }
-
-    final String host = LocalHostUtil.getLocalHost().getHostAddress();
+    // Get the localhost IP address
+    String ipAddress = getIPAddress().getHostAddress();
 
+    // Collection of expected locator addresses.
     final Set<String> locators = new HashSet<>();
-    locators.add(host + "["
-        + dunitLocator.substring(dunitLocator.indexOf("[") + 1, dunitLocator.indexOf("]")) + "]");
-    for (int port : ports) {
-      locators.add(host + "[" + port + "]");
-    }
-
+    // Starting 4 locators
+    MemberVM locator1 = clusterStartupRule.startLocatorVM(0);
+    int locator1Port = locator1.getPort();
+    locators.add(ipAddress + "[" + locator1Port + "]");
+
+    MemberVM locator2 =
+        clusterStartupRule.startLocatorVM(1, l -> l.withConnectionToLocator(locator1Port));
+    int locator2Port = locator2.getPort();
+    locators.add(ipAddress + "[" + locator2Port + "]");
+
+    MemberVM locator3 =
+        clusterStartupRule.startLocatorVM(2,
+            l -> l.withConnectionToLocator(locator1Port, locator2Port));
+    int locator3Port = locator3.getPort();
+    locators.add(ipAddress + "[" + locator3Port + "]");
+
+    MemberVM locator4 =
+        clusterStartupRule.startLocatorVM(3,
+            l -> l.withConnectionToLocator(locator1Port, locator2Port, locator3Port));
+    int locator4Port = locator4.getPort();
+    locators.add(ipAddress + "[" + locator4Port + "]");
+
+    MemberVM server1 =
+        clusterStartupRule.startServerVM(4,
+            s -> s.withConnectionToLocator(locator1Port, locator2Port, locator3Port, locator4Port));
     // validation within non-locator
-    final ClusterDistributionManager dm =
-        (ClusterDistributionManager) system.getDistributionManager();
-
-    final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-    assertEquals(5, locatorIds.size());
+    server1.invoke(() -> {
+      ClusterDistributionManager dm =
+          (ClusterDistributionManager) ClusterStartupRule.getCache().getDistributionManager();
+      final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
+
+      assertThat(locatorIds.size()).isEqualTo(4);
+      final Map<InternalDistributedMember, Collection<String>> hostedLocators =
+          dm.getAllHostedLocators();
+      assertThat(hostedLocators).isNotEmpty();
+      assertThat(hostedLocators.size()).isEqualTo(4);
+      for (InternalDistributedMember member : hostedLocators.keySet()) {
+        assertThat(hostedLocators.get(member).size()).isEqualTo(1);
+        final String hostedLocator = hostedLocators.get(member).iterator().next();
+        assertThat(locators).contains(hostedLocator);
+      }
+    });
+
+    // validations within the locators
+    locator1.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator2.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator3.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+    locator4.invoke(() -> {
+      validateHostedLocators(locators);
+    });
+  }
 
+  private void validateHostedLocators(Set<String> locators) {
+    ClusterDistributionManager dm =
+        (ClusterDistributionManager) ClusterStartupRule.getCache().getDistributionManager();
+    final InternalDistributedMember self = dm.getDistributionManagerId();
+    final Set<InternalDistributedMember> locatorIDs = dm.getLocatorDistributionManagerIds();
+    assertThat(locatorIDs.size()).isEqualTo(4);
+    assertThat(locatorIDs).contains(self);
     final Map<InternalDistributedMember, Collection<String>> hostedLocators =
         dm.getAllHostedLocators();
-    assertTrue(!hostedLocators.isEmpty());
-    assertEquals(5, hostedLocators.size());
-
+    assertThat(hostedLocators).isNotEmpty();
+    assertThat(hostedLocators.size()).isEqualTo(4);
+    assertThat(hostedLocators).containsKey(self);
     for (InternalDistributedMember member : hostedLocators.keySet()) {
-      assertEquals(1, hostedLocators.get(member).size());
+      assertThat(hostedLocators.get(member).size()).isEqualTo(1);
       final String hostedLocator = hostedLocators.get(member).iterator().next();
-      assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
+      assertThat(locators).contains(hostedLocator);
     }
+  }
 
-    // validate fix for #46324
-    for (int whichvm = 0; whichvm < 4; whichvm++) {
-      getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
-        @Override
-        public void run() {
-          final ClusterDistributionManager dm =
-              (ClusterDistributionManager) InternalDistributedSystem.getAnyInstance()
-                  .getDistributionManager();
-          final InternalDistributedMember self = dm.getDistributionManagerId();
-
-          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-          assertTrue(locatorIds.contains(self));
+  public static InetAddress getIPAddress() {
+    return Boolean.getBoolean("java.net.preferIPv6Addresses") ? getIPv6Address() : getIPv4Address();
+  }
 
-          final Map<InternalDistributedMember, Collection<String>> hostedLocators =
-              dm.getAllHostedLocators();
-          assertTrue(
-              "hit bug #46324: " + hostedLocators + " is missing "
-                  + InternalLocator.getLocatorStrings() + " for " + self,
-              hostedLocators.containsKey(self));
-        }
-      });
+  protected static InetAddress getIPv4Address() {
+    InetAddress host = null;
+    try {
+      host = InetAddress.getLocalHost();
+      if (host instanceof Inet4Address && !host.isLinkLocalAddress() && !host.isLoopbackAddress()) {
+        return host;
+      }
+    } catch (UnknownHostException e) {
+      String s = "Local host not found";
+      throw new RuntimeException(s, e);
     }
-
-    // validation with locators
-    for (int whichvm = 0; whichvm < 4; whichvm++) {
-      getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
-        @Override
-        public void run() {
-          final ClusterDistributionManager dm =
-              (ClusterDistributionManager) InternalDistributedSystem.getAnyInstance()
-                  .getDistributionManager();
-
-          final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
-          assertEquals(5, locatorIds.size());
-
-          final Map<InternalDistributedMember, Collection<String>> hostedLocators =
-              dm.getAllHostedLocators();
-          assertTrue(!hostedLocators.isEmpty());
-          assertEquals(5, hostedLocators.size());
-
-          for (InternalDistributedMember member : hostedLocators.keySet()) {
-            assertEquals(1, hostedLocators.get(member).size());
-            final String hostedLocator = hostedLocators.get(member).iterator().next();
-            assertTrue(locators + " does not contain " + hostedLocator,
-                locators.contains(hostedLocator));
+    try {
+      Enumeration i = NetworkInterface.getNetworkInterfaces();

Review comment:
       declare as `Enumeration<NetworkInterface> i` to eliminate the cast on line 156.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org