001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.systest.management;
019:
020: import java.util.Iterator;
021: import java.util.Set;
022:
023: import javax.management.MBeanServer;
024: import javax.management.ObjectName;
025:
026: import org.apache.cxf.Bus;
027: import org.apache.cxf.bus.spring.SpringBusFactory;
028: import org.apache.cxf.management.InstrumentationManager;
029: import org.apache.cxf.management.ManagementConstants;
030: import org.apache.cxf.management.jmx.InstrumentationManagerImpl;
031: import org.apache.cxf.workqueue.WorkQueueManager;
032: import org.junit.Assert;
033: import org.junit.Test;
034:
035: public class ManagedBusTest extends Assert {
036:
037: @Test
038: public void testManagedSpringBus() throws Exception {
039: SpringBusFactory factory = new SpringBusFactory();
040: Bus bus = factory.createBus();
041: InstrumentationManager im = bus
042: .getExtension(InstrumentationManager.class);
043: assertNotNull(im);
044:
045: InstrumentationManagerImpl imi = (InstrumentationManagerImpl) im;
046: assertEquals(
047: "service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi",
048: imi.getJMXServiceURL());
049: assertTrue(!imi.isEnabled());
050: assertNull(imi.getMBeanServer());
051:
052: //Test that registering without an MBeanServer is a no-op
053: im.register(imi, new ObjectName("org.apache.cxf:foo=bar"));
054:
055: bus.shutdown(true);
056: }
057:
058: @Test
059: public void testManagedBusWithConfig() throws Exception {
060: SpringBusFactory factory = new SpringBusFactory();
061: Bus bus = factory.createBus(
062: "org/apache/cxf/systest/management/managed-spring.xml",
063: true);
064: InstrumentationManager im = bus
065: .getExtension(InstrumentationManager.class);
066: assertNotNull(im);
067: InstrumentationManagerImpl imi = (InstrumentationManagerImpl) im;
068: assertEquals(
069: "service:jmx:rmi:///jndi/rmi://localhost:9916/jmxrmi",
070: imi.getJMXServiceURL());
071: assertTrue(imi.isEnabled());
072: assertNotNull(imi.getMBeanServer());
073:
074: WorkQueueManager manager = bus
075: .getExtension(WorkQueueManager.class);
076: manager.getAutomaticWorkQueue();
077:
078: MBeanServer mbs = im.getMBeanServer();
079: ObjectName name = new ObjectName(
080: ManagementConstants.DEFAULT_DOMAIN_NAME
081: + ":type=WorkQueueMBean,*");
082: Set s = mbs.queryNames(name, null);
083: assertTrue(s.size() == 1);
084: Iterator it = s.iterator();
085: while (it.hasNext()) {
086: ObjectName n = (ObjectName) it.next();
087: Long result = (Long) mbs.invoke(n, "getWorkQueueMaxSize",
088: new Object[0], new String[0]);
089: assertEquals(result, Long.valueOf(250));
090: }
091:
092: name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME
093: + ":type=Bus,*");
094: s = mbs.queryNames(name, null);
095: assertTrue(s.size() == 1);
096: it = s.iterator();
097: while (it.hasNext()) {
098: ObjectName n = (ObjectName) it.next();
099: Object[] params = { Boolean.FALSE };
100: String[] sig = { "boolean" };
101: mbs.invoke(n, "shutdown", params, sig);
102: }
103:
104: bus.shutdown(false);
105: }
106: }
|