1 package org.apache.commons.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 import org.apache.commons.jcs.access.CacheAccess;
24
25
26
27
28
29 public class RemovalTestUtil
30 extends TestCase
31 {
32
33
34
35
36
37
38
39 public RemovalTestUtil( String testName )
40 {
41 super( testName );
42 }
43
44
45
46
47
48
49
50
51
52
53
54 public void runTestPutThenRemoveCategorical( int start, int end )
55 throws Exception
56 {
57 CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" );
58
59 for ( int i = start; i <= end; i++ )
60 {
61 jcs.put( i + ":key", "data" + i );
62 }
63
64 for ( int i = end; i >= start; i-- )
65 {
66 String res = jcs.get( i + ":key" );
67 assertNotNull( "[" + i + ":key] should not be null", res );
68 }
69
70 for ( int i = start; i <= end; i++ )
71 {
72 jcs.remove( i + ":" );
73 assertNull( jcs.get( i + ":key" ) );
74 }
75 }
76
77
78
79
80
81
82
83
84
85
86
87 public void runPutInRange( int start, int end )
88 throws Exception
89 {
90 CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" );
91
92 for ( int i = start; i <= end; i++ )
93 {
94 jcs.put( i + ":key", "data" + i );
95 }
96
97 for ( int i = end; i >= start; i-- )
98 {
99 String res = jcs.get( i + ":key" );
100 assertNotNull( "[" + i + ":key] should not be null", res );
101 }
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115 public void runGetInRange( int start, int end, boolean check )
116 throws Exception
117 {
118 CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" );
119
120
121 for ( int i = end; i >= start; i-- )
122 {
123 String res = jcs.get( i + ":key" );
124 if ( check )
125 {
126 assertNotNull( "[" + i + ":key] should not be null", res );
127 }
128 }
129 }
130 }