KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > microbench > unit > BenchUnitTestCase


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.ejb3.test.microbench.unit;
23
24 import junit.framework.Test;
25 import org.jboss.ejb3.test.microbench.StatelessHomeRemote;
26 import org.jboss.ejb3.test.microbench.StatelessRemote;
27 import org.jboss.ejb3.test.microbench.StatelessRemote21;
28 import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
29 import org.jboss.test.JBossTestCase;
30
31 import javax.management.MBeanServerConnection JavaDoc;
32 import javax.management.ObjectName JavaDoc;
33
34 /**
35  * Sample client for the jboss container.
36  *
37  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
38  * @version $Id: BenchUnitTestCase.java 39547 2006-01-05 19:54:38Z bdecoste $
39  */

40
41 public class BenchUnitTestCase
42         extends JBossTestCase
43 {
44    public BenchUnitTestCase(String JavaDoc name)
45    {
46
47       super(name);
48
49    }
50
51    public void testLocalBenchmark() throws Exception JavaDoc
52    {
53        MBeanServerConnection JavaDoc server = getServer();
54       ObjectName JavaDoc testerName = new ObjectName JavaDoc("jboss.ejb3:service=Benchmark");
55       Object JavaDoc[] params = {new Integer JavaDoc(100000)};
56       String JavaDoc[] sig = {"int"};
57       System.out.println("21Local: " + server.invoke(testerName, "benchLocalStateless21", params, sig));
58       System.out.println("30Local: " + server.invoke(testerName, "benchLocalStateless30", params, sig));
59
60
61    }
62
63    public void testRemoteBenchmark() throws Exception JavaDoc
64    {
65       StatelessRemote remote = (StatelessRemote) getInitialContext().lookup("StatelessBean/remote");
66       StatelessHomeRemote home = (StatelessHomeRemote) getInitialContext().lookup("StatelessBean21Remote");
67       StatelessRemote21 remote21 = home.create();
68
69       long start = System.currentTimeMillis();
70       for (int i = 0; i < 1000; i++)
71       {
72          remote21.test(i);
73       }
74       long end = System.currentTimeMillis() - start;
75       System.out.println("21Remote: " + end);
76
77       start = System.currentTimeMillis();
78       for (int i = 0; i < 1000; i++)
79       {
80          remote.test(i);
81       }
82       end = System.currentTimeMillis() - start;
83       System.out.println("30Remote: " + end);
84
85    }
86
87    public static Test suite() throws Exception JavaDoc
88    {
89       return getDeploySetup(BenchUnitTestCase.class, "benchmark-ejb3-test.sar");
90    }
91
92 }
93
Popular Tags