01: /*
02: * The contents of this file are subject to the Sapient Public License
03: * Version 1.0 (the "License"); you may not use this file except in compliance
04: * with the License. You may obtain a copy of the License at
05: * http://carbon.sf.net/License.html.
06: *
07: * Software distributed under the License is distributed on an "AS IS" basis,
08: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
09: * 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: import javax.ejb.EJBHome;
21:
22: import org.sape.carbon.core.component.Lookup;
23: import org.sape.carbon.core.exception.ExceptionUtility;
24: import org.sape.carbon.services.ejb.remote.RemoteHomeFactory;
25:
26: import junit.framework.Test;
27: import junit.framework.TestCase;
28: import junit.framework.TestSuite;
29:
30: public class LocalHomeCachePerformanceTest extends TestCase {
31:
32: /**
33: * Path of the remote home factory test component
34: */
35: public static final String TEST_REMOTE_HOME_FACTORY = "/ejb/test/RemoteHomeFactoryTest";
36:
37: /**
38: * Logical name of the <code>Tester</code> EJB
39: */
40: public static final String TEST_REMOTE_EJB = "org.sape.carbon.services.ejb.local.test.LocalGateway";
41:
42: /**
43: * Number of iterations used in testing the home-interface cache
44: */
45: public static final long TEST_LOOKUP_ITERATIONS = 2000;
46:
47: public LocalHomeCachePerformanceTest(String name) {
48: super (name);
49: }
50:
51: public static void main(String args[]) throws Exception {
52: }
53:
54: /**
55: * Tests the performance of the EJB service's home-interface cache
56: * functionality.
57: */
58: public void testLocalHomeCachePerformance() {
59:
60: long startTime = 0;
61: long elapsedTime = 0;
62:
63: RemoteHomeFactory homeFactory = (RemoteHomeFactory) Lookup
64: .getInstance().fetchComponent(TEST_REMOTE_HOME_FACTORY);
65:
66: // Conduct the performance test on the LocalHomeFactory
67: try {
68: EJBHome ejbHome = homeFactory
69: .lookup("org.sape.carbon.services.ejb.local.test.LocalGateway");
70:
71: LocalGateway gateway = ((LocalGatewayHome) ejbHome)
72: .create();
73:
74: gateway.testLocalHomeCachePerformance();
75: } catch (Exception e) {
76: fail("Test of EJB home cache performance for LocalHomeFactory "
77: + "failed due to: "
78: + e
79: + ": "
80: + ExceptionUtility.printStackTracesToString(e));
81: }
82: }
83:
84: /**
85: * Method called by jUnit to get all the tests in this test case.
86: * @return Test the suite of tests in this test case
87: */
88: public static Test suite() {
89:
90: TestSuite test = new TestSuite();
91:
92: test.addTest(new LocalHomeCachePerformanceTest(
93: "testLocalHomeCachePerformance"));
94:
95: return test;
96: }
97: }
|