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.Test;
23  import junit.framework.TestCase;
24  import junit.framework.TestSuite;
25  
26  /***
27   * Description of the Class
28   *
29   */
30  public class JCSLightLoadUnitTest
31      extends TestCase
32  {
33  
34      private static int items = 20000;
35  
36      /***
37       * Test setup
38       */
39      public void setUp()
40          throws Exception
41      {
42          JCS.setConfigFilename( "/TestSimpleLoad.ccf" );
43          JCS.getInstance( "testCache1" );
44      }
45  
46      /***
47       * Constructor for the TestSimpleLoad object
48       *
49       * @param testName
50       *            Description of the Parameter
51       */
52      public JCSLightLoadUnitTest( String testName )
53      {
54          super( testName );
55      }
56  
57      /***
58       * Description of the Method
59       *
60       * @param args
61       *            Description of the Parameter
62       */
63      public static void main( String args[] )
64      {
65          String[] testCaseName = { JCSLightLoadUnitTest.class.getName() };
66          junit.textui.TestRunner.main( testCaseName );
67      }
68  
69      /***
70       * A unit test suite for JUnit
71       *
72       * @return The test suite
73       */
74      public static Test suite()
75      {
76          return new TestSuite( JCSLightLoadUnitTest.class );
77      }
78  
79      /***
80       * A unit test for JUnit
81       *
82       * @exception Exception
83       *                Description of the Exception
84       */
85      public void testSimpleLoad()
86          throws Exception
87      {
88          JCS jcs = JCS.getInstance( "testCache1" );
89          //        ICompositeCacheAttributes cattr = jcs.getCacheAttributes();
90          //        cattr.setMaxObjects( 20002 );
91          //        jcs.setCacheAttributes( cattr );
92  
93          for ( int i = 1; i <= items; i++ )
94          {
95              jcs.put( i + ":key", "data" + i );
96          }
97  
98          for ( int i = items; i > 0; i-- )
99          {
100             String res = (String) jcs.get( i + ":key" );
101             if ( res == null )
102             {
103                 assertNotNull( "[" + i + ":key] should not be null", res );
104             }
105         }
106 
107         // test removal
108         jcs.remove( "300:key" );
109         assertNull( jcs.get( "300:key" ) );
110 
111     }
112 
113 }