1 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 21 public class TimeoutValidatorTestCase 22 extends TestCase 23 { 24 public TimeoutValidatorTestCase( final String name ) 25 { 26 super( name ); 27 } 28 29 public void testNotExpired() 30 throws InterruptedException 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 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 |