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.extensions.ActiveTestSuite;
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25
26 /***
27 * Test which exercises the indexed disk cache. This one uses three different
28 * regions for thre threads.
29 *
30 * @version $Id: TestTCPLateralCache.java 536904 2007-05-10 16:03:42Z tv $
31 */
32 public class TestTCPLateralCache
33 extends TestCase
34 {
35 /***
36 * Number of items to cache, twice the configured maxObjects for the memory
37 * cache regions.
38 */
39 private static int items = 200;
40
41 /***
42 * Constructor for the TestDiskCache object.
43 *
44 * @param testName
45 */
46 public TestTCPLateralCache( String testName )
47 {
48 super( testName );
49 }
50
51 /***
52 * Main method passes this test to the text test runner.
53 *
54 * @param args
55 */
56 public static void main( String args[] )
57 {
58 String[] testCaseName = { TestTCPLateralCache.class.getName() };
59 junit.textui.TestRunner.main( testCaseName );
60 }
61
62 /***
63 * A unit test suite for JUnit
64 *
65 * @return The test suite
66 */
67 public static Test suite()
68 {
69 ActiveTestSuite suite = new ActiveTestSuite();
70
71 suite.addTest( new TestTCPLateralCache( "testTcpRegion1_no_receiver" )
72 {
73 public void runTest()
74 throws Exception
75 {
76 this.runTestForRegion( "testTcpRegion1" );
77 }
78 } );
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 return suite;
97 }
98
99 /***
100 * Test setup
101 */
102 public void setUp()
103 {
104 JCS.setConfigFilename( "/TestTCPLateralCache.ccf" );
105 }
106
107 /***
108 * Adds items to cache, gets them, and removes them. The item count is more
109 * than the size of the memory cache, so items should spool to disk.
110 *
111 * @param region
112 * Name of the region to access
113 *
114 * @exception Exception
115 * If an error occurs
116 */
117 public void runTestForRegion( String region )
118 throws Exception
119 {
120 JCS jcs = JCS.getInstance( region );
121
122
123
124 for ( int i = 0; i <= items; i++ )
125 {
126 jcs.put( i + ":key", region + " data " + i );
127 }
128
129
130
131 for ( int i = 0; i <= items; i++ )
132 {
133 String value = (String) jcs.get( i + ":key" );
134
135 assertEquals( region + " data " + i, value );
136 }
137
138
139
140 for ( int i = 0; i <= items; i++ )
141 {
142 jcs.remove( i + ":key" );
143 }
144
145
146
147 for ( int i = 0; i <= items; i++ )
148 {
149 assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
150 }
151 }
152 }