activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r1424366 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
Date Thu, 20 Dec 2012 08:35:11 GMT
Author: rajdavies
Date: Thu Dec 20 08:35:10 2012
New Revision: 1424366

URL: http://svn.apache.org/viewvc?rev=1424366&view=rev
Log:
Added junit test for HealthViewMBean

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
  (with props)

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java?rev=1424366&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
(added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
Thu Dec 20 08:35:10 2012
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.activemq.broker.jmx;
+
+import java.util.List;
+
+import javax.jms.BytesMessage;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.EmbeddedBrokerTestSupport;
+import org.apache.activemq.broker.BrokerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
+    private static final Logger LOG = LoggerFactory.getLogger(MBeanTest.class);
+    protected MBeanServer mbeanServer;
+    protected String domain = "org.apache.activemq";
+
+
+    protected void setUp() throws Exception {
+        bindAddress = "tcp://localhost:0";
+        useTopic = false;
+        super.setUp();
+        mbeanServer = broker.getManagementContext().getMBeanServer();
+    }
+
+    protected void tearDown() throws Exception {
+
+
+        super.tearDown();
+    }
+
+    @Override
+    protected ConnectionFactory createConnectionFactory() throws Exception {
+        return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
+    }
+
+    protected BrokerService createBroker() throws Exception {
+        BrokerService answer = new BrokerService();
+        answer.setPersistent(true);
+        answer.setDeleteAllMessagesOnStartup(true);
+        answer.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 64);
+        answer.setUseJmx(true);
+
+
+        // allow options to be visible via jmx
+
+        answer.addConnector(bindAddress);
+        return answer;
+    }
+
+    public void testHealthView() throws Exception{
+            Connection connection = connectionFactory.createConnection();
+
+            connection.start();
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            destination = createDestination();
+            MessageProducer producer = session.createProducer(destination);
+            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+            for (int i = 0; i < 60; i++) {
+                BytesMessage message = session.createBytesMessage();
+                message.writeBytes(new byte[1024 *1024]);
+                producer.send(message);
+            }
+            Thread.sleep(1000);
+
+        ObjectName brokerName = assertRegisteredObjectName(domain + ":Type=Health,BrokerName=localhost");
+        HealthViewMBean health =  MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
brokerName, HealthViewMBean.class, true);
+        List<HealthStatus> list = health.healthList();
+        assertEquals(2,list.size());
+
+    }
+
+    protected ObjectName assertRegisteredObjectName(String name) throws MalformedObjectNameException,
NullPointerException {
+        ObjectName objectName = new ObjectName(name);
+        if (mbeanServer.isRegistered(objectName)) {
+            LOG.info("Bean Registered: " + objectName);
+        } else {
+            fail("Could not find MBean!: " + objectName);
+        }
+        return objectName;
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/HealthViewMBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message