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/05/20 19:27:18 UTC

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

nabarunnag commented on code in PR #7303:
URL: https://github.com/apache/geode/pull/7303#discussion_r878485709


##########
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:
   All review comments have been addressed



##########
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:
   All review comments have been addressed



##########
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:
   All review comments have been addressed



-- 
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