1 package org.apache.jcs;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 /***
25 *
26 * @author Aaron Smuts
27 *
28 */
29 public class ZeroSizeCacheUnitTest
30 extends TestCase
31 {
32 /*** number to get each loop */
33 private static int items = 20000;
34
35 /***
36 * Test setup
37 * <p>
38 * @throws Exception
39 */
40 public void setUp()
41 throws Exception
42 {
43 JCS.setConfigFilename( "/TestZeroSizeCache.ccf" );
44 JCS.getInstance( "testCache1" );
45 }
46
47 /***
48 * Verify that a 0 size cache does not result in errors. You should be able
49 * to disable a region this way.
50 * @throws Exception
51 *
52 */
53 public void testPutGetRemove()
54 throws Exception
55 {
56 JCS jcs = JCS.getInstance( "testCache1" );
57
58 for ( int i = 0; i <= items; i++ )
59 {
60 jcs.put( i + ":key", "data" + i );
61 }
62
63
64 for ( int i = items; i >= 0; i-- )
65 {
66 String res = (String) jcs.get( i + ":key" );
67 if ( res == null )
68 {
69 assertNull( "[" + i + ":key] should be null", res );
70 }
71 }
72
73
74 jcs.remove( "300:key" );
75
76
77 Thread.sleep( 500 );
78
79
80 for ( int i = 0; i <= items; i++ )
81 {
82 jcs.put( i + ":key", "data" + i );
83 }
84
85 for ( int i = items; i >= 0; i-- )
86 {
87 String res = (String) jcs.get( i + ":key" );
88 if ( res == null )
89 {
90 assertNull( "[" + i + ":key] should be null", res );
91 }
92 }
93
94 System.out.println( jcs.getStats() );
95 }
96 }