KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > performance > standard > InvocationTEST


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