KickJava   Java API By Example, From Geeks To Geeks.

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