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.dynamic;
023:
024: import junit.framework.TestCase;
025: import test.performance.PerformanceSUITE;
026: import test.performance.dynamic.support.Dyn;
027:
028: import javax.management.*;
029:
030: public class ThroughputTEST extends TestCase {
031:
032: public ThroughputTEST(String s) {
033: super (s);
034: }
035:
036: public void testInvocation() {
037: try {
038: MyThread myThread = new MyThread();
039: Thread t = new Thread(myThread);
040:
041: MBeanServer server = MBeanServerFactory.createMBeanServer();
042: ObjectName name = new ObjectName(
043: "Domain:performanceTest=dynamic");
044: Dyn mbean = new Dyn();
045:
046: String method = "mixedArguments";
047: String[] signature = new String[] {
048: Integer.class.getName(), int.class.getName(),
049: Object[][][].class.getName(),
050: Attribute.class.getName() };
051:
052: Object[] args = new Object[] {
053: new Integer(1234),
054: new Integer(455617),
055: new Object[][][] {
056: { { "1x1x1", "1x1x2", "1x1x3" },
057: { "1x2x1", "1x2x2", "1x2x3" },
058: { "1x3x1", "1x3x2", "1x3x3" } },
059:
060: { { "2x1x1", "2x1x2", "2x1x3" },
061: { "2x2x1", "2x2x2", "2x2x3" },
062: { "2x3x1", "2x3x2", "2x3x3" } },
063:
064: { { "3x1x1", "3x1x2", "3x1x3" },
065: { "3x2x1", "3x2x2", "3x2x3" },
066: { "3x3x1", "3x3x2", "3x3x3" } } },
067: new Attribute("attribute", "value") };
068:
069: server.registerMBean(mbean, name);
070:
071: assertTrue(mbean.getCount() == 0);
072:
073: t.start();
074: while (myThread.isKeepRunning()) {
075: Object o = server.invoke(name, method, args, signature);
076: }
077:
078: System.out
079: .println("\nDynamic MBean Throughput: "
080: + mbean.getCount()
081: / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND)
082: + " invocations per second.");
083: System.out.println("(Total: " + mbean.getCount() + ")\n");
084: // System.out.println("\nDynamic MBean Throughput: " + mbean.getCount() / 3 + " invocations per second.");
085: // System.out.println("(Total: " + mbean.getCount() + ")\n");
086:
087: } catch (Throwable t) {
088: t.printStackTrace();
089: fail("Unexpected error: " + t.toString());
090: }
091: }
092:
093: public void testInvocationWithDefaultDomain() {
094: try {
095: MyThread myThread = new MyThread();
096: Thread t = new Thread(myThread);
097:
098: MBeanServer server = MBeanServerFactory.createMBeanServer();
099: ObjectName name = new ObjectName(":performanceTest=dynamic");
100: Dyn mbean = new Dyn();
101:
102: String method = "mixedArguments";
103: String[] signature = new String[] {
104: Integer.class.getName(), int.class.getName(),
105: Object[][][].class.getName(),
106: Attribute.class.getName() };
107:
108: Object[] args = new Object[] {
109: new Integer(1234),
110: new Integer(455617),
111: new Object[][][] {
112: { { "1x1x1", "1x1x2", "1x1x3" },
113: { "1x2x1", "1x2x2", "1x2x3" },
114: { "1x3x1", "1x3x2", "1x3x3" } },
115:
116: { { "2x1x1", "2x1x2", "2x1x3" },
117: { "2x2x1", "2x2x2", "2x2x3" },
118: { "2x3x1", "2x3x2", "2x3x3" } },
119:
120: { { "3x1x1", "3x1x2", "3x1x3" },
121: { "3x2x1", "3x2x2", "3x2x3" },
122: { "3x3x1", "3x3x2", "3x3x3" } } },
123: new Attribute("attribute", "value") };
124:
125: server.registerMBean(mbean, name);
126:
127: assertTrue(mbean.getCount() == 0);
128:
129: t.start();
130: while (myThread.isKeepRunning()) {
131: Object o = server.invoke(name, method, args, signature);
132: }
133:
134: System.out
135: .println("\nDynamic MBean Throughput (DEFAULTDOMAIN): "
136: + mbean.getCount()
137: / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND)
138: + " invocations per second.");
139: System.out.println("(Total: " + mbean.getCount() + ")\n");
140:
141: } catch (Throwable t) {
142: t.printStackTrace();
143: fail("Unexpected error: " + t.toString());
144: }
145: }
146:
147: class MyThread implements Runnable {
148:
149: private boolean keepRunning = true;
150:
151: public void run() {
152: try {
153: Thread.sleep(PerformanceSUITE.THROUGHPUT_TIME);
154: } catch (InterruptedException e) {
155:
156: }
157:
158: keepRunning = false;
159: }
160:
161: public boolean isKeepRunning() {
162: return keepRunning;
163: }
164: }
165:
166: }
|