summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBhupendra Bhusman Bhardwaj <bhupendrab@apache.org>2006-12-19 15:17:25 +0000
committerBhupendra Bhusman Bhardwaj <bhupendrab@apache.org>2006-12-19 15:17:25 +0000
commit6d7e2b6fbf8eb7d0c5def163140ed63559a5f8bc (patch)
treef2fcddf9d0b970a7f4c1bca378430fb3262cf6d2
parent243b3c0627077af460c5decfb7769142e22af840 (diff)
downloadqpid-python-6d7e2b6fbf8eb7d0c5def163140ed63559a5f8bc.tar.gz
QPID-188
Adding unit tests for Java broker JMX functionality git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@488705 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/systests/src/test/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBeanTest.java118
1 files changed, 118 insertions, 0 deletions
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
new file mode 100644
index 0000000000..0a41d4166b
--- /dev/null
+++ b/java/systests/src/test/java/org/apache/qpid/server/protocol/AMQProtocolSessionMBeanTest.java
@@ -0,0 +1,118 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.server.protocol;
+
+import junit.framework.TestCase;
+import org.apache.mina.common.IoSession;
+import org.apache.qpid.codec.AMQCodecFactory;
+import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.exchange.DefaultExchangeFactory;
+import org.apache.qpid.server.exchange.DefaultExchangeRegistry;
+import org.apache.qpid.server.exchange.ExchangeRegistry;
+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 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.
+ */
+public class AMQProtocolSessionMBeanTest extends TestCase
+{
+ private IoSession _mockIOSession;
+ private MessageStore _messageStore = new SkeletonMessageStore();
+ private AMQMinaProtocolSession _protocolSession;
+ private AMQChannel _channel;
+ private QueueRegistry _queueRegistry;
+ private ExchangeRegistry _exchangeRegistry;
+ private AMQProtocolSessionMBean _mbean;
+
+ public void testChannels() throws Exception
+ {
+ // check the channel count is correct
+ int channelCount = _mbean.channels().size();
+ assertTrue(channelCount == 1);
+ _protocolSession.addChannel(new AMQChannel(2, _messageStore, null));
+ 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
+ AMQChannel channel3 = new AMQChannel(3, _messageStore, null);
+ channel3.setTransactional(true);
+ _protocolSession.addChannel(channel3);
+ _mbean.rollbackTransactions(2);
+ _mbean.rollbackTransactions(3);
+ _mbean.commitTransactions(2);
+ _mbean.commitTransactions(3);
+
+ // This should throw exception, because the channel does't exist
+ try
+ {
+ _mbean.commitTransactions(4);
+ fail();
+ }
+ catch (JMException ex)
+ {
+ System.out.println("expected exception is thrown :" + ex.getMessage());
+ }
+
+ // check if closing of session works
+ _protocolSession.addChannel(new AMQChannel(5, _messageStore, null));
+ _mbean.closeConnection();
+ try
+ {
+ _mbean.closeChannel(5);
+ fail();
+ }
+ catch(JMException ex)
+ {
+ System.out.println("expected exception is thrown :" + ex.getMessage());
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _channel = new AMQChannel(1, _messageStore, null);
+ _queueRegistry = new DefaultQueueRegistry();
+ _exchangeRegistry = new DefaultExchangeRegistry(new DefaultExchangeFactory());
+ _mockIOSession = new MockIoSession();
+ _protocolSession = new AMQMinaProtocolSession(_mockIOSession, _queueRegistry, _exchangeRegistry, new AMQCodecFactory(true));
+ _protocolSession.addChannel(_channel);
+ _mbean = (AMQProtocolSessionMBean)_protocolSession.getManagedObject();
+ }
+}