001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package test.performance.modelmbean;
023:
024: import junit.framework.TestCase;
025: import test.performance.PerformanceSUITE;
026: import test.performance.modelmbean.support.Resource;
027:
028: import javax.management.*;
029: import javax.management.modelmbean.*;
030:
031: public class ThroughputTEST extends TestCase {
032:
033: public ThroughputTEST(String s) {
034: super (s);
035: }
036:
037: public void testThroughput() throws Exception {
038: MyThread myThread = new MyThread();
039: Thread t = new Thread(myThread);
040:
041: String method = "invokeMixedArgs";
042: String[] signature = new String[] { Integer.class.getName(),
043: String.class.getName(), Object[][][].class.getName(),
044: Attribute.class.getName() };
045:
046: Object[] args = new Object[] {
047: new Integer(1234),
048: "Hello",
049: new Object[][][] {
050: { { "1x1x1", "1x1x2", "1x1x3" },
051: { "1x2x1", "1x2x2", "1x2x3" },
052: { "1x3x1", "1x3x2", "1x3x3" } },
053:
054: { { "2x1x1", "2x1x2", "2x1x3" },
055: { "2x2x1", "2x2x2", "2x2x3" },
056: { "2x3x1", "2x3x2", "2x3x3" } },
057:
058: { { "3x1x1", "3x1x2", "3x1x3" },
059: { "3x2x1", "3x2x2", "3x2x3" },
060: { "3x3x1", "3x3x2", "3x3x3" } } },
061: new Attribute("attribute", "value") };
062:
063: MBeanServer server = MBeanServerFactory.createMBeanServer();
064: ObjectName name = new ObjectName("test:test=test");
065:
066: Resource res = new Resource();
067: RequiredModelMBean rmm = new RequiredModelMBean();
068: rmm.setModelMBeanInfo(getManagementInterface());
069: rmm.setManagedResource(res, "ObjectReference");
070:
071: server.registerMBean(rmm, name);
072:
073: t.start();
074: while (myThread.isKeepRunning()) {
075: server.invoke(name, method, args, signature);
076: }
077:
078: System.out
079: .println("\nModel MBean Throughput: "
080: + res.getCount()
081: / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND)
082: + " invocations per second.");
083: System.out.println("(Total: " + res.getCount() + ")\n");
084: }
085:
086: class MyThread implements Runnable {
087:
088: private boolean keepRunning = true;
089:
090: public void run() {
091: try {
092: Thread.sleep(PerformanceSUITE.THROUGHPUT_TIME);
093: } catch (InterruptedException e) {
094:
095: }
096:
097: keepRunning = false;
098: }
099:
100: public boolean isKeepRunning() {
101: return keepRunning;
102: }
103: }
104:
105: private ModelMBeanInfo getManagementInterface() {
106: final boolean READABLE = true;
107: final boolean WRITABLE = true;
108: final boolean BOOLEAN = true;
109:
110: // registerMBean operation
111: DescriptorSupport descMixedArgs = new DescriptorSupport();
112: descMixedArgs.setField("name", "invokeMixedArgs");
113: descMixedArgs.setField("descriptorType", "operation");
114: descMixedArgs.setField("role", "operation");
115: MBeanParameterInfo[] mixedArgsParms = new MBeanParameterInfo[] {
116: new MBeanParameterInfo("Arg1", Integer.class.getName(),
117: "Desc"),
118: new MBeanParameterInfo("Arg2", String.class.getName(),
119: "Desc"),
120: new MBeanParameterInfo("Arg3", Object[][][].class
121: .getName(), "Desc"),
122: new MBeanParameterInfo("Arg3", Attribute.class
123: .getName(), "Desc") };
124: ModelMBeanOperationInfo invokeMixedArgs = new ModelMBeanOperationInfo(
125: "invokeMixedArgs", "Desc", mixedArgsParms, void.class
126: .getName(),
127: ModelMBeanOperationInfo.ACTION_INFO, descMixedArgs);
128:
129: // Construct the modelmbean
130: DescriptorSupport descMBean = new DescriptorSupport();
131: descMBean.setField("name", RequiredModelMBean.class.getName());
132: descMBean.setField("descriptorType", "MBean");
133: ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(
134: RequiredModelMBean.class.getName(), "Resource",
135: new ModelMBeanAttributeInfo[0],
136: (ModelMBeanConstructorInfo[]) null,
137: new ModelMBeanOperationInfo[] { invokeMixedArgs },
138: (ModelMBeanNotificationInfo[]) null, descMBean);
139:
140: return info;
141: }
142:
143: }
|