01: /*
02: Copyright 2004 Philip Jacob <phil@whirlycott.com>
03: Seth Fitzsimmons <seth@note.amherst.edu>
04:
05: Licensed under the Apache License, Version 2.0 (the "License");
06: you may not use this file except in compliance with the License.
07: You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: */
17:
18: package com.whirlycott.cache.test;
19:
20: import junit.framework.TestCase;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24:
25: import com.whirlycott.cache.Cache;
26: import com.whirlycott.cache.CacheManager;
27:
28: /**
29: * @author phil
30: */
31: public class ExpirationTest extends TestCase {
32:
33: private static Log log = LogFactory.getLog(ExpirationTest.class);
34:
35: public static void main(String[] args) throws Exception {
36: log.debug("Single threaded tests...");
37: ExpirationTest whirlytest = new ExpirationTest();
38: whirlytest.testExpiration();
39: }
40:
41: public void testExpiration() throws Exception {
42: final Cache c = CacheManager.getInstance().getCache();
43: assertNotNull(c);
44:
45: final long startTime = System.currentTimeMillis();
46:
47: // Store some values
48: c.store("first", "10 seconds", 10000L);
49: c.store("second", "30 seconds", 30000L);
50: c.store("third", "45 seconds", 45000L);
51: c.store("fourth", "2 minutes", 120000L);
52:
53: //BEGIN RETRIEVES
54: boolean empty = false;
55: while (!empty) {
56: log.debug("Elapsed time: "
57: + new Long(System.currentTimeMillis() - startTime));
58: final Object first = c.retrieve("first");
59: final Object second = c.retrieve("second");
60: final Object third = c.retrieve("third");
61: final Object fourth = c.retrieve("fourth");
62: log.debug("First: " + first);
63: log.debug("Second: " + second);
64: log.debug("Third: " + third);
65: log.debug("Fourth: " + fourth);
66: empty = (null == fourth);
67:
68: log.debug("Sleeping for 5 seconds");
69: Thread.sleep(5000L);
70: }
71: }
72: }
|