1 package org.apache.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
26 import org.apache.jcs.JCS;
27
28 /***
29 * Test which exercises the indexed disk cache. Runs three threads against the
30 * same region.
31 *
32 * @version $Id: TestDiskCacheConcurrent.java,v 1.8 2005/02/01 00:01:59 asmuts
33 * Exp $
34 */
35 public class IndexedDiskCacheSameRegionConcurrentUnitTest
36 extends TestCase
37 {
38 /***
39 * Constructor for the TestDiskCache object.
40 *
41 * @param testName
42 */
43 public IndexedDiskCacheSameRegionConcurrentUnitTest( String testName )
44 {
45 super( testName );
46 }
47
48 /***
49 * Main method passes this test to the text test runner.
50 *
51 * @param args
52 */
53 public static void main( String args[] )
54 {
55 String[] testCaseName = { IndexedDiskCacheSameRegionConcurrentUnitTest.class.getName() };
56 junit.textui.TestRunner.main( testCaseName );
57 }
58
59 /***
60 * A unit test suite for JUnit
61 *
62 * @return The test suite
63 */
64 public static Test suite()
65 {
66 ActiveTestSuite suite = new ActiveTestSuite();
67
68 suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache1" )
69 {
70 public void runTest()
71 throws Exception
72 {
73 this.runTestForRegion( "indexedRegion4", 0, 200 );
74 }
75 } );
76
77 suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache2" )
78 {
79 public void runTest()
80 throws Exception
81 {
82 this.runTestForRegion( "indexedRegion4", 1000, 1200 );
83 }
84 } );
85
86 suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache3" )
87 {
88 public void runTest()
89 throws Exception
90 {
91 this.runTestForRegion( "indexedRegion4", 2000, 2200 );
92 }
93 } );
94
95 suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache4" )
96 {
97 public void runTest()
98 throws Exception
99 {
100 this.runTestForRegion( "indexedRegion4", 2200, 5200 );
101 }
102 } );
103
104 suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache5" )
105 {
106 public void runTest()
107 throws Exception
108 {
109 this.runTestForRegion( "indexedRegion4", 0, 5200 );
110 }
111 } );
112
113 return suite;
114 }
115
116 /***
117 * Test setup
118 */
119 public void setUp()
120 {
121 JCS.setConfigFilename( "/TestDiskCacheCon.ccf" );
122 }
123
124 /***
125 // * Tests the region which uses the indexed disk cache
126 // */
127
128
129
130
131
132
133 /***
134 // * Tests the region which uses the indexed disk cache
135 // */
136
137
138
139
140
141
142 /***
143 * Adds items to cache, gets them, and removes them. The item count is more
144 * than the size of the memory cache, so items should spool to disk.
145 *
146 * @param region
147 * Name of the region to access
148 * @param start
149 * @param end
150 *
151 * @exception Exception
152 * If an error occurs
153 */
154 public void runTestForRegion( String region, int start, int end )
155 throws Exception
156 {
157 JCS jcs = JCS.getInstance( region );
158
159
160
161 for ( int i = start; i <= end; i++ )
162 {
163 jcs.put( i + ":key", region + " data " + i );
164 }
165
166
167
168 for ( int i = start; i <= end; i++ )
169 {
170 String value = (String) jcs.get( i + ":key" );
171
172 assertEquals( region + " data " + i, value );
173 }
174
175
176
177
178
179
180
181
182
183
184
185
186 }
187 }