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