1 package org.apache.commons.jcs.auxiliary.disk.indexed;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.extensions.ActiveTestSuite;
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25 import org.apache.commons.jcs.JCS;
26 import org.apache.commons.jcs.access.CacheAccess;
27 import org.apache.commons.jcs.engine.behavior.ICacheElement;
28
29 import java.util.HashSet;
30 import java.util.Map;
31 import java.util.Set;
32
33
34
35
36
37 public class IndexedDiskCacheSameRegionConcurrentUnitTest
38 extends TestCase
39 {
40
41
42
43
44
45 public IndexedDiskCacheSameRegionConcurrentUnitTest( String testName )
46 {
47 super( testName );
48 }
49
50
51
52
53
54
55 public static void main( String args[] )
56 {
57 String[] testCaseName = { IndexedDiskCacheSameRegionConcurrentUnitTest.class.getName() };
58 junit.textui.TestRunner.main( testCaseName );
59 }
60
61
62
63
64
65
66 public static Test suite()
67 {
68 ActiveTestSuite suite = new ActiveTestSuite();
69
70 suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache1" )
71 {
72 @Override
73 public void runTest()
74 throws Exception
75 {
76 this.runTestForRegion( "indexedRegion4", 0, 200 );
77 }
78 } );
79
80 suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache2" )
81 {
82 @Override
83 public void runTest()
84 throws Exception
85 {
86 this.runTestForRegion( "indexedRegion4", 1000, 1200 );
87 }
88 } );
89
90 suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache3" )
91 {
92 @Override
93 public void runTest()
94 throws Exception
95 {
96 this.runTestForRegion( "indexedRegion4", 2000, 2200 );
97 }
98 } );
99
100 suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache4" )
101 {
102 @Override
103 public void runTest()
104 throws Exception
105 {
106 this.runTestForRegion( "indexedRegion4", 2200, 5200 );
107 }
108 } );
109
110 suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache5" )
111 {
112 @Override
113 public void runTest()
114 throws Exception
115 {
116 this.runTestForRegion( "indexedRegion4", 0, 5100 );
117 }
118 } );
119
120 return suite;
121 }
122
123
124
125
126 @Override
127 public void setUp()
128 {
129 JCS.setConfigFilename( "/TestDiskCacheCon.ccf" );
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162 public void runTestForRegion( String region, int start, int end )
163 throws Exception
164 {
165 CacheAccess<String, String> jcs = JCS.getInstance( region );
166
167
168
169 for ( int i = start; i <= end; i++ )
170 {
171 jcs.put( i + ":key", region + " data " + i );
172 }
173
174
175
176 for ( int i = start; i <= end; i++ )
177 {
178 String key = i + ":key";
179 String value = jcs.get( key );
180
181 assertEquals( "Wrong value for key [" + key + "]", region + " data " + i, value );
182 }
183
184
185 Set<String> keys = new HashSet<String>();
186 for ( int i = start; i <= end; i++ )
187 {
188 keys.add( i + ":key" );
189 }
190
191 Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
192 for ( int i = start; i <= end; i++ )
193 {
194 ICacheElement<String, String> element = elements.get( i + ":key" );
195 assertNotNull( "element " + i + ":key is missing", element );
196 assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
197 }
198
199
200
201
202
203
204
205
206
207 }
208 }