qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject qpid-jms git commit: QPIDJMS-57: update ErrorCondition 'info' usage to do lookups with Symbol keys
Date Thu, 28 May 2015 14:47:09 GMT
Repository: qpid-jms
Updated Branches:
  refs/heads/master 7e1325e9a -> db615570d


QPIDJMS-57: update ErrorCondition 'info' usage to do lookups with Symbol keys


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/db615570
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/db615570
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/db615570

Branch: refs/heads/master
Commit: db615570d703a78d08f40f844294c0ebc82e6524
Parents: 7e1325e
Author: Robert Gemmell <robbie@apache.org>
Authored: Thu May 28 15:46:16 2015 +0100
Committer: Robert Gemmell <robbie@apache.org>
Committed: Thu May 28 15:46:16 2015 +0100

----------------------------------------------------------------------
 .../jms/provider/amqp/AmqpAbstractResource.java | 12 +++++----
 .../qpid/jms/provider/amqp/AmqpSupport.java     |  6 +++++
 .../integration/ConnectionIntegrationTest.java  | 26 +++++++++++---------
 .../FailedConnectionsIntegrationTest.java       | 14 +++++++----
 .../provider/failover/FailoverRedirectTest.java | 22 +++++++++--------
 .../qpid/jms/test/testpeer/TestAmqpPeer.java    |  4 +--
 6 files changed, 51 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/db615570/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpAbstractResource.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpAbstractResource.java
b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpAbstractResource.java
index cc05312..a6d6764 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpAbstractResource.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpAbstractResource.java
@@ -16,6 +16,9 @@
  */
 package org.apache.qpid.jms.provider.amqp;
 
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.NETWORK_HOST;
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.OPEN_HOSTNAME;
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.PORT;
 import static org.apache.qpid.jms.provider.amqp.AmqpSupport.CONTAINER_ID;
 import static org.apache.qpid.jms.provider.amqp.AmqpSupport.INVALID_FIELD;
 
@@ -344,24 +347,23 @@ public abstract class AmqpAbstractResource<R extends JmsResource,
E extends Endp
      *
      * @return an Exception that captures the details of the redirection error.
      */
-    @SuppressWarnings("unchecked")
     protected Exception createRedirectException(Symbol error, String message, ErrorCondition
condition) {
         Exception result = null;
-        Map<Object, Object> info = condition.getInfo();
+        Map<?, ?> info = condition.getInfo();
 
         if (info == null) {
             result = new IOException(message + " : Redirection information not set.");
         } else {
-            String hostname = (String) info.get("hostname");
+            String hostname = (String) info.get(OPEN_HOSTNAME);
 
-            String networkHost = (String) info.get("network-host");
+            String networkHost = (String) info.get(NETWORK_HOST);
             if (networkHost == null || networkHost.isEmpty()) {
                 result = new IOException(message + " : Redirection information not set.");
             }
 
             int port = 0;
             try {
-                port = Integer.valueOf(info.get("port").toString());
+                port = Integer.valueOf(info.get(PORT).toString());
             } catch (Exception ex) {
                 result = new IOException(message + " : Redirection information not set.");
             }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/db615570/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
index 33b2c58..2dce4ca 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
@@ -28,6 +28,12 @@ public class AmqpSupport {
     public static final Symbol INVALID_FIELD = Symbol.valueOf("invalid-field");
     public static final Symbol CONTAINER_ID = Symbol.valueOf("container-id");
 
+    // Symbols used to announce connection redirect ErrorCondition 'info'
+    public static final Symbol PORT = Symbol.valueOf("port");
+    public static final Symbol NETWORK_HOST = Symbol.valueOf("network-host");
+    public static final Symbol OPEN_HOSTNAME = Symbol.valueOf("hostname");
+
+    // Symbols used for connection properties
     public static final Symbol QUEUE_PREFIX = Symbol.valueOf("queue-prefix");
     public static final Symbol TOPIC_PREFIX = Symbol.valueOf("topic-prefix");
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/db615570/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java
index 1ea529a..9e2e998 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java
@@ -20,6 +20,9 @@
  */
 package org.apache.qpid.jms.integration;
 
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.NETWORK_HOST;
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.OPEN_HOSTNAME;
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.PORT;
 import static org.hamcrest.Matchers.arrayContaining;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -53,6 +56,7 @@ import org.apache.qpid.jms.test.testpeer.TestAmqpPeer;
 import org.apache.qpid.jms.test.testpeer.basictypes.AmqpError;
 import org.apache.qpid.jms.test.testpeer.basictypes.ConnectionError;
 import org.apache.qpid.jms.test.testpeer.matchers.CoordinatorMatcher;
+import org.apache.qpid.proton.amqp.Symbol;
 import org.apache.qpid.proton.amqp.transaction.TxnCapability;
 import org.junit.Test;
 
@@ -151,7 +155,7 @@ public class ConnectionIntegrationTest extends QpidJmsTestCase {
         try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
             final String remoteURI = "amqp://localhost:" + testPeer.getServerPort();
 
-            Map<Object, Object> errorInfo = new HashMap<Object, Object>();
+            Map<Symbol, Object> errorInfo = new HashMap<Symbol, Object>();
             errorInfo.put(AmqpSupport.INVALID_FIELD, AmqpSupport.CONTAINER_ID);
 
             testPeer.rejectConnect(AmqpError.INVALID_FIELD, "Client ID already in use", errorInfo);
@@ -176,18 +180,18 @@ public class ConnectionIntegrationTest extends QpidJmsTestCase {
             final CountDownLatch done = new CountDownLatch(1);
             final AtomicReference<JMSException> asyncError = new AtomicReference<JMSException>();
 
-            final String REDIRECTED_HOSTNAME = "vhost";
-            final String REDIRECTED_NETWORK_HOST = "localhost";
-            final int REDIRECTED_PORT = 5677;
+            final String redirectVhost = "vhost";
+            final String redirectNetworkHost = "localhost";
+            final int redirectPort = 5677;
 
             // Don't set a ClientId, so that the underlying AMQP connection isn't established
yet
             Connection connection = testFixture.establishConnecton(testPeer, false, null,
null, null, false);
 
             // Tell the test peer to close the connection when executing its last handler
-            Map<Object, Object> errorInfo = new HashMap<Object, Object>();
-            errorInfo.put("hostname", REDIRECTED_HOSTNAME);
-            errorInfo.put("network-host", REDIRECTED_NETWORK_HOST);
-            errorInfo.put("port", 5677);
+            Map<Symbol, Object> errorInfo = new HashMap<Symbol, Object>();
+            errorInfo.put(OPEN_HOSTNAME, redirectVhost);
+            errorInfo.put(NETWORK_HOST, redirectNetworkHost);
+            errorInfo.put(PORT, 5677);
 
             testPeer.remotelyCloseConnection(true, ConnectionError.REDIRECT, "Connection
redirected", errorInfo);
 
@@ -210,9 +214,9 @@ public class ConnectionIntegrationTest extends QpidJmsTestCase {
             assertTrue(asyncError.get().getCause() instanceof ProviderRedirectedException);
 
             ProviderRedirectedException redirect = (ProviderRedirectedException) asyncError.get().getCause();
-            assertEquals(REDIRECTED_HOSTNAME, redirect.getHostname());
-            assertEquals(REDIRECTED_NETWORK_HOST, redirect.getNetworkHost());
-            assertEquals(REDIRECTED_PORT, redirect.getPort());
+            assertEquals(redirectVhost, redirect.getHostname());
+            assertEquals(redirectNetworkHost, redirect.getNetworkHost());
+            assertEquals(redirectPort, redirect.getPort());
 
             testPeer.waitForAllHandlersToComplete(1000);
         }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/db615570/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/FailedConnectionsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/FailedConnectionsIntegrationTest.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/FailedConnectionsIntegrationTest.java
index f0208ea..bf91902 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/FailedConnectionsIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/FailedConnectionsIntegrationTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.qpid.jms.integration;
 
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.NETWORK_HOST;
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.OPEN_HOSTNAME;
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.PORT;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -34,6 +37,7 @@ import org.apache.qpid.jms.test.QpidJmsTestCase;
 import org.apache.qpid.jms.test.testpeer.TestAmqpPeer;
 import org.apache.qpid.jms.test.testpeer.basictypes.AmqpError;
 import org.apache.qpid.jms.test.testpeer.basictypes.ConnectionError;
+import org.apache.qpid.proton.amqp.Symbol;
 import org.junit.Test;
 
 /**
@@ -76,11 +80,11 @@ public class FailedConnectionsIntegrationTest extends QpidJmsTestCase
{
 
     @Test(timeout = 5000)
     public void testConnectWithRedirect() throws Exception {
-        Map<Object, Object> redirectInfo = new HashMap<Object, Object>();
+        Map<Symbol, Object> redirectInfo = new HashMap<Symbol, Object>();
 
-        redirectInfo.put("hostname", "localhost");
-        redirectInfo.put("network-host", "127.0.0.1");
-        redirectInfo.put("port", 5672);
+        redirectInfo.put(OPEN_HOSTNAME, "vhost");
+        redirectInfo.put(NETWORK_HOST, "127.0.0.1");
+        redirectInfo.put(PORT, 5672);
 
         try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
             testPeer.rejectConnect(ConnectionError.REDIRECT, "Server is full, go away", redirectInfo);
@@ -90,7 +94,7 @@ public class FailedConnectionsIntegrationTest extends QpidJmsTestCase {
             } catch (JMSException jmsex) {
                 assertTrue(jmsex.getCause() instanceof ProviderRedirectedException);
                 ProviderRedirectedException redirectEx = (ProviderRedirectedException) jmsex.getCause();
-                assertEquals("localhost", redirectEx.getHostname());
+                assertEquals("vhost", redirectEx.getHostname());
                 assertEquals("127.0.0.1", redirectEx.getNetworkHost());
                 assertEquals(5672, redirectEx.getPort());
             } catch (Exception ex) {

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/db615570/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverRedirectTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverRedirectTest.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverRedirectTest.java
index f6d7f5a..b0fb1da 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverRedirectTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverRedirectTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.qpid.jms.provider.failover;
 
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.NETWORK_HOST;
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.OPEN_HOSTNAME;
+import static org.apache.qpid.jms.provider.amqp.AmqpSupport.PORT;
 import static org.junit.Assert.assertTrue;
 
 import java.net.URI;
@@ -34,6 +37,7 @@ import org.apache.qpid.jms.JmsDefaultConnectionListener;
 import org.apache.qpid.jms.test.QpidJmsTestCase;
 import org.apache.qpid.jms.test.testpeer.TestAmqpPeer;
 import org.apache.qpid.jms.test.testpeer.basictypes.ConnectionError;
+import org.apache.qpid.proton.amqp.Symbol;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -59,11 +63,10 @@ public class FailoverRedirectTest extends QpidJmsTestCase {
             redirectedPeer.expectAnonymousConnect(true);
             redirectedPeer.expectBegin(true);
 
-            Map<Object, Object> redirectInfo = new HashMap<Object, Object>();
-
-            redirectInfo.put("hostname", "localhost");
-            redirectInfo.put("network-host", "localhost");
-            redirectInfo.put("port", redirectedPeer.getServerPort());
+            Map<Symbol, Object> redirectInfo = new HashMap<Symbol, Object>();
+            redirectInfo.put(OPEN_HOSTNAME, "localhost");
+            redirectInfo.put(NETWORK_HOST, "localhost");
+            redirectInfo.put(PORT, redirectedPeer.getServerPort());
 
             rejectingPeer.rejectConnect(ConnectionError.REDIRECT, "Server is full, go away",
redirectInfo);
 
@@ -103,11 +106,10 @@ public class FailoverRedirectTest extends QpidJmsTestCase {
             redirectedPeer.expectAnonymousConnect(true);
             redirectedPeer.expectBegin(true);
 
-            Map<Object, Object> redirectInfo = new HashMap<Object, Object>();
-
-            redirectInfo.put("hostname", "localhost");
-            redirectInfo.put("network-host", "localhost");
-            redirectInfo.put("port", redirectedPeer.getServerPort());
+            Map<Symbol, Object> redirectInfo = new HashMap<Symbol, Object>();
+            redirectInfo.put(OPEN_HOSTNAME, "localhost");
+            redirectInfo.put(NETWORK_HOST, "localhost");
+            redirectInfo.put(PORT, redirectedPeer.getServerPort());
 
             rejectingPeer.expectAnonymousConnect(true);
             rejectingPeer.expectBegin(true);

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/db615570/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
index 684ff5b..a2f0c79 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
@@ -519,7 +519,7 @@ public class TestAmqpPeer implements AutoCloseable
     }
 
     // TODO - Reject any incoming connection using the supplied information
-    public void rejectConnect(Symbol errorType, String errorMessage, Map<Object, Object>
errorInfo) {
+    public void rejectConnect(Symbol errorType, String errorMessage, Map<Symbol, Object>
errorInfo) {
         SaslMechanismsFrame saslMechanismsFrame = new SaslMechanismsFrame().setSaslServerMechanisms(Symbol.valueOf("ANONYMOUS"));
         addHandler(new HeaderHandlerImpl(AmqpHeader.SASL_HEADER, AmqpHeader.SASL_HEADER,
                                             new FrameSender(
@@ -1399,7 +1399,7 @@ public class TestAmqpPeer implements AutoCloseable
         remotelyCloseConnection(expectCloseResponse, errorType, errorMessage, null);
     }
 
-    public void remotelyCloseConnection(boolean expectCloseResponse, Symbol errorType, String
errorMessage, Map<Object, Object> info) {
+    public void remotelyCloseConnection(boolean expectCloseResponse, Symbol errorType, String
errorMessage, Map<Symbol, Object> info) {
         synchronized (_handlersLock) {
             // Prepare a composite to insert this action at the end of the handler sequence
             CompositeAmqpPeerRunnable comp = insertCompsiteActionForLastHandler();


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


Mime
View raw message