View Javadoc
1   package org.apache.commons.jcs3.engine.control;
2   
3   import org.apache.commons.jcs3.JCS;
4   import org.apache.commons.jcs3.access.CacheAccess;
5   import org.apache.commons.jcs3.engine.stats.behavior.ICacheStats;
6   
7   /*
8    * Licensed to the Apache Software Foundation (ASF) under one
9    * or more contributor license agreements.  See the NOTICE file
10   * distributed with this work for additional information
11   * regarding copyright ownership.  The ASF licenses this file
12   * to you under the Apache License, Version 2.0 (the
13   * "License"); you may not use this file except in compliance
14   * with the License.  You may obtain a copy of the License at
15   *
16   *   http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing,
19   * software distributed under the License is distributed on an
20   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21   * KIND, either express or implied.  See the License for the
22   * specific language governing permissions and limitations
23   * under the License.
24   */
25  
26  import junit.framework.TestCase;
27  
28  /**
29   */
30  public class CacheManagerStatsUnitTest
31      extends TestCase
32  {
33  
34      /**
35       * Just get the stats after putting a couple entries in the cache.
36       *
37       * @throws Exception
38       */
39      public void testSimpleGetStats() throws Exception
40      {
41          final CacheAccess<String, String> cache = JCS.getInstance( "testCache1" );
42  
43          // 1 miss, 1 hit, 1 put
44          cache.get( "testKey" );
45          cache.put( "testKey", "testdata" );
46          // should have 4 hits
47          cache.get( "testKey" );
48          cache.get( "testKey" );
49          cache.get( "testKey" );
50          cache.get( "testKey" );
51  
52          final CompositeCacheManager mgr = CompositeCacheManager.getInstance();
53          final String statsString = mgr.getStats();
54  
55  //        System.out.println( statsString );
56  
57          assertTrue( "Should have the cacheName in here.", statsString.indexOf("testCache1") != -1 );
58          assertTrue( "Should have the HitCountRam in here.", statsString.indexOf("HitCountRam") != -1 );
59          assertTrue( "Should have the 4 in here.", statsString.indexOf("4") != -1 );
60  
61          final ICacheStats[] stats = mgr.getStatistics();
62          final int statsLen = stats.length;
63  //        System.out.println( "statsLen = " + statsLen );
64          for ( int i = 0; i < statsLen; i++ )
65          {
66              // TODO finish
67          }
68      }
69  
70  }