Author: aidan
Date: Fri Mar 21 06:04:46 2008
New Revision: 639619
URL: http://svn.apache.org/viewvc?rev=639619&view=rev
Log:
QPID-867 Always close connections
Modified:
incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
Modified:
incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java?rev=639619&r1=639618&r2=639619&view=diff
==============================================================================
---
incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
(original)
+++
incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
Fri Mar 21 06:04:46 2008
@@ -56,25 +56,30 @@
TransportConnection.killVMBroker(1);
}
- public void testSimpleConnection()
+ public void testSimpleConnection() throws Exception
{
+ AMQConnection conn = null;
try
{
- AMQConnection conn = new AMQConnection(_broker, "guest", "guest",
"fred", "test");
- conn.close();
+ conn = new AMQConnection(_broker, "guest", "guest", "fred",
"test");
}
catch (Exception e)
{
fail("Connection to " + _broker + " should succeed. Reason: " + e);
}
+ finally
+ {
+ conn.close();
+ }
}
- public void testDefaultExchanges()
+ public void testDefaultExchanges() throws Exception
{
+ AMQConnection conn = null;
try
{
- AMQConnection conn = new AMQConnection("amqp://guest:[EMAIL
PROTECTED]/test?brokerlist='"
+ conn = new AMQConnection("amqp://guest:[EMAIL
PROTECTED]/test?brokerlist='"
+ _broker
+
"?retries='1''&defaultQueueExchange='test.direct'"
+
"&defaultTopicExchange='test.topic'"
@@ -107,21 +112,24 @@
topicSession.close();
-
- conn.close();
}
catch (Exception e)
{
fail("Connection to " + _broker + " should succeed. Reason: " + e);
}
+ finally
+ {
+ conn.close();
+ }
}
//See QPID-771
public void testPasswordFailureConnection() throws Exception
{
+ AMQConnection conn = null;
try
{
- new AMQConnection("amqp://guest:[EMAIL
PROTECTED]/test?brokerlist='" + _broker + "?retries='1''");
+ conn = new AMQConnection("amqp://guest:[EMAIL
PROTECTED]/test?brokerlist='" + _broker + "?retries='1''");
fail("Connection should not be established password is wrong.");
}
catch (AMQException amqe)
@@ -136,13 +144,21 @@
Exception linked = ((JMSException)
amqe.getCause()).getLinkedException();
assertEquals("Exception was wrong type",
AMQAuthenticationException.class, linked.getClass());
}
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testConnectionFailure() throws Exception
{
+ AMQConnection conn = null;
try
{
- new AMQConnection("amqp://guest:[EMAIL
PROTECTED]/testpath?brokerlist='" + _broker_NotRunning + "?retries='0''");
+ conn = new AMQConnection("amqp://guest:[EMAIL
PROTECTED]/testpath?brokerlist='" + _broker_NotRunning + "?retries='0''");
fail("Connection should not be established");
}
catch (AMQException amqe)
@@ -152,14 +168,22 @@
fail("Correct exception not thrown. Excpected
'AMQConnectionException' got: " + amqe);
}
}
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testUnresolvedHostFailure() throws Exception
{
+ AMQConnection conn = null;
try
{
- new AMQConnection("amqp://guest:[EMAIL
PROTECTED]/testpath?brokerlist='" + _broker_BadDNS + "?retries='0''");
+ conn = new AMQConnection("amqp://guest:[EMAIL
PROTECTED]/testpath?brokerlist='" + _broker_BadDNS + "?retries='0''");
fail("Connection should not be established");
}
catch (AMQException amqe)
@@ -169,13 +193,22 @@
fail("Correct exception not thrown. Excpected
'AMQUnresolvedAddressException' got: " + amqe);
}
}
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+
}
public void testUnresolvedVirtualHostFailure() throws Exception
{
+ AMQConnection conn = null;
try
{
- new AMQConnection("amqp://guest:[EMAIL
PROTECTED]/rubbishhost?brokerlist='" + _broker + "?retries='0''");
+ conn = new AMQConnection("amqp://guest:[EMAIL
PROTECTED]/rubbishhost?brokerlist='" + _broker + "?retries='0''");
fail("Connection should not be established");
}
catch (AMQException amqe)
@@ -185,6 +218,13 @@
fail("Correct exception not thrown. Excpected
'AMQConnectionFailureException' got: " + amqe);
}
}
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
}
public void testClientIdCannotBeChanged() throws Exception
@@ -200,13 +240,27 @@
{
// PASS
}
+ finally
+ {
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }
}
public void testClientIdIsPopulatedAutomatically() throws Exception
{
Connection connection = new AMQConnection(_broker, "guest", "guest",
null, "test");
- assertNotNull(connection.getClientID());
+ try
+ {
+ assertNotNull(connection.getClientID());
+ }
+ finally
+ {
+ connection.close();
+ }
}
public static junit.framework.Test suite()