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