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