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