KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > perf > test > PerfUnitTestCase


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.test.perf.test;
23
24 import java.io.IOException JavaDoc;
25 import java.rmi.RemoteException JavaDoc;
26 import javax.ejb.CreateException JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31 import junit.framework.Test;
32 import junit.framework.TestCase;
33 import junit.framework.TestSuite;
34
35 import org.jboss.test.perf.interfaces.PerfResult;
36 import org.jboss.test.perf.interfaces.PerfTestSession;
37 import org.jboss.test.perf.interfaces.PerfTestSessionHome;
38 import org.jboss.test.perf.interfaces.Probe;
39 import org.jboss.test.perf.interfaces.ProbeHome;
40
41 import org.jboss.test.JBossTestCase;
42
43 /** Tests of the Probe session bean method call overhead inside
44 of the JBoss VM. This is performed using the PerfTestSession
45 wrapper.
46  
47  @author Scott.Stark@jboss.org
48  @version $Revision: 37406 $
49 */

50 public class PerfUnitTestCase extends JBossTestCase
51 {
52    int iterationCount;
53    
54    public PerfUnitTestCase(String JavaDoc name)
55    {
56       super(name);
57       iterationCount = getIterationCount();
58    }
59
60    public void testInVMCalls() throws Exception JavaDoc
61    {
62       getLog().debug("+++ testInVMCalls()");
63       Object JavaDoc obj = getInitialContext().lookup("PerfTestSession");
64       obj = PortableRemoteObject.narrow(obj, PerfTestSessionHome.class);
65       PerfTestSessionHome home = (PerfTestSessionHome) obj;
66       getLog().debug("Found PerfTestSessionHome @ jndiName=PerfTestSessionHome");
67       PerfTestSession bean = home.create();
68       getLog().debug("Created PerfTestSession");
69       long start = System.currentTimeMillis();
70       PerfResult result = bean.runProbeTests(iterationCount);
71       String JavaDoc report = result.report;
72       long end = System.currentTimeMillis();
73       long elapsed = end - start;
74       getLog().debug("Elapsed time = "+(elapsed / iterationCount));
75       getLog().info("The testInVMCalls report is:\n"+report);
76       if( result.error != null )
77          throw result.error;
78    }
79
80    public void testInVMLocalCalls() throws Exception JavaDoc
81    {
82       getLog().debug("+++ testInVMLocalCalls()");
83       Object JavaDoc obj = getInitialContext().lookup("PerfTestSession");
84       obj = PortableRemoteObject.narrow(obj, PerfTestSessionHome.class);
85       PerfTestSessionHome home = (PerfTestSessionHome) obj;
86       getLog().debug("Found PerfTestSessionHome @ jndiName=PerfTestSessionHome");
87       PerfTestSession bean = home.create();
88       getLog().debug("Created PerfTestSession");
89       long start = System.currentTimeMillis();
90       PerfResult result = bean.runProbeLocalTests(iterationCount);
91       String JavaDoc report = result.report;
92       long end = System.currentTimeMillis();
93       long elapsed = end - start;
94       getLog().debug("Elapsed time = "+(elapsed / iterationCount));
95       getLog().info("The testInVMLocalCalls report is:\n"+report);
96       if( result.error != null )
97          throw result.error;
98    }
99
100    public static Test suite() throws Exception JavaDoc
101    {
102       Test test = getDeploySetup(PerfUnitTestCase.class, "probe.jar");
103       return test;
104    }
105
106 }
107
Popular Tags