KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > cache > validator > test > TimeoutValidatorTestCase


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.cache.validator.test;
9
10 import org.apache.avalon.excalibur.cache.Cache;
11 import org.apache.avalon.excalibur.cache.LRUCache;
12 import org.apache.avalon.excalibur.cache.ValidatingCache;
13 import org.apache.avalon.excalibur.cache.validator.TimeoutValidator;
14 import junit.framework.TestCase;
15
16 /**
17  * JUnit TestCase for TimeoutValidator.
18  *
19  * @author <a HREF="mailto:colus@apache.org">Eung-ju Park</a>
20  */

21 public class TimeoutValidatorTestCase
22     extends TestCase
23 {
24     public TimeoutValidatorTestCase( final String JavaDoc name )
25     {
26         super( name );
27     }
28
29     public void testNotExpired()
30         throws InterruptedException JavaDoc
31     {
32         final TimeoutValidator validator = new TimeoutValidator( 1000 );
33
34         final Cache cache =
35             new ValidatingCache( new LRUCache( 10 ), validator );
36         cache.addListener( validator );
37
38         cache.put( "K1", "V1" );
39
40         Thread.sleep( 100 );
41
42         assertTrue( cache.containsKey( "K1" ) );
43     }
44
45     public void testExpired()
46         throws InterruptedException JavaDoc
47     {
48         final TimeoutValidator validator = new TimeoutValidator( 1000 );
49
50         final Cache cache =
51             new ValidatingCache( new LRUCache( 10 ), validator );
52         cache.addListener( validator );
53
54         cache.put( "K1", "V1" );
55
56         Thread.sleep( 2000 );
57
58         assertTrue( !cache.containsKey( "K1" ) );
59     }
60 }
61
Popular Tags