View Javadoc
1   package org.apache.commons.jcs3;
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 org.apache.commons.jcs3.access.CacheAccess;
23  
24  import junit.framework.TestCase;
25  
26  /**
27   * Runs a few thousand queries.
28   */
29  public class JCSLightLoadUnitTest
30      extends TestCase
31  {
32      /** number to use for the test */
33      private static final int items = 20000;
34  
35      /**
36       * Test setup
37       * @throws Exception
38       */
39      @Override
40      public void setUp()
41          throws Exception
42      {
43          JCS.setConfigFilename( "/TestSimpleLoad.ccf" );
44          JCS.getInstance( "testCache1" );
45      }
46  
47      /**
48       * A unit test for JUnit
49       * @throws Exception Description of the Exception
50       */
51      public void testSimpleLoad()
52          throws Exception
53      {
54          final CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" );
55          //        ICompositeCacheAttributes cattr = jcs.getCacheAttributes();
56          //        cattr.setMaxObjects( 20002 );
57          //        jcs.setCacheAttributes( cattr );
58  
59          for ( int i = 1; i <= items; i++ )
60          {
61              jcs.put( i + ":key", "data" + i );
62          }
63  
64          for ( int i = items; i > 0; i-- )
65          {
66              final String res = jcs.get( i + ":key" );
67              assertNotNull( "[" + i + ":key] should not be null", res );
68          }
69  
70          // test removal
71          jcs.remove( "300:key" );
72          assertNull( jcs.get( "300:key" ) );
73      }
74  }