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

orudyy pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git


The following commit(s) were added to refs/heads/7.0.x by this push:
     new 39536fc  QPID-8150 : Prevent test failures due to slow initialisation 
of hostname resolution in HostnameAliasImpl
39536fc is described below

commit 39536fcaa3b5cce0a97a77a2221990624bb1efc9
Author: Robert Godfrey <rgodf...@apache.org>
AuthorDate: Sat Mar 31 01:30:13 2018 +0200

    QPID-8150 : Prevent test failures due to slow initialisation of hostname 
resolution in HostnameAliasImpl
    
    (cherry picked from commit fa471435e76f21d3687ee964ba144f4e5dffb506)
---
 .../server/virtualhostalias/HostNameAliasImpl.java | 55 +++++++++++++++++++++-
 .../src/main/resources/config-protocol-tests.json  | 11 -----
 2 files changed, 54 insertions(+), 12 deletions(-)

diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/HostNameAliasImpl.java
 
b/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/HostNameAliasImpl.java
index ab6b930..9326c3c 100644
--- 
a/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/HostNameAliasImpl.java
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/HostNameAliasImpl.java
@@ -20,6 +20,7 @@
  */
 package org.apache.qpid.server.virtualhostalias;
 
+import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.net.InterfaceAddress;
 import java.net.NetworkInterface;
@@ -27,9 +28,11 @@ import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeSet;
 import java.util.concurrent.CopyOnWriteArraySet;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.locks.Lock;
@@ -80,6 +83,10 @@ public class HostNameAliasImpl
     @Override
     protected boolean matches(final String host)
     {
+        if(_localAddressNames.contains(host))
+        {
+            return true;
+        }
         while(!_addressesComputed.get())
         {
             Lock lock = _addressLock;
@@ -167,7 +174,7 @@ public class HostNameAliasImpl
 
         private Collection<InetAddress> getAllInetAddresses() throws 
SocketException
         {
-            Set<InetAddress> addresses = new HashSet<>();
+            Set<InetAddress> addresses = new 
TreeSet<>(HostNameAliasImpl::compareAddresses);
             for (NetworkInterface networkInterface : 
Collections.list(NetworkInterface.getNetworkInterfaces()))
             {
                 for (InterfaceAddress inetAddress : 
networkInterface.getInterfaceAddresses())
@@ -183,4 +190,50 @@ public class HostNameAliasImpl
     {
         return bindingAddress == null || bindingAddress.trim().equals("") || 
bindingAddress.trim().equals("*");
     }
+
+    private static int compareAddresses(final InetAddress left, final 
InetAddress right)
+    {
+        byte[] leftBytes;
+        byte[] rightBytes;
+        if(left.isLoopbackAddress() != right.isLoopbackAddress())
+        {
+            return left.isLoopbackAddress() ? -1 : 1;
+        }
+        else if(left.isSiteLocalAddress() != right.isSiteLocalAddress())
+        {
+            return left.isSiteLocalAddress() ? -1 : 1;
+        }
+        else if(left.isLinkLocalAddress() != right.isLinkLocalAddress())
+        {
+            return left.isLinkLocalAddress() ? 1 : -1;
+        }
+        else if(left.isMulticastAddress() != right.isMulticastAddress())
+        {
+            return left.isMulticastAddress() ? 1 : -1;
+        }
+        else if(left instanceof Inet4Address && !(right instanceof 
Inet4Address))
+        {
+            return -1;
+        }
+        else if(right instanceof Inet4Address && !(left instanceof 
Inet4Address))
+        {
+            return 1;
+        }
+        else if((leftBytes = left.getAddress()).length == (rightBytes = 
right.getAddress()).length)
+        {
+            for(int i = 0; i < left.getAddress().length; i++)
+            {
+                int compare = Byte.compare(leftBytes[i], rightBytes[i]);
+                if(compare != 0)
+                {
+                    return compare;
+                }
+            }
+            return 0;
+        }
+        else
+        {
+            return Integer.compare(left.getAddress().length, 
right.getAddress().length);
+        }
+    }
 }
diff --git 
a/systests/protocol-tests-amqp-1-0/src/main/resources/config-protocol-tests.json
 
b/systests/protocol-tests-amqp-1-0/src/main/resources/config-protocol-tests.json
index 764ff89..ca54cc4 100644
--- 
a/systests/protocol-tests-amqp-1-0/src/main/resources/config-protocol-tests.json
+++ 
b/systests/protocol-tests-amqp-1-0/src/main/resources/config-protocol-tests.json
@@ -48,9 +48,6 @@
       "name" : "defaultAlias",
       "type" : "defaultAlias"
     }, {
-      "name" : "hostnameAlias",
-      "type" : "hostnameAlias"
-    }, {
       "name" : "nameAlias",
       "type" : "nameAlias"
     } ]
@@ -65,10 +62,6 @@
       "type" : "defaultAlias",
       "durable" : true
     }, {
-      "name" : "hostnameAlias",
-      "type" : "hostnameAlias",
-      "durable" : true
-    }, {
       "name" : "nameAlias",
       "type" : "nameAlias",
       "durable" : true
@@ -85,10 +78,6 @@
       "type" : "defaultAlias",
       "durable" : true
     }, {
-      "name" : "hostnameAlias",
-      "type" : "hostnameAlias",
-      "durable" : true
-    }, {
       "name" : "nameAlias",
       "type" : "nameAlias",
       "durable" : true


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to