qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ritch...@apache.org
Subject svn commit: r674058 - in /incubator/qpid/trunk/qpid/java/client/src: main/java/org/apache/qpid/testutil/QpidTestCase.java test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
Date Fri, 04 Jul 2008 14:01:09 GMT
Author: ritchiem
Date: Fri Jul  4 07:01:09 2008
New Revision: 674058

URL: http://svn.apache.org/viewvc?rev=674058&view=rev
Log:
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)

Modified:
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/testutil/QpidTestCase.java
    incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/testutil/QpidTestCase.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/testutil/QpidTestCase.java?rev=674058&r1=674057&r2=674058&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/testutil/QpidTestCase.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/testutil/QpidTestCase.java
Fri Jul  4 07:01:09 2008
@@ -22,6 +22,7 @@
 
 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.AMQConnection;
 import org.apache.qpid.client.AMQConnectionFactory;
 
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -47,7 +47,7 @@
     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 @@
      * 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 @@
             _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 @@
                     _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 @@
             }
             _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 @@
     // 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 QpidTestCase()
-       {
-           super("QpidTestCase");
-       }
+    {
+        super("QpidTestCase");
+    }
 
     public void runBare() throws Throwable
     {
@@ -163,8 +172,8 @@
 
     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 @@
         }
     }
 
-
     private static final class Piper extends Thread
     {
 
@@ -331,7 +339,8 @@
 
     /**
      * 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 @@
         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 @@
      * 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 @@
     /**
      * 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 @@
      *
      * @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 @@
         {
             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;
     }

Modified: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java?rev=674058&r1=674057&r2=674058&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
Fri Jul  4 07:01:09 2008
@@ -23,6 +23,7 @@
 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.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 @@
         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 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 @@
 
             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 @@
         }
         catch (Exception e)
         {
-            fail("Connection to " + _broker + " should succeed. Reason: " + e);
+            fail("Connection to " + getBroker() + " should succeed. Reason: " + e);
         }
         finally
         {
@@ -129,7 +137,7 @@
         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 @@
         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 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 void testClientIdIsPopulatedAutomatically() throws Exception
     {
-        Connection connection = new AMQConnection(_broker, "guest", "guest",
+        Connection connection = new AMQConnection(getBroker(), "guest", "guest",
                                                   null, "test");
         try
         {



Mime
View raw message