001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.test;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import de.finix.contelligent.CallData;
024: import de.finix.contelligent.ComponentManager;
025: import de.finix.contelligent.ComponentPath;
026: import de.finix.contelligent.Container;
027: import de.finix.contelligent.Session;
028:
029: public class ResolvePerfTest extends ContelligentTestCase {
030: private CallData callData;
031:
032: private ComponentManager manager;
033:
034: private Session session;
035:
036: final static private ComponentPath existentPath = new ComponentPath(
037: "/contelligent/test/pages/page");
038:
039: final static private ComponentPath nonExistingPath = existentPath
040: .append("bljkdhfljh");
041:
042: final int LOOPS = 10000;
043:
044: /**
045: * Creates a new <code>CResolvePerfTest</code> instance.
046: *
047: * @param name
048: * a <code>String</code> value
049: */
050: public ResolvePerfTest(String name) {
051: super (name);
052: }
053:
054: /**
055: * Here we fetch the <code>CallData</code> and the <code>ComponentManager</code> from the request and set them
056: * as instance variables.
057: *
058: * @exception java.lang.Exception
059: * if an error occurs
060: */
061: public void setUp() throws Exception {
062: session = beginSession("admin", "system-users", "admin");
063: callData = createCallData(session);
064: manager = callData.getActualManager();
065: assertNotNull("No ComponentManager set in CallData", manager);
066: }
067:
068: public void tearDown() throws Exception {
069: endSession(session);
070: }
071:
072: public void testNoOpTime() {
073: // do nothing to check time for setup
074: }
075:
076: public void testComponentExists() throws Throwable {
077: beginTx(callData);
078: try {
079: assertTrue("Container '" + existentPath
080: + "' does not exist!", manager
081: .componentExists(existentPath));
082: for (int i = 0; i < 1000; i++) {
083: manager.componentExists(existentPath);
084: }
085: commitTx();
086: } catch (Throwable t) {
087: rollbackTx();
088: throw t;
089: }
090: }
091:
092: public void testComponentNotExists() throws Throwable {
093: beginTx(callData);
094: try {
095: assertFalse("Container '" + nonExistingPath
096: + "' does not exist!", manager
097: .componentExists(nonExistingPath));
098: for (int i = 0; i < 1000; i++) {
099: manager.componentExists(nonExistingPath);
100: }
101: commitTx();
102: } catch (Throwable t) {
103: rollbackTx();
104: throw t;
105: }
106: }
107:
108: public void testGetExistentComponent() throws Throwable {
109: beginTx(callData);
110: try {
111: assertTrue("Container '" + existentPath
112: + "' does not exist!", manager
113: .componentExists(existentPath));
114: long start = System.currentTimeMillis();
115: for (int i = 0; i < LOOPS; i++) {
116: manager.getComponent(existentPath, callData);
117: }
118: System.err.println("testGetExistentComponent() - " + LOOPS
119: + " loops took "
120: + (System.currentTimeMillis() - start) + " ms.");
121: commitTx();
122: } catch (Throwable t) {
123: rollbackTx();
124: throw t;
125: }
126: }
127:
128: public void testGetExistentSubcomponent() throws Throwable {
129: beginTx(callData);
130: try {
131: Container container = (Container) manager.getComponent(
132: existentPath.parentPath(), callData);
133: String name = existentPath.getName();
134: for (int i = 0; i < LOOPS; i++) {
135: manager
136: .getSubcomponent(container, name, callData,
137: true);
138: }
139: commitTx();
140: } catch (Throwable t) {
141: rollbackTx();
142: throw t;
143: }
144: }
145:
146: public void testHashMap() throws Exception {
147: Map cache = new HashMap();
148: cache.put("jahdja", "lskdleqksd");
149: cache.put("jahdqweja", "lskqwedlksd");
150: cache.put("jdsahdja", "lskwqdlksd");
151: cache.put("jahddasja", "lskqwedlksd");
152: cache.put("jaerhdja", "lskdeqlksd");
153: cache.put("jaheqdja", "lskdqwelksd");
154: cache.put("robin", "sander");
155:
156: long start = System.currentTimeMillis();
157: for (int i = 0; i < LOOPS; i++) {
158: String tmp = (String) cache.get("robin");
159: }
160: long end = System.currentTimeMillis();
161: System.err.println("testHashMap() - " + LOOPS
162: + " loops get() took " + (end - start) + " ms.");
163:
164: start = System.currentTimeMillis();
165: for (int i = 0; i < LOOPS; i++) {
166: String s = (cache.containsKey("robin")) ? (String) cache
167: .get("robin") : "";
168: }
169: end = System.currentTimeMillis();
170: System.err.println("testHashMap() - " + LOOPS
171: + " loops contains/get took " + (end - start) + " ms.");
172: }
173:
174: public void testSynchronizedHashMap() throws Exception {
175: Map cache = new HashMap();
176: cache.put("jahdja", "lskdleqksd");
177: cache.put("jahdqweja", "lskqwedlksd");
178: cache.put("jdsahdja", "lskwqdlksd");
179: cache.put("jahddasja", "lskqwedlksd");
180: cache.put("jaerhdja", "lskdeqlksd");
181: cache.put("jaheqdja", "lskdqwelksd");
182: cache.put("robin", "sander");
183:
184: long start = System.currentTimeMillis();
185: for (int i = 0; i < LOOPS; i++) {
186: synchronized (cache) {
187: String tmp = (String) cache.get("robin");
188: }
189: }
190: long end = System.currentTimeMillis();
191: System.err.println("testSynchronizedHashMap() - " + LOOPS
192: + " loops get() took " + (end - start) + " ms.");
193:
194: start = System.currentTimeMillis();
195: for (int i = 0; i < LOOPS; i++) {
196: synchronized (cache) {
197: String s = (cache.containsKey("robin")) ? (String) cache
198: .get("robin")
199: : "";
200: }
201: }
202: end = System.currentTimeMillis();
203: System.err.println("testSynchronizedHashMap() - " + LOOPS
204: + " loops contains/get took " + (end - start) + " ms.");
205: }
206: }
|