KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > performance > dynamic > 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.dynamic;
23
24 import junit.framework.TestCase;
25 import test.performance.PerformanceSUITE;
26 import test.performance.dynamic.support.Dyn;
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("\nDYNAMIC: 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=dynamic");
49          String JavaDoc method = "methodInvocation";
50          long start = 0, end = 0;
51          float avg = 0l;
52
53          server.registerMBean(new Dyn(), 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          MBeanServerFactory.releaseMBeanServer(server);
75       }
76       catch (Throwable JavaDoc t)
77       {
78          t.printStackTrace();
79          fail("Unexpected error: " + t.toString());
80       }
81
82    }
83
84    public void testVoidInvocation()
85    {
86       try
87       {
88          System.out.println("\nDYNAMIC: void invocation");
89          System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT);
90          System.out.println("(this may take a while...)\n");
91
92          MBeanServer server = MBeanServerFactory.createMBeanServer();
93          ObjectName name = new ObjectName("Domain:performanceTest=dynamic");
94          String JavaDoc method = "methodInvocation";
95          long start = 0, end = 0;
96          float avg = 0l;
97
98          server.registerMBean(new Dyn(), name);
99
100          // drop the first batch (+1)
101
for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations)
102          {
103             start = System.currentTimeMillis();
104             for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.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          System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT));
119          MBeanServerFactory.releaseMBeanServer(server);
120       }
121       catch (Throwable JavaDoc t)
122       {
123          t.printStackTrace();
124          fail("Unexpected error: " + t.toString());
125       }
126    }
127
128    public void testCounterInvocation()
129    {
130       try
131       {
132          System.out.println("\nDYNAMIC: counter invocation");
133          System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT);
134          System.out.println("(this may take a while...)\n");
135
136          MBeanServer server = MBeanServerFactory.createMBeanServer();
137          ObjectName name = new ObjectName("Domain:performanceTest=dynamic");
138          Dyn mbean = new Dyn();
139          String JavaDoc method = "counter";
140          long start = 0, end = 0;
141          float avg = 0l;
142
143          server.registerMBean(mbean, name);
144
145          // drop the first batch (+1)
146
for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations)
147          {
148             start = System.currentTimeMillis();
149             for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations)
150             {
151                server.invoke(name, method, null, null);
152             }
153             end = System.currentTimeMillis();
154
155             if (testIterations != 0)
156             {
157                long time = end - start;
158                System.out.print( time + " ");
159                avg += time;
160             }
161          }
162
163          System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT));
164          MBeanServerFactory.releaseMBeanServer(server);
165
166          assertTrue(mbean.getCount() == (PerformanceSUITE.REPEAT_COUNT + 1)*PerformanceSUITE.ITERATION_COUNT);
167       }
168       catch (Throwable JavaDoc t)
169       {
170          t.printStackTrace();
171          fail("Unexpected error: " + t.toString());
172       }
173    }
174
175
176    public void testMixedArgsInvocation()
177    {
178       try
179       {
180          System.out.println("\nDYNAMIC: mixed arguments invocation");
181          System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT);
182          System.out.println("(this may take a while...)\n");
183
184          MBeanServer server = MBeanServerFactory.createMBeanServer();
185          ObjectName name = new ObjectName("Domain:performanceTest=dynamic");
186          Dyn mbean = new Dyn();
187          
188          String JavaDoc method = "mixedArguments";
189          String JavaDoc[] signature = new String JavaDoc[] {
190                                  Integer JavaDoc.class.getName(),
191                                  int.class.getName(),
192                                  Object JavaDoc[][][].class.getName(),
193                                  Attribute.class.getName()
194                               };
195                               
196          Object JavaDoc[] args = new Object JavaDoc[] {
197                                  new Integer JavaDoc(1234),
198                                  new Integer JavaDoc(455617),
199                                  new Object JavaDoc[][][] {
200                                     {
201                                        { "1x1x1", "1x1x2", "1x1x3" },
202                                        { "1x2x1", "1x2x2", "1x2x3" },
203                                        { "1x3x1", "1x3x2", "1x3x3" }
204                                     },
205                                     
206                                     {
207                                        { "2x1x1", "2x1x2", "2x1x3" },
208                                        { "2x2x1", "2x2x2", "2x2x3" },
209                                        { "2x3x1", "2x3x2", "2x3x3" }
210                                     },
211                                     
212                                     {
213                                        { "3x1x1", "3x1x2", "3x1x3" },
214                                        { "3x2x1", "3x2x2", "3x2x3" },
215                                        { "3x3x1", "3x3x2", "3x3x3" }
216                                     }
217                                  },
218                                  new Attribute("attribute", "value")
219                               };
220                                     
221          long start = 0, end = 0;
222          float avg = 0l;
223
224          server.registerMBean(mbean, name);
225
226          // drop the first batch (+1)
227
for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations)
228          {
229             start = System.currentTimeMillis();
230             for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations)
231             {
232                server.invoke(name, method, args, signature);
233             }
234             end = System.currentTimeMillis();
235
236             if (testIterations != 0)
237             {
238                long time = end - start;
239                System.out.print( time + " ");
240                avg += time;
241             }
242          }
243
244          System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT));
245          MBeanServerFactory.releaseMBeanServer(server);
246
247       }
248       catch (Throwable JavaDoc t)
249       {
250          t.printStackTrace();
251          fail("Unexpected error: " + t.toString());
252       }
253    }
254    
255 }
256
Popular Tags