diff options
author | Bhupendra Bhusman Bhardwaj <bhupendrab@apache.org> | 2006-12-21 11:32:58 +0000 |
---|---|---|
committer | Bhupendra Bhusman Bhardwaj <bhupendrab@apache.org> | 2006-12-21 11:32:58 +0000 |
commit | 2c418b019c8f3a9cc720c588e0268c00b86c8576 (patch) | |
tree | c750425a5e0f37ef16971a7f24dd9fbead528a36 | |
parent | c190f7dcc2c0d6cc84956fc8443f60a12d8645e1 (diff) | |
download | qpid-python-2c418b019c8f3a9cc720c588e0268c00b86c8576.tar.gz |
QPID-188
Unit test for AMQProtocolSession mbean updated and closeChannel() method removed from mbean because it didn't seem to be a required feature for management console.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@489330 13f79535-47bb-0310-9956-ffa450edef68
5 files changed, 22 insertions, 47 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java index 6ba78ba722..7a9dfbc67c 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java +++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQMinaProtocolSession.java @@ -316,8 +316,13 @@ public class AMQMinaProtocolSession implements AMQProtocolSession, return _channelMap.get(channelId); } - public void addChannel(AMQChannel channel) + public void addChannel(AMQChannel channel) throws AMQException { + if (_closed) + { + throw new AMQException("Session is closed"); + } + _channelMap.put(channel.getChannelId(), channel); checkForNotification(); } diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java index 03d0c50dac..a75627d240 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java +++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSession.java @@ -70,7 +70,7 @@ public interface AMQProtocolSession * @param channel the channel to associate with this session. It is an error to * associate the same channel with more than one session but this is not validated. */ - void addChannel(AMQChannel channel); + void addChannel(AMQChannel channel) throws AMQException; /** * Close a specific channel. This will remove any resources used by the channel, including: diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java index a47d462810..d57f9b9be1 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java +++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBean.java @@ -18,6 +18,9 @@ package org.apache.qpid.server.protocol; import org.apache.qpid.AMQException; +import org.apache.qpid.protocol.AMQConstant; +import org.apache.qpid.framing.ConnectionCloseBody; +import org.apache.qpid.framing.AMQFrame; import org.apache.qpid.server.AMQChannel; import org.apache.qpid.server.management.AMQManagedObject; import org.apache.qpid.server.management.MBeanConstructor; @@ -183,33 +186,17 @@ public class AMQProtocolSessionMBean extends AMQManagedObject implements Managed } /** - * @see AMQMinaProtocolSession#closeChannel(int) - */ - public void closeChannel(int id) throws JMException - { - try - { - AMQChannel channel = _session.getChannel(id); - if (channel == null) - { - throw new JMException("The channel (channel Id = " + id + ") does not exist"); - } - - _session.closeChannel(id); - } - catch (AMQException ex) - { - throw new MBeanException(ex, ex.toString()); - } - } - - /** * closes the connection. The administrator can use this management operation to close connection to free up * resources. * @throws JMException */ public void closeConnection() throws JMException { + + final AMQFrame response = ConnectionCloseBody.createAMQFrame(0, AMQConstant.REPLY_SUCCESS.getCode(), + "Broker Management Console has closing the connection.", 0, 0); + _session.writeFrame(response); + try { _session.closeSession(); diff --git a/java/broker/src/main/java/org/apache/qpid/server/protocol/ManagedConnection.java b/java/broker/src/main/java/org/apache/qpid/server/protocol/ManagedConnection.java index 2f3102b048..1a7b7e9e96 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/protocol/ManagedConnection.java +++ b/java/broker/src/main/java/org/apache/qpid/server/protocol/ManagedConnection.java @@ -114,15 +114,6 @@ public interface ManagedConnection void rollbackTransactions(@MBeanOperationParameter(name="channel Id", description="channel Id")int channelId) throws JMException; /** - * Unsubscribes the consumers and unregisters the channel from managed objects. - */ - @MBeanOperation(name="closeChannel", - description="Closes the channel with given channel Id and connected consumers will be unsubscribed", - impact= MBeanOperationInfo.ACTION) - void closeChannel(@MBeanOperationParameter(name="channel Id", description="channel Id")int channelId) - throws Exception; - - /** * Closes all the related channels and unregisters this connection from managed objects. */ @MBeanOperation(name="closeConnection", diff --git a/java/systests/src/test/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBeanTest.java b/java/systests/src/test/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBeanTest.java index 0a41d4166b..356c887996 100644 --- a/java/systests/src/test/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBeanTest.java +++ b/java/systests/src/test/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBeanTest.java @@ -28,11 +28,9 @@ import org.apache.qpid.server.queue.DefaultQueueRegistry; import org.apache.qpid.server.queue.QueueRegistry; import org.apache.qpid.server.store.MessageStore; import org.apache.qpid.server.store.SkeletonMessageStore; +import org.apache.qpid.AMQException; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.TabularData; import javax.management.JMException; -import java.util.ArrayList; /** * Test class to test MBean operations for AMQMinaProtocolSession. @@ -56,20 +54,11 @@ public class AMQProtocolSessionMBeanTest extends TestCase channelCount = _mbean.channels().size(); assertTrue(channelCount == 2); - // check the channel closing - _mbean.closeChannel(1); - TabularData channels = _mbean.channels(); - ArrayList<CompositeData> list = new ArrayList<CompositeData>(channels.values()); - channelCount = list.size(); - assertTrue(channelCount == 1); - CompositeData channelData = list.get(0); - assertEquals(channelData.get("Channel Id"), new Integer(2)); - // general properties test _mbean.setMaximumNumberOfChannels(1000L); assertTrue(_mbean.getMaximumNumberOfChannels() == 1000L); - // check if the rollback and commit APIs + // check APIs AMQChannel channel3 = new AMQChannel(3, _messageStore, null); channel3.setTransactional(true); _protocolSession.addChannel(channel3); @@ -94,10 +83,13 @@ public class AMQProtocolSessionMBeanTest extends TestCase _mbean.closeConnection(); try { - _mbean.closeChannel(5); + channelCount = _mbean.channels().size(); + assertTrue(channelCount == 0); + // session is now closed so adding another channel should throw an exception + _protocolSession.addChannel(new AMQChannel(6, _messageStore, null)); fail(); } - catch(JMException ex) + catch(AMQException ex) { System.out.println("expected exception is thrown :" + ex.getMessage()); } |