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