diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2008-07-04 14:01:09 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2008-07-04 14:01:09 +0000 |
| commit | dc1198195619a0e449cd6f7658b90da6dff41729 (patch) | |
| tree | 4571130092bd6677c8f178d7970c6ab4ffb9358d /java/client/src | |
| parent | f226a3025c8e6c7a50489710f2f9b7a15fbbdded (diff) | |
| download | qpid-python-dc1198195619a0e449cd6f7658b90da6dff41729.tar.gz | |
Qpid-940 - ConnectionTest#testPasswordFailureConnection fails occasionally so while these race conditions are addressed I've converted the ConnectionTest to QpidTestCase and use it to skip the PasswordFailureConnection.
junit.framework.AssertionFailedError: No cause set
at org.apache.qpid.test.unit.client.connection.ConnectionTest.testPasswordFailureConnection(ConnectionTest.java:145)
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@674058 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/src')
| -rw-r--r-- | java/client/src/main/java/org/apache/qpid/testutil/QpidTestCase.java | 64 | ||||
| -rw-r--r-- | java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java | 58 |
2 files changed, 73 insertions, 49 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/testutil/QpidTestCase.java b/java/client/src/main/java/org/apache/qpid/testutil/QpidTestCase.java index 1fe9a3ae51..0218d693d5 100644 --- a/java/client/src/main/java/org/apache/qpid/testutil/QpidTestCase.java +++ b/java/client/src/main/java/org/apache/qpid/testutil/QpidTestCase.java @@ -22,6 +22,7 @@ import junit.framework.TestResult; import javax.jms.Connection; import javax.naming.InitialContext; +import javax.naming.NamingException; import java.io.*; import java.util.ArrayList; import java.util.List; @@ -33,7 +34,6 @@ import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQConnectionFactory; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,7 +47,7 @@ public class QpidTestCase extends TestCase private static final Logger _logger = LoggerFactory.getLogger(QpidTestCase.class); /** - * Some tests are excluded when the property test.excludes is set to true. + * Some tests are excluded when the property test.excludes is set to true. * An exclusion list is either a file (prop test.excludesfile) which contains one test name * to be excluded per line or a String (prop test.excludeslist) where tests to be excluded are * separated by " ". Excluded tests are specified following the format: @@ -55,6 +55,8 @@ public class QpidTestCase extends TestCase * excluded and testName is the name of the test to be excluded. * className#* excludes all the tests of the specified class. */ + private static final String DEFAULT_INITIAL_CONTEXT = "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"; + static { if (Boolean.getBoolean("test.excludes")) @@ -62,7 +64,7 @@ public class QpidTestCase extends TestCase _logger.info("Some tests should be excluded, building the exclude list"); String exclusionListURI = System.getProperties().getProperty("test.excludesfile", ""); String exclusionListString = System.getProperties().getProperty("test.excludeslist", ""); - File file=new File(exclusionListURI); + File file = new File(exclusionListURI); List<String> exclusionList = new ArrayList<String>(); if (file.exists()) { @@ -83,7 +85,7 @@ public class QpidTestCase extends TestCase _logger.warn("Exception when reading exclusion list", e); } } - else if( ! exclusionListString.equals("")) + else if (!exclusionListString.equals("")) { _logger.info("Using excludeslist: " + exclusionListString); // the exclusion list may be specified as a string @@ -99,6 +101,13 @@ public class QpidTestCase extends TestCase } _exclusionList = exclusionList; } + + String initialContext = System.getProperty(InitialContext.INITIAL_CONTEXT_FACTORY); + + if (initialContext == null || initialContext.isEmpty()) + { + System.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, DEFAULT_INITIAL_CONTEXT); + } } private static List<String> _exclusionList; @@ -106,7 +115,7 @@ public class QpidTestCase extends TestCase // system properties private static final String BROKER = "broker"; private static final String BROKER_CLEAN = "broker.clean"; - private static final String BROKER_VERSION = "broker.version"; + private static final String BROKER_VERSION = "broker.version"; private static final String BROKER_READY = "broker.ready"; // values @@ -134,9 +143,9 @@ public class QpidTestCase extends TestCase } public QpidTestCase() - { - super("QpidTestCase"); - } + { + super("QpidTestCase"); + } public void runBare() throws Throwable { @@ -163,8 +172,8 @@ public class QpidTestCase extends TestCase public void run(TestResult testResult) { - if( _exclusionList != null && (_exclusionList.contains( getClass().getName() + "#*") || - _exclusionList.contains( getClass().getName() + "#" + getName()))) + if (_exclusionList != null && (_exclusionList.contains(getClass().getName() + "#*") || + _exclusionList.contains(getClass().getName() + "#" + getName()))) { _logger.info("Test: " + getName() + " is excluded"); testResult.endTest(this); @@ -175,7 +184,6 @@ public class QpidTestCase extends TestCase } } - private static final class Piper extends Thread { @@ -331,7 +339,8 @@ public class QpidTestCase extends TestCase /** * Check whether the broker is an 0.8 - * @return true if the broker is an 0_8 version, false otherwise. + * + * @return true if the broker is an 0_8 version, false otherwise. */ public boolean isBroker08() { @@ -348,15 +357,17 @@ public class QpidTestCase extends TestCase stopBroker(); startBroker(); } + /** * we assume that the environment is correctly set * i.e. -Djava.naming.provider.url="..//example010.properties" * TODO should be a way of setting that through maven * * @return an initial context + * * @throws Exception if there is an error getting the context */ - public InitialContext getInitialContext() throws Exception + public InitialContext getInitialContext() throws NamingException { _logger.info("get InitialContext"); if (_initialContext == null) @@ -371,21 +382,22 @@ public class QpidTestCase extends TestCase * Default factory is "local" * * @return A conection factory + * * @throws Exception if there is an error getting the tactory */ - public AMQConnectionFactory getConnectionFactory() throws Exception + public AMQConnectionFactory getConnectionFactory() throws NamingException { _logger.info("get ConnectionFactory"); if (_connectionFactory == null) { - if (_broker.equals(VM)) - { + if (_broker.equals(VM)) + { _connectionFactory = getConnectionFactory("vm"); - } - else - { + } + else + { _connectionFactory = getConnectionFactory("local"); - } + } } return _connectionFactory; } @@ -393,11 +405,13 @@ public class QpidTestCase extends TestCase /** * Get a connection factory for the currently used broker * - * @param factoryName The factory name + * @param factoryName The factory name + * * @return A conection factory + * * @throws Exception if there is an error getting the tactory */ - public AMQConnectionFactory getConnectionFactory(String factoryName) throws Exception + public AMQConnectionFactory getConnectionFactory(String factoryName) throws NamingException { return (AMQConnectionFactory) getInitialContext().lookup(factoryName); } @@ -412,13 +426,15 @@ public class QpidTestCase extends TestCase * * @param username The user name * @param password The user password + * * @return a newly created connection + * * @throws Exception if there is an error getting the connection */ public Connection getConnection(String username, String password) throws Exception { _logger.info("get Connection"); - Connection con = getConnectionFactory().createConnection(username, password); + Connection con = getConnectionFactory().createConnection(username, password); //add the connection in the lis of connections _connections.add(con); return con; @@ -436,7 +452,7 @@ public class QpidTestCase extends TestCase { con = getConnectionFactory().createConnection(username, password); } - //add the connection in the lis of connections + //add the connection in the lis of connections _connections.add(con); return con; } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java index 97eed08ab1..30b7ccc550 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java @@ -23,6 +23,7 @@ package org.apache.qpid.test.unit.client.connection; import org.apache.qpid.AMQConnectionFailureException; import org.apache.qpid.AMQException; import org.apache.qpid.AMQUnresolvedAddressException; +import org.apache.qpid.testutil.QpidTestCase; import org.apache.qpid.client.AMQAuthenticationException; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQQueue; @@ -36,24 +37,34 @@ import javax.jms.Connection; import javax.jms.JMSException; import javax.jms.QueueSession; import javax.jms.TopicSession; +import javax.naming.NamingException; -public class ConnectionTest extends TestCase +public class ConnectionTest extends QpidTestCase { - String _broker = "vm://:1"; String _broker_NotRunning = "vm://:2"; String _broker_BadDNS = "tcp://hg3sgaaw4lgihjs"; - - protected void setUp() throws Exception + public String getBroker() { - super.setUp(); - TransportConnection.createVMBroker(1); - } + try + { + if (getConnectionFactory().getConnectionURL().getBrokerCount() > 0) + { + return getConnectionFactory().getConnectionURL().getBrokerDetails(0).toString(); + } + else + { + fail("No broker details are available."); + } + } + catch (NamingException e) + { + fail(e.getMessage()); + } - protected void tearDown() throws Exception - { - TransportConnection.killVMBroker(1); + //keep compiler happy + return null; } public void testSimpleConnection() throws Exception @@ -61,11 +72,11 @@ public class ConnectionTest extends TestCase AMQConnection conn = null; try { - conn = new AMQConnection(_broker, "guest", "guest", "fred", "test"); + conn = new AMQConnection(getBroker(), "guest", "guest", "fred", "test"); } catch (Exception e) { - fail("Connection to " + _broker + " should succeed. Reason: " + e); + fail("Connection to " + getBroker() + " should succeed. Reason: " + e); } finally { @@ -73,18 +84,17 @@ public class ConnectionTest extends TestCase } } - public void testDefaultExchanges() throws Exception { AMQConnection conn = null; try { conn = new AMQConnection("amqp://guest:guest@clientid/test?brokerlist='" - + _broker - + "?retries='1''&defaultQueueExchange='test.direct'" - + "&defaultTopicExchange='test.topic'" - + "&temporaryQueueExchange='tmp.direct'" - + "&temporaryTopicExchange='tmp.topic'"); + + getBroker() + + "?retries='1''&defaultQueueExchange='test.direct'" + + "&defaultTopicExchange='test.topic'" + + "&temporaryQueueExchange='tmp.direct'" + + "&temporaryTopicExchange='tmp.topic'"); QueueSession queueSession = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); @@ -96,10 +106,8 @@ public class ConnectionTest extends TestCase assertEquals(tempQueue.getExchangeName().toString(), "tmp.direct"); - queueSession.close(); - TopicSession topicSession = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); AMQTopic topic = (AMQTopic) topicSession.createTopic("silly.topic"); @@ -115,7 +123,7 @@ public class ConnectionTest extends TestCase } catch (Exception e) { - fail("Connection to " + _broker + " should succeed. Reason: " + e); + fail("Connection to " + getBroker() + " should succeed. Reason: " + e); } finally { @@ -129,7 +137,7 @@ public class ConnectionTest extends TestCase AMQConnection conn = null; try { - conn = new AMQConnection("amqp://guest:rubbishpassword@clientid/test?brokerlist='" + _broker + "?retries='1''"); + conn = new AMQConnection("amqp://guest:rubbishpassword@clientid/test?brokerlist='" + getBroker() + "?retries='1''"); fail("Connection should not be established password is wrong."); } catch (AMQException amqe) @@ -209,7 +217,7 @@ public class ConnectionTest extends TestCase AMQConnection conn = null; try { - conn = new AMQConnection("amqp://guest:guest@clientid/rubbishhost?brokerlist='" + _broker + "?retries='0''"); + conn = new AMQConnection("amqp://guest:guest@clientid/rubbishhost?brokerlist='" + getBroker() + "?retries='0''"); fail("Connection should not be established"); } catch (AMQException amqe) @@ -230,7 +238,7 @@ public class ConnectionTest extends TestCase public void testClientIdCannotBeChanged() throws Exception { - Connection connection = new AMQConnection(_broker, "guest", "guest", + Connection connection = new AMQConnection(getBroker(), "guest", "guest", "fred", "test"); try { @@ -252,7 +260,7 @@ public class ConnectionTest extends TestCase public void testClientIdIsPopulatedAutomatically() throws Exception { - Connection connection = new AMQConnection(_broker, "guest", "guest", + Connection connection = new AMQConnection(getBroker(), "guest", "guest", null, "test"); try { |
