KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > ejb > local > test > LocalHomeCachePerformanceTest


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.ejb.local.test;
19
20
21 import javax.ejb.EJBHome JavaDoc;
22
23 import org.sape.carbon.core.component.Lookup;
24 import org.sape.carbon.core.exception.ExceptionUtility;
25 import org.sape.carbon.services.ejb.remote.RemoteHomeFactory;
26
27 import junit.framework.Test;
28 import junit.framework.TestCase;
29 import junit.framework.TestSuite;
30
31 public class LocalHomeCachePerformanceTest extends TestCase {
32
33     /**
34      * Path of the remote home factory test component
35      */

36     public static final String JavaDoc TEST_REMOTE_HOME_FACTORY =
37         "/ejb/test/RemoteHomeFactoryTest";
38
39
40     /**
41      * Logical name of the <code>Tester</code> EJB
42      */

43     public static final String JavaDoc TEST_REMOTE_EJB =
44         "org.sape.carbon.services.ejb.local.test.LocalGateway";
45
46
47     /**
48      * Number of iterations used in testing the home-interface cache
49      */

50     public static final long TEST_LOOKUP_ITERATIONS = 2000;
51
52
53     public LocalHomeCachePerformanceTest(String JavaDoc name) {
54         super(name);
55     }
56
57
58     public static void main(String JavaDoc args[]) throws Exception JavaDoc{
59     }
60
61
62     /**
63      * Tests the performance of the EJB service's home-interface cache
64      * functionality.
65      */

66     public void testLocalHomeCachePerformance() {
67
68         long startTime = 0;
69         long elapsedTime = 0;
70
71         RemoteHomeFactory homeFactory = (RemoteHomeFactory)
72             Lookup.getInstance().fetchComponent(TEST_REMOTE_HOME_FACTORY);
73
74         // Conduct the performance test on the LocalHomeFactory
75
try {
76             EJBHome JavaDoc ejbHome =
77                 homeFactory.lookup("org.sape.carbon.services.ejb.local.test.LocalGateway");
78
79             LocalGateway gateway = ((LocalGatewayHome) ejbHome).create();
80
81             gateway.testLocalHomeCachePerformance();
82         } catch (Exception JavaDoc e) {
83             fail("Test of EJB home cache performance for LocalHomeFactory "
84                 + "failed due to: "
85                 + e
86                 + ": "
87                 + ExceptionUtility.printStackTracesToString(e));
88         }
89     }
90
91     /**
92      * Method called by jUnit to get all the tests in this test case.
93      * @return Test the suite of tests in this test case
94      */

95     public static Test suite() {
96
97         TestSuite test = new TestSuite();
98
99         test.addTest(new LocalHomeCachePerformanceTest(
100             "testLocalHomeCachePerformance"));
101
102         return test;
103     }
104 }
105
Popular Tags