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.standard;
023:
024: import junit.framework.TestCase;
025: import test.performance.PerformanceSUITE;
026: import test.performance.standard.support.Standard;
027:
028: import javax.management.*;
029:
030: import org.jboss.mx.server.ServerConstants;
031:
032: /**
033: * Tests the performance of the byte code optimized invocation dispatcher.
034: *
035: * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
036: * @version $Revision: 57200 $
037: *
038: */
039: public class OptimizedInvocationTEST extends TestCase implements
040: ServerConstants {
041:
042: public OptimizedInvocationTEST(String s) {
043: super (s);
044: }
045:
046: public void testVoidInvocationWithDefaultDomain() {
047: try {
048: System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true");
049:
050: System.out
051: .println("\nSTANDARD (OPTIMIZED): void invocation with DefaultDomain");
052: System.out.println(PerformanceSUITE.ITERATION_COUNT
053: + " Invocations, Repeat: x"
054: + PerformanceSUITE.REPEAT_COUNT);
055: System.out.println("(this may take a while...)\n");
056:
057: MBeanServer server = MBeanServerFactory.createMBeanServer();
058: ObjectName name = new ObjectName(
059: ":performanceTest=standard");
060: String method = "methodInvocation";
061: long start = 0, end = 0;
062: float avg = 0l;
063:
064: server.registerMBean(new Standard(), name);
065:
066: // drop the first batch (+1)
067: for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) {
068: start = System.currentTimeMillis();
069: for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) {
070: server.invoke(name, method, null, null);
071: }
072: end = System.currentTimeMillis();
073:
074: if (testIterations != 0) {
075: long time = end - start;
076: System.out.print(time + " ");
077: avg += time;
078: }
079: }
080:
081: System.out.println("\nAverage: "
082: + (avg / PerformanceSUITE.REPEAT_COUNT));
083: } catch (Throwable t) {
084: t.printStackTrace();
085: fail("Unexpected error: " + t.toString());
086: } finally {
087: System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false");
088: }
089: }
090:
091: public void testVoidInvocation() {
092: try {
093: System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true");
094:
095: System.out
096: .println("\nSTANDARD (OPTIMIZED): void invocation");
097: System.out.println(PerformanceSUITE.ITERATION_COUNT
098: + " Invocations, Repeat: x"
099: + PerformanceSUITE.REPEAT_COUNT);
100: System.out.println("(this may take a while...)\n");
101:
102: MBeanServer server = MBeanServerFactory.createMBeanServer();
103: ObjectName name = new ObjectName(
104: "Domain:performanceTest=standard");
105: String method = "methodInvocation";
106: long start = 0, end = 0;
107: float avg = 0l;
108:
109: server.registerMBean(new Standard(), name);
110:
111: // drop the first batch (+1)
112: for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) {
113: start = System.currentTimeMillis();
114: for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) {
115: server.invoke(name, method, null, null);
116: }
117: end = System.currentTimeMillis();
118:
119: if (testIterations != 0) {
120: long time = end - start;
121: System.out.print(time + " ");
122: avg += time;
123: }
124: }
125:
126: System.out.println("\nAverage: "
127: + (avg / PerformanceSUITE.REPEAT_COUNT));
128: } catch (Throwable t) {
129: t.printStackTrace();
130: fail("Unexpected error: " + t.toString());
131: } finally {
132: System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false");
133: }
134: }
135:
136: public void testCounterInvocation() {
137: try {
138: System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true");
139:
140: System.out
141: .println("\nSTANDARD (OPTIMIZED): counter invocation");
142: System.out.println(PerformanceSUITE.ITERATION_COUNT
143: + " Invocations, Repeat: x"
144: + PerformanceSUITE.REPEAT_COUNT);
145: System.out.println("(this may take a while...)\n");
146:
147: MBeanServer server = MBeanServerFactory.createMBeanServer();
148: ObjectName name = new ObjectName(
149: "Domain:performanceTest=standard");
150: Standard mbean = new Standard();
151: String method = "counter";
152: long start = 0, end = 0;
153: float avg = 0l;
154:
155: server.registerMBean(mbean, name);
156:
157: // drop the first batch (+1)
158: for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) {
159: start = System.currentTimeMillis();
160: for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) {
161: server.invoke(name, method, null, null);
162: }
163: end = System.currentTimeMillis();
164:
165: if (testIterations != 0) {
166: long time = end - start;
167: System.out.print(time + " ");
168: avg += time;
169: }
170: }
171:
172: System.out.println("\nAverage: "
173: + (avg / PerformanceSUITE.REPEAT_COUNT));
174:
175: assertTrue(mbean.getCount() == (PerformanceSUITE.REPEAT_COUNT + 1)
176: * PerformanceSUITE.ITERATION_COUNT);
177: } catch (Throwable t) {
178: t.printStackTrace();
179: fail("Unexpected error: " + t.toString());
180: } finally {
181: System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false");
182: }
183: }
184:
185: public void testMixedArgsInvocation() {
186: try {
187: System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true");
188:
189: System.out
190: .println("\nSTANDARD (OPTIMIZED): mixed arguments invocation");
191: System.out.println(PerformanceSUITE.ITERATION_COUNT
192: + " Invocations, Repeat: x"
193: + PerformanceSUITE.REPEAT_COUNT);
194: System.out.println("(this may take a while...)\n");
195:
196: MBeanServer server = MBeanServerFactory.createMBeanServer();
197: ObjectName name = new ObjectName(
198: "Domain:performanceTest=standard");
199: Standard mbean = new Standard();
200:
201: String method = "mixedArguments";
202: String[] signature = new String[] {
203: Integer.class.getName(), int.class.getName(),
204: Object[][][].class.getName(),
205: Attribute.class.getName() };
206:
207: Object[] args = new Object[] {
208: new Integer(1234),
209: new Integer(455617),
210: new Object[][][] {
211: { { "1x1x1", "1x1x2", "1x1x3" },
212: { "1x2x1", "1x2x2", "1x2x3" },
213: { "1x3x1", "1x3x2", "1x3x3" } },
214:
215: { { "2x1x1", "2x1x2", "2x1x3" },
216: { "2x2x1", "2x2x2", "2x2x3" },
217: { "2x3x1", "2x3x2", "2x3x3" } },
218:
219: { { "3x1x1", "3x1x2", "3x1x3" },
220: { "3x2x1", "3x2x2", "3x2x3" },
221: { "3x3x1", "3x3x2", "3x3x3" } } },
222: new Attribute("attribute", "value") };
223:
224: long start = 0, end = 0;
225: float avg = 0l;
226:
227: server.registerMBean(mbean, name);
228:
229: // drop the first batch (+1)
230: for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) {
231: start = System.currentTimeMillis();
232: for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) {
233: server.invoke(name, method, args, signature);
234: }
235: end = System.currentTimeMillis();
236:
237: if (testIterations != 0) {
238: long time = end - start;
239: System.out.print(time + " ");
240: avg += time;
241: }
242: }
243:
244: System.out.println("\nAverage: "
245: + (avg / PerformanceSUITE.REPEAT_COUNT));
246:
247: } catch (Throwable t) {
248: t.printStackTrace();
249: fail("Unexpected error: " + t.toString());
250: } finally {
251: System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false");
252: }
253:
254: }
255:
256: }
|