01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.rewriter.rom.test;
06:
07: import com.sun.portal.rewriter.RewriterModule;
08: import com.sun.portal.rewriter.rom.RuleSet;
09: import com.sun.portal.rewriter.rom.RuleSetManager;
10: import com.sun.portal.rewriter.test.util.BasicTestCase;
11: import com.sun.portal.rewriter.test.util.Timer;
12:
13: public class TestRuleSetCache extends BasicTestCase {
14: private static final Timer timer = new Timer();
15:
16: public TestRuleSetCache(String aName) {
17: super (aName);
18: }//constructor
19:
20: public void testWithSimpleTimer() throws Exception {
21: String ruleSetID = storeRandomRuleSet("test_ruleset_cache");
22:
23: RuleSet r;
24: Timer timer = new Timer();
25:
26: //first time
27: timer.start();
28: r = RuleSetManager.getDefault().fetchRuleSet(ruleSetID);
29: timer.stop();
30: long first = timer.getTimeTaken();
31:
32: //second time
33: timer.start();
34: r = RuleSetManager.getDefault().fetchRuleSet(ruleSetID);
35: timer.stop();
36: long second = timer.getTimeTaken();
37: RuleSetManager.getDefault().delete(ruleSetID);
38:
39: String msg = "RuleSet Cache: First it took : " + first
40: + "(s) and Second time it took: " + second + "(s)";
41: assertTrue(msg, ((second < first) && (second < 5))); //second time it should take zero time..
42: }//testWithSimpleTimer()
43:
44: public void testEventFiring() throws Exception {
45: String ruleSetID = storeRandomRuleSet("test_ruleset_cache");
46: RuleSet r;
47: //first time
48: timer.start();
49: r = RuleSetManager.getDefault().fetchRuleSet(ruleSetID);
50: timer.stop();
51: long first = timer.getTimeTaken();
52:
53: //store so that id is removed from cache
54: setUp();
55:
56: //second time
57: timer.start();
58: r = RuleSetManager.getDefault().fetchRuleSet(ruleSetID);
59: timer.stop();
60: long second = timer.getTimeTaken();
61:
62: RuleSetManager.getDefault().delete(ruleSetID);
63: String msg = "RuleSet Cache: First it took : " + first
64: + "(s) and Second time it took: " + second + "(s)";
65: assertTrue(msg, ((second == 0) || (first > 5)
66: && (Math.abs(second - first) >= 0 && (Math.abs(second
67: - first) <= 20)))); //both times it should take almost the same time..
68: }//testEventFiring()
69:
70: public static void main(String[] args) {
71: RewriterModule.initFile();
72: BasicTestCase.run(TestRuleSetCache.class);
73: }//main()
74: }//class TestRuleSetCache
|