KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > performance > invocationhandler > 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.invocationhandler;
23
24 import junit.framework.TestCase;
25 import test.performance.PerformanceSUITE;
26 import test.performance.invocationhandler.support.Standard;
27 import test.performance.invocationhandler.support.StandardMBean;
28
29 import javax.management.*;
30
31 public class ThroughputTEST extends TestCase
32 {
33
34    public ThroughputTEST(String JavaDoc s)
35    {
36       super(s);
37    }
38
39    public void testThroughput() throws Exception JavaDoc
40    {
41       MyThread myThread = new MyThread();
42       Thread JavaDoc t = new Thread JavaDoc(myThread);
43                            
44       Integer JavaDoc arg0 = new Integer JavaDoc(1234);
45       int arg1 = 5678;
46       Object JavaDoc[][][] arg2 = new Object JavaDoc[][][] {
47                                  {
48                                     { "1x1x1", "1x1x2", "1x1x3" },
49                                     { "1x2x1", "1x2x2", "1x2x3" },
50                                     { "1x3x1", "1x3x2", "1x3x3" }
51                                  },
52                                  
53                                  {
54                                     { "2x1x1", "2x1x2", "2x1x3" },
55                                     { "2x2x1", "2x2x2", "2x2x3" },
56                                     { "2x3x1", "2x3x2", "2x3x3" }
57                                  },
58                                  
59                                  {
60                                     { "3x1x1", "3x1x2", "3x1x3" },
61                                     { "3x2x1", "3x2x2", "3x2x3" },
62                                     { "3x3x1", "3x3x2", "3x3x3" }
63                                  }
64                               };
65       Attribute arg3 = new Attribute("attribute", "value");
66
67       MBeanServer server = MBeanServerFactory.createMBeanServer();
68       ObjectName name = new ObjectName("test:test=test");
69
70       Standard test = new Standard();
71       server.registerMBean(test, name);
72       StandardMBean proxy = (StandardMBean) MBeanServerInvocationHandler.newProxyInstance(
73          server, name, StandardMBean.class, false);
74       
75       t.start();
76       while(myThread.isKeepRunning())
77       {
78          proxy.mixedArguments(arg0, arg1, arg2, arg3);
79       }
80
81          System.out.println("\nMBeanServerInvocationHandler Throughput: " +
82                              test.getCount() / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND) +
83                             " invocations per second.");
84          System.out.println("(Total: " + test.getCount() + ")\n");
85    }
86 /*
87    public void testThroughputProxy() throws Exception
88    {
89       MyThread myThread = new MyThread();
90       Thread t = new Thread(myThread);
91                            
92       Integer arg0 = new Integer(1234);
93       int arg1 = 5678;
94       Object[][][] arg2 = new Object[][][] {
95                                  {
96                                     { "1x1x1", "1x1x2", "1x1x3" },
97                                     { "1x2x1", "1x2x2", "1x2x3" },
98                                     { "1x3x1", "1x3x2", "1x3x3" }
99                                  },
100                                  
101                                  {
102                                     { "2x1x1", "2x1x2", "2x1x3" },
103                                     { "2x2x1", "2x2x2", "2x2x3" },
104                                     { "2x3x1", "2x3x2", "2x3x3" }
105                                  },
106                                  
107                                  {
108                                     { "3x1x1", "3x1x2", "3x1x3" },
109                                     { "3x2x1", "3x2x2", "3x2x3" },
110                                     { "3x3x1", "3x3x2", "3x3x3" }
111                                  }
112                               };
113       Attribute arg3 = new Attribute("attribute", "value");
114
115       MBeanServer server = MBeanServerFactory.createMBeanServer();
116       ObjectName name = new ObjectName("test:test=test");
117
118       Standard test = new Standard();
119       server.registerMBean(test, name);
120       StandardMBean proxy = (StandardMBean) org.jboss.mx.util.MBeanProxy.get(StandardMBean.class, name, server);
121       
122       t.start();
123       while(myThread.isKeepRunning())
124       {
125          proxy.mixedArguments(arg0, arg1, arg2, arg3);
126       }
127
128          System.out.println("\nMBeanProxy Throughput: " +
129                              test.getCount() / (PerformanceSUITE.THROUGHPUT_TIME / PerformanceSUITE.SECOND) +
130                             " invocations per second.");
131          System.out.println("(Total: " + test.getCount() + ")\n");
132    }
133 */

134    class MyThread implements Runnable JavaDoc
135    {
136
137       private boolean keepRunning = true;
138       
139       public void run()
140       {
141          try
142          {
143             Thread.sleep(PerformanceSUITE.THROUGHPUT_TIME);
144          }
145          catch (InterruptedException JavaDoc e)
146          {
147             
148          }
149          
150          keepRunning = false;
151       }
152       
153       public boolean isKeepRunning()
154       {
155          return keepRunning;
156       }
157    }
158 }
159
Popular Tags