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.framework.TestCase;
23
24 import org.apache.jcs.JCS;
25 import org.apache.jcs.access.TestCacheAccess;
26
27 /***
28 * This is used by other tests to generate a random load on the disk cache.
29 */
30 public class IndexedDiskCacheRandomConcurrentTestUtil
31 extends TestCase
32 {
33
34 /***
35 * Constructor for the TestDiskCache object.
36 *
37 * @param testName
38 */
39 public IndexedDiskCacheRandomConcurrentTestUtil( String testName )
40 {
41 super( testName );
42 }
43
44 /***
45 * Randomly adds items to cache, gets them, and removes them. The range
46 * count is more than the size of the memory cache, so items should spool to
47 * disk.
48 *
49 * @param region
50 * Name of the region to access
51 * @param range
52 * @param numOps
53 * @param testNum
54 *
55 * @exception Exception
56 * If an error occurs
57 */
58 public void runTestForRegion( String region, int range, int numOps, int testNum )
59 throws Exception
60 {
61
62 TestCacheAccess tca = new TestCacheAccess( "/TestDiskCacheCon.ccf" );
63 tca.setRegion( region );
64 tca.random( range, numOps );
65
66
67
68 JCS jcs = JCS.getInstance( region );
69 String key = "testKey" + testNum;
70 String data = "testData" + testNum;
71 jcs.put( key, data );
72 String value = (String) jcs.get( key );
73 assertEquals( data, value );
74
75 }
76
77 /***
78 * Test setup
79 */
80 public void setUp()
81 {
82 JCS.setConfigFilename( "/TestDiskCacheCon.ccf" );
83 }
84
85 }