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