1 package org.apache.jcs;
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 /***
25 * Simple methods to be run by active test suites that test removal.
26 *
27 */
28 public class RemovalTestUtil
29 extends TestCase
30 {
31
32 /***
33 * Constructor for the TestSimpleLoad object
34 *
35 * @param testName
36 * Description of the Parameter
37 */
38 public RemovalTestUtil( String testName )
39 {
40 super( testName );
41 }
42
43 /***
44 * Adds elements in the range specified and then removes them using the
45 * categorical or substring removal method.
46 *
47 * @param start
48 * @param end
49 *
50 * @exception Exception
51 * Description of the Exception
52 */
53 public void runTestPutThenRemoveCategorical( int start, int end )
54 throws Exception
55 {
56 JCS jcs = JCS.getInstance( "testCache1" );
57
58 for ( int i = start; i <= end; i++ )
59 {
60 jcs.put( i + ":key", "data" + i );
61 }
62
63 for ( int i = end; i >= start; i-- )
64 {
65 String res = (String) jcs.get( i + ":key" );
66 if ( res == null )
67 {
68 assertNotNull( "[" + i + ":key] should not be null", res );
69 }
70 }
71 System.out.println( "Confirmed that " + ( end - start ) + " items could be found" );
72
73 for ( int i = start; i <= end; i++ )
74 {
75 jcs.remove( i + ":" );
76 assertNull( jcs.get( i + ":key" ) );
77 }
78 System.out.println( "Confirmed that " + ( end - start ) + " items were removed" );
79
80 System.out.println( jcs.getStats() );
81
82 }
83
84 /***
85 * Put items in the cache in this key range. Can be used to verify that
86 * concurrent operations are not effected by things like hierchical removal.
87 *
88 * @param start
89 * int
90 * @param end
91 * int
92 * @throws Exception
93 */
94 public void runPutInRange( int start, int end )
95 throws Exception
96 {
97 JCS jcs = JCS.getInstance( "testCache1" );
98
99 for ( int i = start; i <= end; i++ )
100 {
101 jcs.put( i + ":key", "data" + i );
102 }
103
104 for ( int i = end; i >= start; i-- )
105 {
106 String res = (String) jcs.get( i + ":key" );
107 if ( res == null )
108 {
109 assertNotNull( "[" + i + ":key] should not be null", res );
110 }
111 }
112
113 }
114
115 /***
116 * Just get from start to end.
117 *
118 * @param start
119 * int
120 * @param end
121 * int
122 * @param check
123 * boolean -- check to see if the items are in the cache.
124 * @throws Exception
125 */
126 public void runGetInRange( int start, int end, boolean check )
127 throws Exception
128 {
129 JCS jcs = JCS.getInstance( "testCache1" );
130
131
132 for ( int i = end; i >= start; i-- )
133 {
134 String res = (String) jcs.get( i + ":key" );
135 if ( check && res == null )
136 {
137 assertNotNull( "[" + i + ":key] should not be null", res );
138 }
139
140 }
141
142 }
143
144 }