You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by mc...@apache.org on 2019/07/31 21:16:53 UTC

[geode] branch develop updated: GEODE-7029: More robust INetAddress retrieval for revocation

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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 671ba75  GEODE-7029: More robust INetAddress retrieval for revocation
671ba75 is described below

commit 671ba75cefeda953e393a43c86094704c9c8f79c
Author: Ryan McMahon <rm...@pivotal.io>
AuthorDate: Wed Jul 31 14:16:40 2019 -0700

    GEODE-7029: More robust INetAddress retrieval for revocation
---
 .../PersistentPartitionedRegionDistributedTest.java | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionDistributedTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionDistributedTest.java
index c1fe27a..7970cab 100644
--- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionDistributedTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/PersistentPartitionedRegionDistributedTest.java
@@ -36,7 +36,11 @@ import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.io.Serializable;
+import java.net.Inet4Address;
 import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.net.UnknownHostException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -366,7 +370,7 @@ public class PersistentPartitionedRegionDistributedTest implements Serializable
 
           try {
             adminDS.waitToBeConnected(MINUTES.toMillis(2));
-            adminDS.revokePersistentMember(InetAddress.getLocalHost(), null);
+            adminDS.revokePersistentMember(getFirstInet4Address(), null);
           } finally {
             adminDS.disconnect();
           }
@@ -390,7 +394,7 @@ public class PersistentPartitionedRegionDistributedTest implements Serializable
       adminDS.connect();
       try {
         adminDS.waitToBeConnected(MINUTES.toMillis(2));
-        adminDS.revokePersistentMember(InetAddress.getLocalHost(), diskDirPathOnVM1);
+        adminDS.revokePersistentMember(getFirstInet4Address(), diskDirPathOnVM1);
       } finally {
         adminDS.disconnect();
       }
@@ -1606,6 +1610,19 @@ public class PersistentPartitionedRegionDistributedTest implements Serializable
     }
   }
 
+  private static InetAddress getFirstInet4Address() throws SocketException, UnknownHostException {
+    for (NetworkInterface netint : Collections.list(NetworkInterface.getNetworkInterfaces())) {
+      for (InetAddress inetAddress : Collections.list(netint.getInetAddresses())) {
+        if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
+          return inetAddress;
+        }
+      }
+    }
+
+    // If no INet4Address was found for any of the interfaces above, default to getLocalHost()
+    return InetAddress.getLocalHost();
+  }
+
   private InternalCache getCache() {
     return cacheRule.getOrCreateCache();
   }