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.invocationhandler;
023:
024: import junit.framework.TestCase;
025: import test.performance.PerformanceSUITE;
026: import test.performance.invocationhandler.support.Standard;
027: import test.performance.invocationhandler.support.StandardMBean;
028:
029: import javax.management.*;
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: Integer arg0 = new Integer(1234);
042: int arg1 = 5678;
043: Object[][][] arg2 = new Object[][][] {
044: { { "1x1x1", "1x1x2", "1x1x3" },
045: { "1x2x1", "1x2x2", "1x2x3" },
046: { "1x3x1", "1x3x2", "1x3x3" } },
047:
048: { { "2x1x1", "2x1x2", "2x1x3" },
049: { "2x2x1", "2x2x2", "2x2x3" },
050: { "2x3x1", "2x3x2", "2x3x3" } },
051:
052: { { "3x1x1", "3x1x2", "3x1x3" },
053: { "3x2x1", "3x2x2", "3x2x3" },
054: { "3x3x1", "3x3x2", "3x3x3" } } };
055: Attribute arg3 = new Attribute("attribute", "value");
056:
057: MBeanServer server = MBeanServerFactory.createMBeanServer();
058: ObjectName name = new ObjectName("test:test=test");
059:
060: Standard test = new Standard();
061: server.registerMBean(test, name);
062: StandardMBean proxy = (StandardMBean) MBeanServerInvocationHandler
063: .newProxyInstance(server, name, StandardMBean.class,
064: false);
065:
066: t.start();
067: while (myThread.isKeepRunning()) {
068: proxy.mixedArguments(arg0, arg1, arg2, arg3);
069: }
070:
071: System.out
072: .println("\nMBeanServerInvocationHandler Throughput: "
073: + test.getCount()
074: / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND)
075: + " invocations per second.");
076: System.out.println("(Total: " + test.getCount() + ")\n");
077: }
078:
079: /*
080: public void testThroughputProxy() throws Exception
081: {
082: MyThread myThread = new MyThread();
083: Thread t = new Thread(myThread);
084:
085: Integer arg0 = new Integer(1234);
086: int arg1 = 5678;
087: Object[][][] arg2 = new Object[][][] {
088: {
089: { "1x1x1", "1x1x2", "1x1x3" },
090: { "1x2x1", "1x2x2", "1x2x3" },
091: { "1x3x1", "1x3x2", "1x3x3" }
092: },
093:
094: {
095: { "2x1x1", "2x1x2", "2x1x3" },
096: { "2x2x1", "2x2x2", "2x2x3" },
097: { "2x3x1", "2x3x2", "2x3x3" }
098: },
099:
100: {
101: { "3x1x1", "3x1x2", "3x1x3" },
102: { "3x2x1", "3x2x2", "3x2x3" },
103: { "3x3x1", "3x3x2", "3x3x3" }
104: }
105: };
106: Attribute arg3 = new Attribute("attribute", "value");
107:
108: MBeanServer server = MBeanServerFactory.createMBeanServer();
109: ObjectName name = new ObjectName("test:test=test");
110:
111: Standard test = new Standard();
112: server.registerMBean(test, name);
113: StandardMBean proxy = (StandardMBean) org.jboss.mx.util.MBeanProxy.get(StandardMBean.class, name, server);
114:
115: t.start();
116: while(myThread.isKeepRunning())
117: {
118: proxy.mixedArguments(arg0, arg1, arg2, arg3);
119: }
120:
121: System.out.println("\nMBeanProxy Throughput: " +
122: test.getCount() / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND) +
123: " invocations per second.");
124: System.out.println("(Total: " + test.getCount() + ")\n");
125: }
126: */
127: class MyThread implements Runnable {
128:
129: private boolean keepRunning = true;
130:
131: public void run() {
132: try {
133: Thread.sleep(PerformanceSUITE.THROUGHPUT_TIME);
134: } catch (InterruptedException e) {
135:
136: }
137:
138: keepRunning = false;
139: }
140:
141: public boolean isKeepRunning() {
142: return keepRunning;
143: }
144: }
145: }
|