KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmx > performance > standard > InvocationTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jbossmx.performance.standard;
23
24 import org.jboss.test.jbossmx.performance.TestCase;
25 import org.jboss.test.jbossmx.performance.standard.support.Standard;
26
27 import javax.management.*;
28
29
30 public class InvocationTestCase
31    extends TestCase
32 {
33
34    org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass());
35    
36    public InvocationTestCase(String JavaDoc s)
37    {
38       super(s);
39    }
40
41    public void testVoidInvocationWithDefaultDomain()
42    {
43       try
44       {
45          log.debug("\nSTANDARD: void invocation with DefaultDomain");
46          log.debug(ITERATION_COUNT + " Invocations, Repeat: x" + REPEAT_COUNT);
47          log.debug("(this may take a while...)\n");
48
49          MBeanServer server = MBeanServerFactory.createMBeanServer();
50          ObjectName name = new ObjectName(":performanceTest=standard");
51          String JavaDoc method = "methodInvocation";
52          long start = 0, end = 0;
53          float avg = 0l;
54
55          server.registerMBean(new Standard(), name);
56
57          // drop the first batch (+1)
58
for (int testIterations = 0; testIterations < REPEAT_COUNT + 1; ++testIterations)
59          {
60             start = System.currentTimeMillis();
61             for (int invocationIterations = 0; invocationIterations < ITERATION_COUNT; ++invocationIterations)
62             {
63                server.invoke(name, method, null, null);
64             }
65             end = System.currentTimeMillis();
66
67             if (testIterations != 0)
68             {
69                long time = end - start;
70                System.out.print( time + " ");
71                avg += time;
72             }
73          }
74
75          log.debug("\nAverage: " + (avg/REPEAT_COUNT));
76       }
77       catch (Throwable JavaDoc t)
78       {
79          log.debug("failed", t);
80          fail("Unexpected error: " + t.toString());
81       }
82    }
83
84    public void testVoidInvocation()
85    {
86       try
87       {
88          log.debug("\nSTANDARD: void invocation");
89          log.debug(ITERATION_COUNT + " Invocations, Repeat: x" + REPEAT_COUNT);
90          log.debug("(this may take a while...)\n");
91
92          MBeanServer server = MBeanServerFactory.createMBeanServer();
93          ObjectName name = new ObjectName("Domain:performanceTest=standard");
94          String JavaDoc method = "methodInvocation";
95          long start = 0, end = 0;
96          float avg = 0l;
97
98          server.registerMBean(new Standard(), name);
99
100          // drop the first batch (+1)
101
for (int testIterations = 0; testIterations < REPEAT_COUNT + 1; ++testIterations)
102          {
103             start = System.currentTimeMillis();
104             for (int invocationIterations = 0; invocationIterations < ITERATION_COUNT; ++invocationIterations)
105             {
106                server.invoke(name, method, null, null);
107             }
108             end = System.currentTimeMillis();
109
110             if (testIterations != 0)
111             {
112                long time = end - start;
113                System.out.print( time + " ");
114                avg += time;
115             }
116          }
117
118          log.debug("\nAverage: " + (avg/REPEAT_COUNT));
119       }
120       catch (Throwable JavaDoc t)
121       {
122          log.debug("failed", t);
123          fail("Unexpected error: " + t.toString());
124       }
125    }
126
127    public void testCounterInvocation()
128    {
129       try
130       {
131          log.debug("\nSTANDARD: counter invocation");
132          log.debug(ITERATION_COUNT + " Invocations, Repeat: x" + REPEAT_COUNT);
133          log.debug("(this may take a while...)\n");
134
135          MBeanServer server = MBeanServerFactory.createMBeanServer();
136          ObjectName name = new ObjectName("Domain:performanceTest=standard");
137          Standard mbean = new Standard();
138          String JavaDoc method = "counter";
139          long start = 0, end = 0;
140          float avg = 0l;
141
142          server.registerMBean(mbean, name);
143
144          // drop the first batch (+1)
145
for (int testIterations = 0; testIterations < REPEAT_COUNT + 1; ++testIterations)
146          {
147             start = System.currentTimeMillis();
148             for (int invocationIterations = 0; invocationIterations < ITERATION_COUNT; ++invocationIterations)
149             {
150                server.invoke(name, method, null, null);
151             }
152             end = System.currentTimeMillis();
153
154             if (testIterations != 0)
155             {
156                long time = end - start;
157                System.out.print( time + " ");
158                avg += time;
159             }
160          }
161
162          log.debug("\nAverage: " + (avg/REPEAT_COUNT));
163
164          assertTrue(mbean.getCount() == (REPEAT_COUNT + 1)*ITERATION_COUNT);
165       }
166       catch (Throwable JavaDoc t)
167       {
168          log.debug("failed", t);
169          fail("Unexpected error: " + t.toString());
170       }
171    }
172
173
174    public void testMixedArgsInvocation()
175    {
176       try
177       {
178          log.debug("\nSTANDARD: mixed arguments invocation");
179          log.debug(ITERATION_COUNT + " Invocations, Repeat: x" + REPEAT_COUNT);
180          log.debug("(this may take a while...)\n");
181
182          MBeanServer server = MBeanServerFactory.createMBeanServer();
183          ObjectName name = new ObjectName("Domain:performanceTest=standard");
184          Standard mbean = new Standard();
185          
186          String JavaDoc method = "mixedArguments";
187          String JavaDoc[] signature = new String JavaDoc[] {
188                                  Integer JavaDoc.class.getName(),
189                                  int.class.getName(),
190                                  Object JavaDoc[][][].class.getName(),
191                                  Attribute.class.getName()
192                               };
193                               
194          Object JavaDoc[] args = new Object JavaDoc[] {
195                                  new Integer JavaDoc(1234),
196                                  new Integer JavaDoc(455617),
197                                  new Object JavaDoc[][][] {
198                                     {
199                                        { "1x1x1", "1x1x2", "1x1x3" },
200                                        { "1x2x1", "1x2x2", "1x2x3" },
201                                        { "1x3x1", "1x3x2", "1x3x3" }
202                                     },
203                                     
204                                     {
205                                        { "2x1x1", "2x1x2", "2x1x3" },
206                                        { "2x2x1", "2x2x2", "2x2x3" },
207                                        { "2x3x1", "2x3x2", "2x3x3" }
208                                     },
209                                     
210                                     {
211                                        { "3x1x1", "3x1x2", "3x1x3" },
212                                        { "3x2x1", "3x2x2", "3x2x3" },
213                                        { "3x3x1", "3x3x2", "3x3x3" }
214                                     }
215                                  },
216                                  new Attribute("attribute", "value")
217                               };
218                                     
219          long start = 0, end = 0;
220          float avg = 0l;
221
222          server.registerMBean(mbean, name);
223
224          // drop the first batch (+1)
225
for (int testIterations = 0; testIterations < REPEAT_COUNT + 1; ++testIterations)
226          {
227             start = System.currentTimeMillis();
228             for (int invocationIterations = 0; invocationIterations < ITERATION_COUNT; ++invocationIterations)
229             {
230                server.invoke(name, method, args, signature);
231             }
232             end = System.currentTimeMillis();
233
234             if (testIterations != 0)
235             {
236                long time = end - start;
237                System.out.print( time + " ");
238                avg += time;
239             }
240          }
241
242          log.debug("\nAverage: " + (avg/REPEAT_COUNT));
243
244       }
245       catch (Throwable JavaDoc t)
246       {
247          log.debug("failed", t);
248          fail("Unexpected error: " + t.toString());
249       }
250    }
251    
252 }
253
Popular Tags