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 | ac6e526370a8e860123a97fced2019ebb28146ce (patch) | |
| tree | b5019711fc8a98b2be3ec2ac7d16b4d99a148642 /qpid/java/common/src/test | |
| parent | f5bc6d047f2ea17048704c6e353078e9d2b27978 (diff) | |
| download | qpid-python-ac6e526370a8e860123a97fced2019ebb28146ce.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@720200 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/common/src/test')
| -rw-r--r-- | qpid/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java | 88 |
1 files changed, 76 insertions, 12 deletions
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java b/qpid/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java index 1da56654f0..ebb8e49e77 100644 --- a/qpid/java/common/src/test/java/org/apache/qpid/transport/ConnectionTest.java +++ b/qpid/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"); |
