diff options
author | Martin Ritchie <ritchiem@apache.org> | 2008-11-24 14:16:30 +0000 |
---|---|---|
committer | Martin Ritchie <ritchiem@apache.org> | 2008-11-24 14:16:30 +0000 |
commit | d0a73775a14466283f37b0dce90a178d86b88ad8 (patch) | |
tree | 036c7c05d31a1cdf1d23011fe6cf11dec917590f /java/common | |
parent | d5cc1feb86956b95406e7223454a8ffd1aa0180d (diff) | |
download | qpid-python-d0a73775a14466283f37b0dce90a178d86b88ad8.tar.gz |
QPID-1251 : Applied patch from JIRA (With correct code style). Augemented ConnectionTest to correctly test for the special os.name = windows case.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@720200 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common')
-rw-r--r-- | java/common/src/main/java/org/apache/qpid/transport/Connection.java | 12 | ||||
-rw-r--r-- | java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java | 88 |
2 files changed, 87 insertions, 13 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/transport/Connection.java b/java/common/src/main/java/org/apache/qpid/transport/Connection.java index cf9b9145a9..56cbf5ee13 100644 --- a/java/common/src/main/java/org/apache/qpid/transport/Connection.java +++ b/java/common/src/main/java/org/apache/qpid/transport/Connection.java @@ -181,7 +181,17 @@ public class Connection extends ConnectionInvoker { ConnectionException t = error; error = null; - close(); + try + { + close(); + } + catch (ConnectionException ce) + { + if (!(t instanceof ProtocolVersionException)) + { + throw ce; + } + } t.rethrow(); } diff --git a/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java b/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java index 1da56654f0..ebb8e49e77 100644 --- a/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java +++ b/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java @@ -35,6 +35,8 @@ import junit.framework.TestCase; import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.Collections; +import java.io.IOException; /** * ConnectionTest @@ -56,18 +58,6 @@ public class ConnectionTest extends TestCase implements SessionListener port = AvailablePortFinder.getNextAvailable(12000); - ConnectionDelegate server = new ServerDelegate() { - @Override public Session getSession(Connection conn, SessionAttach atc) - { - Session ssn = super.getSession(conn, atc); - ssn.setSessionListener(ConnectionTest.this); - return ssn; - } - }; - - IoAcceptor ioa = new IoAcceptor - ("localhost", port, ConnectionBinding.get(server)); - ioa.start(); } public void opened(Session ssn) {} @@ -163,8 +153,78 @@ public class ConnectionTest extends TestCase implements SessionListener return conn; } + public void testProtocolNegotiationExceptionOverridesCloseException() throws Exception + { + // Force os.name to be windows to exercise code in IoReceiver + // that looks for the value of os.name + System.setProperty("os.name","windows"); + + // Start server as 0-9 to froce a ProtocolVersionException + startServer(new ProtocolHeader(1, 0, 9)); + + Condition closed = new Condition(); + + try + { + connect(closed); + fail("ProtocolVersionException expected"); + } + catch (ProtocolVersionException pve) + { + //Expected code path + } + catch (Exception e) + { + fail("ProtocolVersionException expected. Got:" + e.getMessage()); + } + } + + private void startServer() + { + startServer(new ProtocolHeader(1, 0, 10)); + } + + private void startServer(final ProtocolHeader protocolHeader) + { + ConnectionDelegate server = new ServerDelegate() + { + @Override + public void init(Connection conn, ProtocolHeader hdr) + { + conn.send(protocolHeader); + List<Object> utf8 = new ArrayList<Object>(); + utf8.add("utf8"); + conn.connectionStart(null, Collections.EMPTY_LIST, utf8); + } + + @Override + public Session getSession(Connection conn, SessionAttach atc) + { + Session ssn = super.getSession(conn, atc); + ssn.setSessionListener(ConnectionTest.this); + return ssn; + } + }; + + IoAcceptor ioa = null; + try + { + ioa = new IoAcceptor + ("localhost", port, ConnectionBinding.get(server)); + } + catch (IOException e) + { + e.printStackTrace(); + fail("Unable to start Server for test due to:" + e.getMessage()); + } + + ioa.start(); + } + public void testClosedNotificationAndWriteToClosed() throws Exception { + startServer(); + Condition closed = new Condition(); Connection conn = connect(closed); @@ -223,6 +283,8 @@ public class ConnectionTest extends TestCase implements SessionListener public void testResumeNonemptyReplayBuffer() throws Exception { + startServer(); + Connection conn = new Connection(); conn.setConnectionListener(new FailoverConnectionListener()); conn.connect("localhost", port, null, "guest", "guest"); @@ -276,6 +338,8 @@ public class ConnectionTest extends TestCase implements SessionListener public void testResumeEmptyReplayBuffer() throws InterruptedException { + startServer(); + Connection conn = new Connection(); conn.setConnectionListener(new FailoverConnectionListener()); conn.connect("localhost", port, null, "guest", "guest"); |