KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > performance > dynamic > ThroughputTEST


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 ThroughputTEST extends TestCase
32 {
33
34    public ThroughputTEST(String JavaDoc s)
35    {
36       super(s);
37    }
38
39    public void testInvocation()
40    {
41       try
42       {
43          MyThread myThread = new MyThread();
44          Thread JavaDoc t = new Thread JavaDoc(myThread);
45
46          MBeanServer server = MBeanServerFactory.createMBeanServer();
47          ObjectName name = new ObjectName("Domain:performanceTest=dynamic");
48          Dyn mbean = new Dyn();
49          
50          String JavaDoc method = "mixedArguments";
51          String JavaDoc[] signature = new String JavaDoc[] {
52                                  Integer JavaDoc.class.getName(),
53                                  int.class.getName(),
54                                  Object JavaDoc[][][].class.getName(),
55                                  Attribute.class.getName()
56                               };
57                               
58          Object JavaDoc[] args = new Object JavaDoc[] {
59                                  new Integer JavaDoc(1234),
60                                  new Integer JavaDoc(455617),
61                                  new Object JavaDoc[][][] {
62                                     {
63                                        { "1x1x1", "1x1x2", "1x1x3" },
64                                        { "1x2x1", "1x2x2", "1x2x3" },
65                                        { "1x3x1", "1x3x2", "1x3x3" }
66                                     },
67                                     
68                                     {
69                                        { "2x1x1", "2x1x2", "2x1x3" },
70                                        { "2x2x1", "2x2x2", "2x2x3" },
71                                        { "2x3x1", "2x3x2", "2x3x3" }
72                                     },
73                                     
74                                     {
75                                        { "3x1x1", "3x1x2", "3x1x3" },
76                                        { "3x2x1", "3x2x2", "3x2x3" },
77                                        { "3x3x1", "3x3x2", "3x3x3" }
78                                     }
79                                  },
80                                  new Attribute("attribute", "value")
81                               };
82                                     
83          server.registerMBean(mbean, name);
84
85          assertTrue(mbean.getCount() == 0);
86
87          t.start();
88          while(myThread.isKeepRunning())
89          {
90             Object JavaDoc o = server.invoke(name, method, args, signature);
91          }
92
93          System.out.println("\nDynamic MBean Throughput: " +
94                              mbean.getCount() / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND) +
95                             " invocations per second.");
96          System.out.println("(Total: " + mbean.getCount() + ")\n");
97 // System.out.println("\nDynamic MBean Throughput: " + mbean.getCount() / 3 + " invocations per second.");
98
// System.out.println("(Total: " + mbean.getCount() + ")\n");
99

100       }
101       catch (Throwable JavaDoc t)
102       {
103          t.printStackTrace();
104          fail("Unexpected error: " + t.toString());
105       }
106    }
107
108    
109    public void testInvocationWithDefaultDomain()
110    {
111       try
112       {
113          MyThread myThread = new MyThread();
114          Thread JavaDoc t = new Thread JavaDoc(myThread);
115
116          MBeanServer server = MBeanServerFactory.createMBeanServer();
117          ObjectName name = new ObjectName(":performanceTest=dynamic");
118          Dyn mbean = new Dyn();
119          
120          String JavaDoc method = "mixedArguments";
121          String JavaDoc[] signature = new String JavaDoc[] {
122                                  Integer JavaDoc.class.getName(),
123                                  int.class.getName(),
124                                  Object JavaDoc[][][].class.getName(),
125                                  Attribute.class.getName()
126                               };
127                               
128          Object JavaDoc[] args = new Object JavaDoc[] {
129                                  new Integer JavaDoc(1234),
130                                  new Integer JavaDoc(455617),
131                                  new Object JavaDoc[][][] {
132                                     {
133                                        { "1x1x1", "1x1x2", "1x1x3" },
134                                        { "1x2x1", "1x2x2", "1x2x3" },
135                                        { "1x3x1", "1x3x2", "1x3x3" }
136                                     },
137                                     
138                                     {
139                                        { "2x1x1", "2x1x2", "2x1x3" },
140                                        { "2x2x1", "2x2x2", "2x2x3" },
141                                        { "2x3x1", "2x3x2", "2x3x3" }
142                                     },
143                                     
144                                     {
145                                        { "3x1x1", "3x1x2", "3x1x3" },
146                                        { "3x2x1", "3x2x2", "3x2x3" },
147                                        { "3x3x1", "3x3x2", "3x3x3" }
148                                     }
149                                  },
150                                  new Attribute("attribute", "value")
151                               };
152                                     
153          server.registerMBean(mbean, name);
154
155          assertTrue(mbean.getCount() == 0);
156
157          t.start();
158          while(myThread.isKeepRunning())
159          {
160             Object JavaDoc o = server.invoke(name, method, args, signature);
161          }
162
163          System.out.println("\nDynamic MBean Throughput (DEFAULTDOMAIN): " +
164                              mbean.getCount() / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND) +
165                             " invocations per second.");
166          System.out.println("(Total: " + mbean.getCount() + ")\n");
167          
168       }
169       catch (Throwable JavaDoc t)
170       {
171          t.printStackTrace();
172          fail("Unexpected error: " + t.toString());
173       }
174    }
175    
176    class MyThread implements Runnable JavaDoc
177    {
178
179       private boolean keepRunning = true;
180       
181       public void run()
182       {
183          try
184          {
185             Thread.sleep(PerformanceSUITE.THROUGHPUT_TIME);
186          }
187          catch (InterruptedException JavaDoc e)
188          {
189             
190          }
191          
192          keepRunning = false;
193       }
194       
195       public boolean isKeepRunning()
196       {
197          return keepRunning;
198       }
199    }
200    
201 }
202
Popular Tags