diff options
| author | Aidan Skinner <aidan@apache.org> | 2009-09-16 10:06:55 +0000 |
|---|---|---|
| committer | Aidan Skinner <aidan@apache.org> | 2009-09-16 10:06:55 +0000 |
| commit | 9c4ecc45da929750ff7f0e0a5d7ada4e674b9105 (patch) | |
| tree | 3834f1b7f1fe3fbdd632a9c78f6295e54595abc5 /qpid/java/systests | |
| parent | c1ebe66bfab328c5192a35c21ea290b5c45f40f5 (diff) | |
| download | qpid-python-9c4ecc45da929750ff7f0e0a5d7ada4e674b9105.tar.gz | |
QPID-2105: Make NetworkDriver.open use a SSLContextFactory, not an SSLEngine.
Allow an existing SocketConnector to be passed into a MINANetworkDriver, for
use with the ExistingSocket bit of TransportConnection.
Move the ExistingSocket stuff to one place, use MINANetworkDriver in
TransportConnection and make AMQProtocolHandler implement ProtocolEngine. Remove MINA specific gubbins from AMQProtocolHandler and AMQProtocolSession.
Move fireAsynchEvent to Job
Add getLocalAddress to AMQProtocolEngine
Move TestNetworkDriver to common
Use correct class for logger in AMQProtocolEngine
Check the exception is thrown properly in SimpleACLTest, make it a little less
prone to obscure race conditions.
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/java-network-refactor@815704 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/systests')
3 files changed, 50 insertions, 35 deletions
diff --git a/qpid/java/systests/build.xml b/qpid/java/systests/build.xml index ac3c77e4a3..34a360ecad 100644 --- a/qpid/java/systests/build.xml +++ b/qpid/java/systests/build.xml @@ -20,7 +20,7 @@ nn - or more contributor license agreements. See the NOTICE file --> <project name="System Tests" default="build"> - <property name="module.depends" value="client management/tools/qpid-cli management/eclipse-plugin management/common broker broker/test common junit-toolkit"/> + <property name="module.depends" value="client management/tools/qpid-cli management/eclipse-plugin management/common broker broker/test common common/test nt junit-toolkit"/> <property name="module.test.src" location="src/main/java"/> <property name="module.test.excludes" value="**/TTLTest.java,**/DropInTest.java,**/TestClientControlledTest.java"/> diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java index b5c0a87b0f..f402522a19 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/SimpleACLTest.java @@ -22,6 +22,9 @@ package org.apache.qpid.server.security.acl; import junit.framework.TestCase; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Logger; import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.*; import org.apache.qpid.framing.AMQShortString; @@ -34,11 +37,17 @@ import org.apache.qpid.url.URLSyntaxException; import javax.jms.*; import javax.jms.IllegalStateException; + import java.io.File; +import java.util.ArrayList; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; -public class SimpleACLTest extends QpidTestCase implements ConnectionListener +public class SimpleACLTest extends QpidTestCase implements ConnectionListener, ExceptionListener { private String BROKER = "vm://:"+ApplicationRegistry.DEFAULT_INSTANCE;//"tcp://localhost:5672"; + private ArrayList<Exception> _thrownExceptions = new ArrayList<Exception>(); + private CountDownLatch _awaitError = new CountDownLatch(51); public void setUp() throws Exception { @@ -268,7 +277,7 @@ public class SimpleACLTest extends QpidTestCase implements ConnectionListener } } - public void testClientPublishInvalidQueueSuccess() throws AMQException, URLSyntaxException, JMSException + public void testClientPublishInvalidQueueSuccess() throws AMQException, URLSyntaxException, JMSException, InterruptedException { try { @@ -276,41 +285,38 @@ public class SimpleACLTest extends QpidTestCase implements ConnectionListener ((AMQConnection) conn).setConnectionListener(this); - Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + Session session = conn.createSession(true, Session.AUTO_ACKNOWLEDGE); conn.start(); - + conn.setExceptionListener(this); MessageProducer sender = ((AMQSession) session).createProducer(null); - Queue queue = session.createQueue("Invalid"); - + Queue queue = session.createQueue("NewQueueThatIDoNotHaveRightsToPublishToo"); + // Send a message that we will wait to be sent, this should give the broker time to close the connection // before we finish this test. Message is set !immed !mand as the queue is invalid so want to test ACLs not // queue existence. ((org.apache.qpid.jms.MessageProducer) sender).send(queue, session.createTextMessage("test"), DeliveryMode.NON_PERSISTENT, 0, 0L, false, false, true); - // Test the connection with a valid consumer - // This may fail as the session may be closed before the queue or the consumer created. - Queue temp = session.createTemporaryQueue(); - - session.createConsumer(temp).close(); - - //Connection should now be closed and will throw the exception caused by the above send - conn.close(); - - fail("Close is not expected to succeed."); + _awaitError.await(1, TimeUnit.SECONDS); } catch (JMSException e) { - Throwable cause = e.getLinkedException(); - if (!(cause instanceof AMQAuthenticationException)) + fail("Unknown exception thrown:" + e.getMessage()); + } + boolean foundCorrectException = false; + for (Exception cause : _thrownExceptions) + { + if (cause instanceof JMSException) { - e.printStackTrace(); + if (((JMSException) cause).getLinkedException() instanceof AMQAuthenticationException) + { + foundCorrectException = true; + } } - assertEquals("Incorrect exception", AMQAuthenticationException.class, cause.getClass()); - assertEquals("Incorrect error code thrown", 403, ((AMQAuthenticationException) cause).getErrorCode().getCode()); } + assertTrue("Did not get AMQAuthenticationException thrown", foundCorrectException); } public void testServerConsumeFromNamedQueueValid() throws AMQException, URLSyntaxException @@ -657,4 +663,10 @@ public class SimpleACLTest extends QpidTestCase implements ConnectionListener public void failoverComplete() { } + + public void onException(JMSException arg0) + { + _thrownExceptions.add(arg0); + _awaitError.countDown(); + } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java index 91cb37e455..b99cd239d3 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java @@ -20,27 +20,27 @@ */ package org.apache.qpid.test.unit.client.protocol; -import org.apache.mina.common.IoSession; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.protocol.AMQProtocolHandler; import org.apache.qpid.client.protocol.AMQProtocolSession; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.test.utils.protocol.TestIoSession; +import org.apache.qpid.transport.TestNetworkDriver; +import org.apache.qpid.transport.NetworkDriver; public class AMQProtocolSessionTest extends QpidTestCase { private static class AMQProtSession extends AMQProtocolSession { - public AMQProtSession(AMQProtocolHandler protocolHandler, IoSession protocolSession, AMQConnection connection) + public AMQProtSession(AMQProtocolHandler protocolHandler, AMQConnection connection) { - super(protocolHandler,protocolSession,connection); + super(protocolHandler,connection); } - public TestIoSession getMinaProtocolSession() + public TestNetworkDriver getNetworkDriver() { - return (TestIoSession) _minaProtocolSession; + return (TestNetworkDriver) _protocolHandler.getNetworkDriver(); } public AMQShortString genQueueName() @@ -63,8 +63,11 @@ public class AMQProtocolSessionTest extends QpidTestCase { super.setUp(); + AMQConnection con = (AMQConnection) getConnection("guest", "guest"); + AMQProtocolHandler protocolHandler = new AMQProtocolHandler(con); + protocolHandler.setNetworkDriver(new TestNetworkDriver()); //don't care about the values set here apart from the dummy IoSession - _testSession = new AMQProtSession(null,new TestIoSession(), (AMQConnection) getConnection("guest", "guest")); + _testSession = new AMQProtSession(protocolHandler , con); //initialise addresses for test and expected results _port = 123; @@ -75,32 +78,32 @@ public class AMQProtocolSessionTest extends QpidTestCase _validAddress = "abc"; _generatedAddress_3 = "tmp_abc123_3"; } - +/* public void testGenerateQueueName() { AMQShortString testAddress; //test address with / and ; chars which generateQueueName should removeKey - _testSession.getMinaProtocolSession().setStringLocalAddress(_brokenAddress); - _testSession.getMinaProtocolSession().setLocalPort(_port); + _testSession.getNetworkDriver().setLocalAddress(_brokenAddress); + _testSession.getNetworkDriver().setPort(_port); testAddress = _testSession.genQueueName(); assertEquals("Failure when generating a queue exchange from an address with special chars",_generatedAddress,testAddress.toString()); //test empty address - _testSession.getMinaProtocolSession().setStringLocalAddress(_emptyAddress); + _testSession.getNetworkDriver().setLocalAddress(_emptyAddress); testAddress = _testSession.genQueueName(); assertEquals("Failure when generating a queue exchange from an empty address",_generatedAddress_2,testAddress.toString()); //test address with no special chars - _testSession.getMinaProtocolSession().setStringLocalAddress(_validAddress); + _testSession.getNetworkDriver().setStringLocalAddress(_validAddress); testAddress = _testSession.genQueueName(); assertEquals("Failure when generating a queue exchange from an address with no special chars",_generatedAddress_3,testAddress.toString()); } - +*/ protected void tearDown() throws Exception { _testSession = null; |
