You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2015/06/16 16:01:23 UTC
[4/6] qpid-jms git commit: NO-JIRA: consolidate the ANONYMOUS
connection handling
NO-JIRA: consolidate the ANONYMOUS connection handling
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/848b1000
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/848b1000
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/848b1000
Branch: refs/heads/master
Commit: 848b100046ab2f8517b0111d5684f909e3d18e7f
Parents: 680fe88
Author: Robert Gemmell <ro...@apache.org>
Authored: Tue Jun 16 11:34:55 2015 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Tue Jun 16 11:34:55 2015 +0100
----------------------------------------------------------------------
.../integration/ConnectionIntegrationTest.java | 2 +-
.../integration/IdleTimeoutIntegrationTest.java | 12 +--
.../jms/integration/SaslIntegrationTest.java | 2 +-
.../provider/failover/FailoverRedirectTest.java | 6 +-
.../qpid/jms/test/testpeer/TestAmqpPeer.java | 107 +++++++------------
5 files changed, 50 insertions(+), 79 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/848b1000/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 afc7f72..b2166ac 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
@@ -142,7 +142,7 @@ public class ConnectionIntegrationTest extends QpidJmsTestCase {
private void doAmqpHostnameTestImpl(String amqpHostname, boolean setHostnameOption, Matcher<?> hostnameMatcher) throws JMSException, InterruptedException, Exception, IOException {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
- testPeer.expectAnonymousConnect(null, hostnameMatcher);
+ testPeer.expectSaslAnonymousConnect(null, hostnameMatcher);
// Each connection creates a session for managing temporary destinations etc
testPeer.expectBegin(true);
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/848b1000/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/IdleTimeoutIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/IdleTimeoutIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/IdleTimeoutIntegrationTest.java
index 67b326a..b796226 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/IdleTimeoutIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/IdleTimeoutIntegrationTest.java
@@ -52,7 +52,7 @@ public class IdleTimeoutIntegrationTest extends QpidJmsTestCase {
@Test(timeout = 5000)
public void testIdleTimeoutIsAdvertisedByDefault() throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
- testPeer.expectAnonymousConnect(greaterThan(UnsignedInteger.valueOf(0)), null);
+ testPeer.expectSaslAnonymousConnect(greaterThan(UnsignedInteger.valueOf(0)), null);
// Each connection creates a session for managing temporary destinations etc
testPeer.expectBegin(true);
@@ -75,7 +75,7 @@ public class IdleTimeoutIntegrationTest extends QpidJmsTestCase {
int configuredTimeout = 54320;
int advertisedValue = configuredTimeout / 2;
- testPeer.expectAnonymousConnect(equalTo(UnsignedInteger.valueOf(advertisedValue)), null);
+ testPeer.expectSaslAnonymousConnect(equalTo(UnsignedInteger.valueOf(advertisedValue)), null);
// Each connection creates a session for managing temporary destinations etc
testPeer.expectBegin(true);
@@ -101,7 +101,7 @@ public class IdleTimeoutIntegrationTest extends QpidJmsTestCase {
testPeer.setAdvertisedIdleTimeout(advertisedTimeout);
- testPeer.expectAnonymousConnect();
+ testPeer.expectSaslAnonymousConnect();
// Each connection creates a session for managing temporary destinations etc
testPeer.expectBegin(true);
@@ -139,7 +139,7 @@ public class IdleTimeoutIntegrationTest extends QpidJmsTestCase {
testPeer.setAdvertisedIdleTimeout(advertisedTimeout);
- testPeer.expectAnonymousConnect();
+ testPeer.expectSaslAnonymousConnect();
// Each connection creates a session for managing temporary destinations etc
testPeer.expectBegin(true);
@@ -168,7 +168,7 @@ public class IdleTimeoutIntegrationTest extends QpidJmsTestCase {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
int configuredTimeout = 200;
- testPeer.expectAnonymousConnect();
+ testPeer.expectSaslAnonymousConnect();
// Each connection creates a session for managing temporary destinations etc
testPeer.expectBegin(true);
@@ -203,7 +203,7 @@ public class IdleTimeoutIntegrationTest extends QpidJmsTestCase {
final CountDownLatch latch = new CountDownLatch(cycles);
- testPeer.expectAnonymousConnect();
+ testPeer.expectSaslAnonymousConnect();
// Each connection creates a session for managing temporary destinations etc
testPeer.expectBegin(true);
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/848b1000/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SaslIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SaslIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SaslIntegrationTest.java
index 9696a26..a18f2d2 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SaslIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SaslIntegrationTest.java
@@ -114,7 +114,7 @@ public class SaslIntegrationTest extends QpidJmsTestCase {
public void testSaslAnonymousConnection() throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
// Expect an ANOYMOUS connection
- testPeer.expectAnonymousConnect();
+ testPeer.expectSaslAnonymousConnect();
// Each connection creates a session for managing temporary destinations etc
testPeer.expectBegin(true);
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/848b1000/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 ba74564..8b3baeb 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
@@ -60,7 +60,7 @@ public class FailoverRedirectTest extends QpidJmsTestCase {
final String redirectURI = createPeerURI(redirectedPeer);
LOG.info("Backup peer is at: {}", redirectURI);
- redirectedPeer.expectAnonymousConnect();
+ redirectedPeer.expectSaslAnonymousConnect();
redirectedPeer.expectBegin(true);
Map<Symbol, Object> redirectInfo = new HashMap<Symbol, Object>();
@@ -103,7 +103,7 @@ public class FailoverRedirectTest extends QpidJmsTestCase {
final String redirectURI = createPeerURI(redirectedPeer);
LOG.info("Primary is at {}: Backup peer is at: {}", rejectingURI, redirectURI);
- redirectedPeer.expectAnonymousConnect();
+ redirectedPeer.expectSaslAnonymousConnect();
redirectedPeer.expectBegin(true);
Map<Symbol, Object> redirectInfo = new HashMap<Symbol, Object>();
@@ -111,7 +111,7 @@ public class FailoverRedirectTest extends QpidJmsTestCase {
redirectInfo.put(NETWORK_HOST, "localhost");
redirectInfo.put(PORT, redirectedPeer.getServerPort());
- rejectingPeer.expectAnonymousConnect();
+ rejectingPeer.expectSaslAnonymousConnect();
rejectingPeer.expectBegin(true);
rejectingPeer.remotelyCloseConnection(true, ConnectionError.REDIRECT, "Server is full, go away", redirectInfo);
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/848b1000/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 d6afef0..29a0634 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
@@ -96,6 +96,7 @@ import org.slf4j.LoggerFactory;
// TODO should expectXXXYYYZZZ methods just be expect(matcher)?
public class TestAmqpPeer implements AutoCloseable
{
+ private static final Symbol ANONYMOUS = Symbol.valueOf("ANONYMOUS");
private static final Symbol EXTERNAL = Symbol.valueOf("EXTERNAL");
private static final Symbol PLAIN = Symbol.valueOf("PLAIN");
private static final Logger LOGGER = LoggerFactory.getLogger(TestAmqpPeer.class.getName());
@@ -366,7 +367,8 @@ public class TestAmqpPeer implements AutoCloseable
return openFrame;
}
- public void expectSaslConnect(Symbol mechanism, Matcher<Binary> initialResponseMatcher, Symbol[] desiredCapabilities, Symbol[] serverCapabilities, Map<Symbol, Object> serverProperties)
+ public void expectSaslConnect(Symbol mechanism, Matcher<Binary> initialResponseMatcher, Symbol[] desiredCapabilities, Symbol[] serverCapabilities,
+ Map<Symbol, Object> serverProperties, Matcher<?> idleTimeoutMatcher, Matcher<?> hostnameMatcher)
{
SaslMechanismsFrame saslMechanismsFrame = new SaslMechanismsFrame().setSaslServerMechanisms(mechanism);
addHandler(new HeaderHandlerImpl(AmqpHeader.SASL_HEADER, AmqpHeader.SASL_HEADER,
@@ -374,7 +376,7 @@ public class TestAmqpPeer implements AutoCloseable
this, FrameType.SASL, 0,
saslMechanismsFrame, null)));
- addHandler(new SaslInitMatcher()
+ SaslInitMatcher saslInitMatcher = new SaslInitMatcher()
.withMechanism(equalTo(mechanism))
.withInitialResponse(initialResponseMatcher)
.onSuccess(new AmqpPeerRunnable()
@@ -387,9 +389,19 @@ public class TestAmqpPeer implements AutoCloseable
new SaslOutcomeFrame().setCode(UnsignedByte.valueOf((byte)0)),
null,
false);
+
+ // Now that we processed the SASL layer AMQP header, reset the
+ // peer to expect the non-SASL AMQP header.
_driverRunnable.expectHeader();
}
- }));
+ });
+
+ if(hostnameMatcher != null)
+ {
+ saslInitMatcher.withHostname(hostnameMatcher);
+ }
+
+ addHandler(saslInitMatcher);
addHandler(new HeaderHandlerImpl(AmqpHeader.HEADER, AmqpHeader.HEADER));
@@ -420,6 +432,16 @@ public class TestAmqpPeer implements AutoCloseable
openMatcher.withDesiredCapabilities(nullValue());
}
+ if(idleTimeoutMatcher !=null)
+ {
+ openMatcher.withIdleTimeOut(idleTimeoutMatcher);
+ }
+
+ if(hostnameMatcher != null)
+ {
+ openMatcher.withHostname(hostnameMatcher);
+ }
+
addHandler(openMatcher);
}
@@ -438,7 +460,7 @@ public class TestAmqpPeer implements AutoCloseable
Matcher<Binary> initialResponseMatcher = equalTo(new Binary(data));
- expectSaslConnect(PLAIN, initialResponseMatcher, desiredCapabilities, serverCapabilities, serverProperties);
+ expectSaslConnect(PLAIN, initialResponseMatcher, desiredCapabilities, serverCapabilities, serverProperties, null, null);
}
public void expectSaslExternalConnect()
@@ -448,7 +470,17 @@ public class TestAmqpPeer implements AutoCloseable
throw new IllegalStateException("need-client-cert must be enabled on the test peer");
}
- expectSaslConnect(EXTERNAL, equalTo(new Binary(new byte[0])), new Symbol[] { AmqpSupport.SOLE_CONNECTION_CAPABILITY }, null, null);
+ expectSaslConnect(EXTERNAL, equalTo(new Binary(new byte[0])), new Symbol[] { AmqpSupport.SOLE_CONNECTION_CAPABILITY }, null, null, null, null);
+ }
+
+ public void expectSaslAnonymousConnect()
+ {
+ expectSaslAnonymousConnect(null, null);
+ }
+
+ public void expectSaslAnonymousConnect(Matcher<?> idleTimeoutMatcher, Matcher<?> hostnameMatcher)
+ {
+ expectSaslConnect(ANONYMOUS, equalTo(new Binary(new byte[0])), new Symbol[] { AmqpSupport.SOLE_CONNECTION_CAPABILITY }, null, null, idleTimeoutMatcher, hostnameMatcher);
}
public void expectFailingSaslConnect(Symbol[] serverMechs, Symbol clientSelectedMech)
@@ -497,77 +529,16 @@ public class TestAmqpPeer implements AutoCloseable
addHandler(openMatcher);
}
- public void expectAnonymousConnect()
- {
- expectAnonymousConnect(null, null);
- }
-
- public void expectAnonymousConnect(Matcher<?> idleTimeoutMatcher, Matcher<?> hostnameMatcher)
- {
- SaslMechanismsFrame saslMechanismsFrame = new SaslMechanismsFrame().setSaslServerMechanisms(Symbol.valueOf("ANONYMOUS"));
- addHandler(new HeaderHandlerImpl(AmqpHeader.SASL_HEADER, AmqpHeader.SASL_HEADER,
- new FrameSender(
- this, FrameType.SASL, 0,
- saslMechanismsFrame, null)));
-
- SaslInitMatcher saslInitMatcher = new SaslInitMatcher()
- .withMechanism(equalTo(Symbol.valueOf("ANONYMOUS")))
- .withInitialResponse(equalTo(new Binary(new byte[0])))
- .onSuccess(new AmqpPeerRunnable()
- {
- @Override
- public void run()
- {
- TestAmqpPeer.this.sendFrame(
- FrameType.SASL, 0,
- new SaslOutcomeFrame().setCode(UnsignedByte.valueOf((byte)0)),
- null,
- false);
- _driverRunnable.expectHeader();
- }
- });
-
- if(hostnameMatcher != null)
- {
- saslInitMatcher.withHostname(hostnameMatcher);
- }
-
- addHandler(saslInitMatcher);
-
- addHandler(new HeaderHandlerImpl(AmqpHeader.HEADER, AmqpHeader.HEADER));
-
- OpenFrame openFrame = createOpenFrame();
-
- OpenMatcher openMatcher = new OpenMatcher()
- .withContainerId(notNullValue(String.class))
- .onSuccess(new FrameSender(
- this, FrameType.AMQP, 0,
- openFrame,
- null));
-
- if(idleTimeoutMatcher !=null)
- {
- openMatcher.withIdleTimeOut(idleTimeoutMatcher);
- }
-
- if(hostnameMatcher != null)
- {
- openMatcher.withHostname(hostnameMatcher);
- }
-
- addHandler(openMatcher);
- }
-
// TODO - Reject any incoming connection using the supplied information
public void rejectConnect(Symbol errorType, String errorMessage, Map<Symbol, Object> errorInfo) {
- SaslMechanismsFrame saslMechanismsFrame = new SaslMechanismsFrame().setSaslServerMechanisms(Symbol.valueOf("ANONYMOUS"));
+ SaslMechanismsFrame saslMechanismsFrame = new SaslMechanismsFrame().setSaslServerMechanisms(ANONYMOUS);
addHandler(new HeaderHandlerImpl(AmqpHeader.SASL_HEADER, AmqpHeader.SASL_HEADER,
new FrameSender(
this, FrameType.SASL, 0,
saslMechanismsFrame, null)));
addHandler(new SaslInitMatcher()
- .withMechanism(equalTo(Symbol.valueOf("ANONYMOUS")))
+ .withMechanism(equalTo(ANONYMOUS))
.withInitialResponse(equalTo(new Binary(new byte[0])))
.onSuccess(new AmqpPeerRunnable()
{
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org