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