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 java.util.Properties;
23  
24  import junit.framework.TestCase;
25  
26  import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
27  import org.apache.commons.jcs.auxiliary.AuxiliaryCacheConfigurator;
28  import org.apache.commons.jcs.auxiliary.MockAuxiliaryCache;
29  import org.apache.commons.jcs.auxiliary.MockAuxiliaryCacheAttributes;
30  import org.apache.commons.jcs.auxiliary.MockAuxiliaryCacheFactory;
31  import org.apache.commons.jcs.engine.logging.MockCacheEventLogger;
32  
33  /** Unit tests for the configurator. */
34  public class CompositeCacheConfiguratorUnitTest
35      extends TestCase
36  {
37      /**
38       * Verify that we can parse the event logger correctly
39       */
40      public void testParseAuxiliary_CacheEventLogger_Normal()
41      {
42          // SETUP
43          String regionName = "MyRegion";
44  
45          String auxName = "MockAux";
46          String auxPrefix = CompositeCacheConfigurator.AUXILIARY_PREFIX + auxName;
47          String auxiliaryClassName = MockAuxiliaryCacheFactory.class.getName();
48          String eventLoggerClassName = MockCacheEventLogger.class.getName();
49          String auxiliaryAttributeClassName = MockAuxiliaryCacheAttributes.class.getName();
50  
51          Properties props = new Properties();
52          props.put( auxPrefix, auxiliaryClassName );
53          props.put( auxPrefix + CompositeCacheConfigurator.ATTRIBUTE_PREFIX, auxiliaryAttributeClassName );
54          props.put( auxPrefix + AuxiliaryCacheConfigurator.CACHE_EVENT_LOGGER_PREFIX, eventLoggerClassName );
55  
56  //        System.out.print( props );
57  
58          CompositeCacheManager manager = CompositeCacheManager.getUnconfiguredInstance();
59          CompositeCacheConfigurator configurator = new CompositeCacheConfigurator();
60  
61          // DO WORK
62          AuxiliaryCache<String, String> aux = configurator.parseAuxiliary( props, manager, auxName, regionName );
63          MockAuxiliaryCache<String, String> result = (MockAuxiliaryCache<String, String>)aux;
64  
65          // VERIFY
66          assertNotNull( "Should have an auxcache.", result );
67          assertNotNull( "Should have an event logger.", result.getCacheEventLogger() );
68      }
69  
70      /**
71       * Verify that we can parse the spool chunk size
72       */
73      public void testParseSpoolChunkSize_Normal()
74      {
75          // SETUP
76          String regionName = "MyRegion";
77          int chunkSize = 5;
78  
79          Properties props = new Properties();
80          props.put( "jcs.default", "" );
81          props.put( "jcs.default.cacheattributes.SpoolChunkSize", String.valueOf( chunkSize ) );
82  
83          CompositeCacheManager manager = CompositeCacheManager.getUnconfiguredInstance();
84  
85          // DO WORK
86          manager.configure( props );
87  
88          // VERIFY
89          CompositeCache<String, String> cache = manager.getCache( regionName );
90          assertEquals( "Wrong chunkSize", cache.getCacheAttributes().getSpoolChunkSize(), chunkSize );
91      }
92  }