1 package org.apache.commons.jcs3;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.jcs3.access.CacheAccess;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 import junit.framework.TestCase;
44
45
46
47
48 public class JCSRemovalSimpleConcurrentTest
49 extends TestCase
50 {
51 private CacheAccess<String, String> jcs;
52
53
54
55
56
57
58 @Override
59 public void setUp()
60 throws Exception
61 {
62 JCS.setConfigFilename( "/TestRemoval.ccf" );
63 jcs = JCS.getInstance( "testCache1" );
64 }
65
66
67
68
69
70
71 public void testTwoDeepRemoval()
72 throws Exception
73 {
74 final int count = 500;
75
76 for ( int i = 0; i <= count; i++ )
77 {
78 jcs.put( "key:" + i + ":anotherpart", "data" + i );
79 }
80
81 for ( int i = count; i >= 0; i-- )
82 {
83 final String res = jcs.get( "key:" + i + ":anotherpart" );
84 assertNotNull( "[key:" + i + ":anotherpart] should not be null, " + jcs.getStats(), res );
85 }
86
87 for ( int i = 0; i <= count; i++ )
88 {
89 jcs.remove( "key:" + i + ":" );
90 assertNull( jcs.getStats(), jcs.get( "key:" + i + ":anotherpart" ) );
91 }
92
93 }
94
95
96
97
98
99
100 public void testSingleDepthRemoval()
101 throws Exception
102 {
103
104 final int count = 500;
105
106 for ( int i = 0; i <= count; i++ )
107 {
108 jcs.put( i + ":key", "data" + i );
109 }
110
111 for ( int i = count; i >= 0; i-- )
112 {
113 final String res = jcs.get( i + ":key" );
114 assertNotNull( "[" + i + ":key] should not be null", res );
115 }
116
117 for ( int i = 0; i <= count; i++ )
118 {
119 jcs.remove( i + ":" );
120 assertNull( jcs.get( i + ":key" ) );
121 }
122 }
123
124
125
126
127
128
129 public void testClear()
130 throws Exception
131 {
132
133 final int count = 500;
134
135 for ( int i = 0; i <= count; i++ )
136 {
137 jcs.put( i + ":key", "data" + i );
138 }
139
140 for ( int i = count; i >= 0; i-- )
141 {
142 final String res = jcs.get( i + ":key" );
143 assertNotNull( "[" + i + ":key] should not be null", res );
144 }
145 jcs.clear();
146
147 for ( int i = count; i >= 0; i-- )
148 {
149 final String res = jcs.get( i + ":key" );
150 if ( res != null )
151 {
152 assertNull( "[" + i + ":key] should be null after remvoeall" + jcs.getStats(), res );
153 }
154 }
155 }
156
157
158
159
160
161
162 public void testClearRepeatedlyWithoutError()
163 throws Exception
164 {
165 final int count = 500;
166
167 jcs.clear();
168
169 for ( int i = 0; i <= count; i++ )
170 {
171 jcs.put( i + ":key", "data" + i );
172 }
173
174 for ( int i = count; i >= 0; i-- )
175 {
176 final String res = jcs.get( i + ":key" );
177 assertNotNull( "[" + i + ":key] should not be null", res );
178 }
179
180 for ( int i = count; i >= 0; i-- )
181 {
182 jcs.put( i + ":key", "data" + i );
183 jcs.clear();
184 final String res = jcs.get( i + ":key" );
185 if ( res != null )
186 {
187 assertNull( "[" + i + ":key] should be null after remvoeall" + jcs.getStats(), res );
188 }
189 }
190 }
191 }