View Javadoc
1   package org.apache.commons.jcs3.engine.control;
2   
3   import org.apache.commons.jcs3.engine.CacheStatus;
4   import org.apache.commons.jcs3.engine.CompositeCacheAttributes;
5   
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  /** Unit tests for the composite cache manager */
29  public class CompositeCacheManagerTest
30      extends TestCase
31  {
32  
33      /**
34       * Verify that calling release, when there are active clients, the caches are correctly disposed or not.
35       */
36      public void testRelease()
37      {
38          // See JCS-184
39          // create the manager
40          final CompositeCacheManager manager = CompositeCacheManager.getInstance();
41          // add a simple cache
42          final CompositeCacheAttributes cacheAttributes = new CompositeCacheAttributes();
43          final CompositeCache<String, String> cache = new CompositeCache<>(cacheAttributes, /* attr */ null);
44          manager.addCache("simple_cache", cache);
45          // add a client to the cache
46          CompositeCacheManager.getUnconfiguredInstance();
47          // won't release as there are still clients. Only disposed when release() is called by
48          // the last client
49          manager.release();
50          assertEquals("The cache was disposed during release!", CacheStatus.ALIVE, cache.getStatus());
51          manager.release();
52          assertEquals("The cache was NOT disposed during release!", CacheStatus.DISPOSED, cache.getStatus());
53      }
54  
55  }