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