2
* Copyright 2003-2010 Terracotta, Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package net.sf.ehcache.config;
19
import junit.framework.TestCase;
20
import net.sf.ehcache.Cache;
21
import net.sf.ehcache.CacheManager;
22
import net.sf.ehcache.config.TerracottaConfiguration.StorageStrategy;
24
import org.junit.Test;
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
29
* @author Abhishek Sanoujam
31
public class StorageStrategyConfigTest extends TestCase {
33
private static final Logger LOG = LoggerFactory.getLogger(StorageStrategyConfigTest.class);
36
public void testStorageStrategyConfig() {
37
CacheManager cacheManager = new CacheManager(this.getClass().getResourceAsStream("/ehcache-storage-strategy.xml"));
38
Cache cache = cacheManager.getCache("defaultStorageStrategy");
39
StorageStrategy storageStrategy = cache.getCacheConfiguration().getTerracottaConfiguration().getStorageStrategy();
40
LOG.info("default storageStrategy: " + storageStrategy);
41
StorageStrategy defaultStorageStrategy = StorageStrategy.DCV2;
42
assertEquals("Default storageStrategy should be: " + defaultStorageStrategy, defaultStorageStrategy, storageStrategy);
44
cache = cacheManager.getCache("classicStorageStrategy");
45
storageStrategy = cache.getCacheConfiguration().getTerracottaConfiguration().getStorageStrategy();
46
LOG.info("classic storageStrategy: " + storageStrategy);
47
assertEquals(StorageStrategy.CLASSIC, storageStrategy);
49
cache = cacheManager.getCache("DCV2StorageStrategy");
50
storageStrategy = cache.getCacheConfiguration().getTerracottaConfiguration().getStorageStrategy();
51
LOG.info("DCV2 storageStrategy: " + storageStrategy);
52
assertEquals(StorageStrategy.DCV2, storageStrategy);
54
TerracottaConfiguration config = cache.getCacheConfiguration().getTerracottaConfiguration();
55
config.setStorageStrategy("classic");
56
assertEquals(StorageStrategy.CLASSIC, config.getStorageStrategy());
58
config.setStorageStrategy("DCV2");
59
assertEquals(StorageStrategy.DCV2, config.getStorageStrategy());
61
config.storageStrategy("classic");
62
assertEquals(StorageStrategy.CLASSIC, config.getStorageStrategy());
64
config.storageStrategy("DCV2");
65
assertEquals(StorageStrategy.DCV2, config.getStorageStrategy());
67
config.storageStrategy(StorageStrategy.CLASSIC);
68
assertEquals(StorageStrategy.CLASSIC, config.getStorageStrategy());
70
config.storageStrategy(StorageStrategy.DCV2);
71
assertEquals(StorageStrategy.DCV2, config.getStorageStrategy());