You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2018/03/30 23:32:53 UTC
qpid-broker-j git commit: QPID-8150 : Prevent test failures due to
slow initialisation of hostname resolution in HostnameAliasImpl
Repository: qpid-broker-j
Updated Branches:
refs/heads/master eef93a82a -> fa471435e
QPID-8150 : Prevent test failures due to slow initialisation of hostname resolution in HostnameAliasImpl
Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/fa471435
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/fa471435
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/fa471435
Branch: refs/heads/master
Commit: fa471435e76f21d3687ee964ba144f4e5dffb506
Parents: eef93a8
Author: Robert Godfrey <rg...@apache.org>
Authored: Sat Mar 31 01:30:13 2018 +0200
Committer: Robert Godfrey <rg...@apache.org>
Committed: Sat Mar 31 01:30:44 2018 +0200
----------------------------------------------------------------------
.../virtualhostalias/HostNameAliasImpl.java | 55 +++++++++++++++++++-
.../resources/config-protocol-tests-0-8.json | 8 +--
.../main/resources/config-protocol-tests.json | 11 ----
3 files changed, 55 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/fa471435/broker-core/src/main/java/org/apache/qpid/server/virtualhostalias/HostNameAliasImpl.java
----------------------------------------------------------------------
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 a3b100d..16a904b 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;
@@ -79,6 +82,10 @@ public class HostNameAliasImpl
@Override
protected boolean matches(final String host)
{
+ if(_localAddressNames.contains(host))
+ {
+ return true;
+ }
while(!_addressesComputed.get())
{
Lock lock = _addressLock;
@@ -166,7 +173,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())
@@ -182,4 +189,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);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/fa471435/systests/protocol-tests-amqp-0-8/src/main/resources/config-protocol-tests-0-8.json
----------------------------------------------------------------------
diff --git a/systests/protocol-tests-amqp-0-8/src/main/resources/config-protocol-tests-0-8.json b/systests/protocol-tests-amqp-0-8/src/main/resources/config-protocol-tests-0-8.json
index d3738c9..791d9ef 100644
--- a/systests/protocol-tests-amqp-0-8/src/main/resources/config-protocol-tests-0-8.json
+++ b/systests/protocol-tests-amqp-0-8/src/main/resources/config-protocol-tests-0-8.json
@@ -43,14 +43,12 @@
"type" : "AMQP",
"authenticationProvider" : "plain",
"port" : "0",
+ "bindingAddresss" : "127.0.0.1",
"protocols" : [ "AMQP_0_8", "AMQP_0_9", "AMQP_0_9_1" ],
"virtualhostaliases" : [ {
"name" : "defaultAlias",
"type" : "defaultAlias"
}, {
- "name" : "hostnameAlias",
- "type" : "hostnameAlias"
- }, {
"name" : "nameAlias",
"type" : "nameAlias"
} ]
@@ -65,10 +63,6 @@
"type" : "defaultAlias",
"durable" : true
}, {
- "name" : "hostnameAlias",
- "type" : "hostnameAlias",
- "durable" : true
- }, {
"name" : "nameAlias",
"type" : "nameAlias",
"durable" : true
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/fa471435/systests/protocol-tests-amqp-1-0/src/main/resources/config-protocol-tests.json
----------------------------------------------------------------------
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-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org