diff options
| author | Arnaud Simon <arnaudsimon@apache.org> | 2008-02-21 14:38:38 +0000 |
|---|---|---|
| committer | Arnaud Simon <arnaudsimon@apache.org> | 2008-02-21 14:38:38 +0000 |
| commit | 5dfd843776112832a38abecadb4dbbe00b03390b (patch) | |
| tree | 7549693b42e051875364ce499c13e5526486e264 | |
| parent | 6e8de0252bf736addca80056075ae2cc1066e4b9 (diff) | |
| download | qpid-python-5dfd843776112832a38abecadb4dbbe00b03390b.tar.gz | |
changed for runing only with an 0.8 broker (this is testing 0.8 connection)
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@629800 13f79535-47bb-0310-9956-ffa450edef68
| -rw-r--r-- | java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java | 246 |
1 files changed, 128 insertions, 118 deletions
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java index 87984e8c49..08d6b0bcab 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/channelclose/ChannelCloseTest.java @@ -24,6 +24,7 @@ import junit.framework.TestCase; import org.apache.qpid.AMQException; import org.apache.qpid.AMQTimeoutException; +import org.apache.qpid.testutil.QpidTestCase; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.failover.FailoverException; import org.apache.qpid.client.protocol.AMQProtocolSession; @@ -53,7 +54,7 @@ import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; -public class ChannelCloseTest extends TestCase implements ExceptionListener, ConnectionListener +public class ChannelCloseTest extends QpidTestCase implements ExceptionListener, ConnectionListener { private static final Logger _logger = LoggerFactory.getLogger(ChannelCloseTest.class); @@ -80,56 +81,60 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con */ public void testReusingChannelAfterFullClosure() throws Exception { - _connection = newConnection(); - - // Create Producer - try + // this is testing an 0.8 conneciton + if(isBroker08()) { - _connection.start(); - - createChannelAndTest(1); + _connection=newConnection(); - // Cause it to close + // Create Producer try { - _logger.info("Testing invalid exchange"); - declareExchange(1, "", "name_that_will_lookup_to_null", false); - fail("Exchange name is empty so this should fail "); - } - catch (AMQException e) - { - assertEquals("Exchange should not be found", AMQConstant.NOT_FOUND, e.getErrorCode()); - } + _connection.start(); - // Check that - try - { - _logger.info("Testing valid exchange should fail"); - declareExchange(1, "topic", "amq.topic", false); - fail("This should not succeed as the channel should be closed "); - } - catch (AMQException e) - { - if (_logger.isInfoEnabled()) + createChannelAndTest(1); + + // Cause it to close + try + { + _logger.info("Testing invalid exchange"); + declareExchange(1, "", "name_that_will_lookup_to_null", false); + fail("Exchange name is empty so this should fail "); + } + catch (AMQException e) { - _logger.info("Exception occured was:" + e.getErrorCode()); + assertEquals("Exchange should not be found", AMQConstant.NOT_FOUND, e.getErrorCode()); } - assertEquals("Connection should be closed", AMQConstant.CHANNEL_ERROR, e.getErrorCode()); + // Check that + try + { + _logger.info("Testing valid exchange should fail"); + declareExchange(1, "topic", "amq.topic", false); + fail("This should not succeed as the channel should be closed "); + } + catch (AMQException e) + { + if (_logger.isInfoEnabled()) + { + _logger.info("Exception occured was:" + e.getErrorCode()); + } - _connection = newConnection(); - } + assertEquals("Connection should be closed", AMQConstant.CHANNEL_ERROR, e.getErrorCode()); - checkSendingMessage(); + _connection=newConnection(); + } - _session.close(); - _connection.close(); + checkSendingMessage(); - } - catch (JMSException e) - { - e.printStackTrace(); - fail(e.getMessage()); + _session.close(); + _connection.close(); + + } + catch (JMSException e) + { + e.printStackTrace(); + fail(e.getMessage()); + } } } @@ -138,113 +143,118 @@ public class ChannelCloseTest extends TestCase implements ExceptionListener, Con */ public void testSendingMethodsAfterClose() throws Exception { - try + // this is testing an 0.8 connection + if(isBroker08()) { - _connection = new AMQConnection("amqp://guest:guest@CCTTest/test?brokerlist='" + _brokerlist + "'"); - - ((AMQConnection) _connection).setConnectionListener(this); + try + { + _connection=new AMQConnection("amqp://guest:guest@CCTTest/test?brokerlist='" + _brokerlist + "'"); - _connection.setExceptionListener(this); + ((AMQConnection) _connection).setConnectionListener(this); - // Change the StateManager for one that doesn't respond with Close-OKs - AMQStateManager oldStateManager = ((AMQConnection) _connection).getProtocolHandler().getStateManager(); + _connection.setExceptionListener(this); - _session = _connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); + // Change the StateManager for one that doesn't respond with Close-OKs + AMQStateManager oldStateManager=((AMQConnection) _connection).getProtocolHandler().getStateManager(); - _connection.start(); + _session=_connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); - // Test connection - checkSendingMessage(); + _connection.start(); - // Set StateManager to manager that ignores Close-oks - AMQProtocolSession protocolSession = ((AMQConnection) _connection).getProtocolHandler().getProtocolSession(); - AMQStateManager newStateManager = new NoCloseOKStateManager(protocolSession); - newStateManager.changeState(oldStateManager.getCurrentState()); + // Test connection + checkSendingMessage(); - ((AMQConnection) _connection).getProtocolHandler().setStateManager(newStateManager); + // Set StateManager to manager that ignores Close-oks + AMQProtocolSession protocolSession= + ((AMQConnection) _connection).getProtocolHandler().getProtocolSession(); + AMQStateManager newStateManager=new NoCloseOKStateManager(protocolSession); + newStateManager.changeState(oldStateManager.getCurrentState()); - final int TEST_CHANNEL = 1; - _logger.info("Testing Channel(" + TEST_CHANNEL + ") Creation"); + ((AMQConnection) _connection).getProtocolHandler().setStateManager(newStateManager); - createChannelAndTest(TEST_CHANNEL); + final int TEST_CHANNEL=1; + _logger.info("Testing Channel(" + TEST_CHANNEL + ") Creation"); - // Cause it to close - try - { - _logger.info("Closing Channel - invalid exchange"); - declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", false); - fail("Exchange name is empty so this should fail "); - } - catch (AMQException e) - { - assertEquals("Exchange should not be found", AMQConstant.NOT_FOUND, e.getErrorCode()); - } + createChannelAndTest(TEST_CHANNEL); - try - { - // Send other methods that should be ignored - // send them no wait as server will ignore them - _logger.info("Tested known exchange - should ignore"); - declareExchange(TEST_CHANNEL, "topic", "amq.topic", true); + // Cause it to close + try + { + _logger.info("Closing Channel - invalid exchange"); + declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", false); + fail("Exchange name is empty so this should fail "); + } + catch (AMQException e) + { + assertEquals("Exchange should not be found", AMQConstant.NOT_FOUND, e.getErrorCode()); + } - _logger.info("Tested known invalid exchange - should ignore"); - declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", true); + try + { + // Send other methods that should be ignored + // send them no wait as server will ignore them + _logger.info("Tested known exchange - should ignore"); + declareExchange(TEST_CHANNEL, "topic", "amq.topic", true); - _logger.info("Tested known invalid exchange - should ignore"); - declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", true); + _logger.info("Tested known invalid exchange - should ignore"); + declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", true); - // Send sync .. server will igore and timy oue - _logger.info("Tested known invalid exchange - should ignore"); - declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", false); - } - catch (AMQTimeoutException te) - { - assertEquals("Request should timeout", AMQConstant.REQUEST_TIMEOUT, te.getErrorCode()); - } - catch (AMQException e) - { - fail("This should not fail as all requests should be ignored"); - } + _logger.info("Tested known invalid exchange - should ignore"); + declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", true); - _logger.info("Sending Close"); - // Send Close-ok - sendClose(TEST_CHANNEL); + // Send sync .. server will igore and timy oue + _logger.info("Tested known invalid exchange - should ignore"); + declareExchange(TEST_CHANNEL, "", "name_that_will_lookup_to_null", false); + } + catch (AMQTimeoutException te) + { + assertEquals("Request should timeout", AMQConstant.REQUEST_TIMEOUT, te.getErrorCode()); + } + catch (AMQException e) + { + fail("This should not fail as all requests should be ignored"); + } - _logger.info("Re-opening channel"); + _logger.info("Sending Close"); + // Send Close-ok + sendClose(TEST_CHANNEL); - createChannelAndTest(TEST_CHANNEL); + _logger.info("Re-opening channel"); - // Test connection is still ok + createChannelAndTest(TEST_CHANNEL); - checkSendingMessage(); + // Test connection is still ok - } - catch (JMSException e) - { - e.printStackTrace(); - fail(e.getMessage()); - } - catch (AMQException e) - { - fail(e.getMessage()); + checkSendingMessage(); - } - catch (URLSyntaxException e) - { - fail(e.getMessage()); - } - finally - { - try - { - _session.close(); - _connection.close(); } catch (JMSException e) { e.printStackTrace(); fail(e.getMessage()); } + catch (AMQException e) + { + fail(e.getMessage()); + + } + catch (URLSyntaxException e) + { + fail(e.getMessage()); + } + finally + { + try + { + _session.close(); + _connection.close(); + } + catch (JMSException e) + { + e.printStackTrace(); + fail(e.getMessage()); + } + } } } |
