1 package org.apache.jcs;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import junit.framework.TestCase;
23
24 /***
25 *
26 * @author Aaron Smuts
27 *
28 */
29 public class ZeroSizeCacheUnitTest
30 extends TestCase
31 {
32 /*** number to get each loop */
33 private static int items = 20000;
34
35 /***
36 * Test setup
37 * <p>
38 * @throws Exception
39 */
40 public void setUp()
41 throws Exception
42 {
43 JCS.setConfigFilename( "/TestZeroSizeCache.ccf" );
44 JCS.getInstance( "testCache1" );
45 }
46
47 /***
48 * Verify that a 0 size cache does not result in errors. You should be able
49 * to disable a region this way.
50 * @throws Exception
51 *
52 */
53 public void testPutGetRemove()
54 throws Exception
55 {
56 JCS jcs = JCS.getInstance( "testCache1" );
57
58 for ( int i = 0; i <= items; i++ )
59 {
60 jcs.put( i + ":key", "data" + i );
61 }
62
63 // all the gets should be null
64 for ( int i = items; i >= 0; i-- )
65 {
66 String res = (String) jcs.get( i + ":key" );
67 if ( res == null )
68 {
69 assertNull( "[" + i + ":key] should be null", res );
70 }
71 }
72
73 // test removal, should be no exceptions
74 jcs.remove( "300:key" );
75
76 // allow the shrinker to run
77 Thread.sleep( 500 );
78
79 // do it again.
80 for ( int i = 0; i <= items; i++ )
81 {
82 jcs.put( i + ":key", "data" + i );
83 }
84
85 for ( int i = items; i >= 0; i-- )
86 {
87 String res = (String) jcs.get( i + ":key" );
88 if ( res == null )
89 {
90 assertNull( "[" + i + ":key] should be null", res );
91 }
92 }
93
94 System.out.println( jcs.getStats() );
95 }
96 }