View Javadoc
1   package org.apache.commons.jcs.engine.control;
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  import org.apache.commons.jcs.JCS;
24  import org.apache.commons.jcs.access.CacheAccess;
25  import org.apache.commons.jcs.engine.stats.behavior.ICacheStats;
26  
27  /**
28   * @author Aaron Smuts
29   *
30   */
31  public class CacheManagerStatsUnitTest
32      extends TestCase
33  {
34  
35      /**
36       * Just get the stats after putting a couple entries in the cache.
37       *
38       * @throws Exception
39       */
40      public void testSimpleGetStats() throws Exception
41      {
42          CacheAccess<String, String> cache = JCS.getInstance( "testCache1" );
43  
44          // 1 miss, 1 hit, 1 put
45          cache.get( "testKey" );
46          cache.put( "testKey", "testdata" );
47          // should have 4 hits
48          cache.get( "testKey" );
49          cache.get( "testKey" );
50          cache.get( "testKey" );
51          cache.get( "testKey" );
52  
53          CompositeCacheManager mgr = CompositeCacheManager.getInstance();
54          String statsString = mgr.getStats();
55  
56  //        System.out.println( statsString );
57  
58          assertTrue( "Should have the cacheName in here.", statsString.indexOf("testCache1") != -1 );
59          assertTrue( "Should have the HitCountRam in here.", statsString.indexOf("HitCountRam") != -1 );
60          assertTrue( "Should have the 4 in here.", statsString.indexOf("4") != -1 );
61  
62          ICacheStats[] stats = mgr.getStatistics();
63          int statsLen = stats.length;
64  //        System.out.println( "statsLen = " + statsLen );
65          for ( int i = 0; i < statsLen; i++ )
66          {
67              // TODO finish
68          }
69      }
70  
71  }