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
26 /***
27 * Put a few hundred thousand entries in the disk cache.
28 *
29 * @author Aaron Smuts
30 *
31 */
32 public class HugeQuantityIndDiskCacheLoadTest
33 extends TestCase
34 {
35
36 /***
37 * Test setup
38 */
39 public void setUp()
40 {
41 JCS.setConfigFilename( "/TestDiskCacheHuge.ccf" );
42 }
43
44 /***
45 * Adds items to cache, gets them, and removes them. The item count is more
46 * than the size of the memory cache, so items should spool to disk.
47 *
48 * @param region
49 * Name of the region to access
50 *
51 * @exception Exception
52 * If an error occurs
53 */
54 public void testLargeNumberOfItems()
55 throws Exception
56 {
57 int items = 300000;
58 String region = "testCache1";
59
60 JCS jcs = JCS.getInstance( region );
61
62 try
63 {
64
65 System.out.println( "Start: " + measureMemoryUse() );
66
67
68
69 for ( int i = 0; i <= items; i++ )
70 {
71 jcs.put( i + ":key", region + " data " + i );
72 }
73
74 System.out.println( jcs.getStats() );
75 System.out.println( "--------------------------" );
76 System.out.println( "After put: " + measureMemoryUse() );
77
78 Thread.sleep( 5000 );
79
80 System.out.println( jcs.getStats() );
81 System.out.println( "--------------------------" );
82 System.out.println( "After wait: " + measureMemoryUse() );
83
84
85
86 for ( int i = 0; i <= items; i++ )
87 {
88 String value = (String) jcs.get( i + ":key" );
89
90 assertEquals( region + " data " + i, value );
91 }
92
93 System.out.println( "After get: " + measureMemoryUse() );
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 }
109 finally
110 {
111
112 System.out.println( jcs.getStats() );
113 System.out.println( "--------------------------" );
114 System.out.println( "End: " + measureMemoryUse() );
115 }
116 }
117
118 /***
119 * Measure memory used by the VM.
120 *
121 * @return
122 * @throws InterruptedException
123 */
124 protected long measureMemoryUse()
125 throws InterruptedException
126 {
127 System.gc();
128 Thread.sleep( 3000 );
129 System.gc();
130 return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
131 }
132 }