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