View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
3    *
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
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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.
15   */
16  
17  package net.sf.ehcache.config;
18  
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;
23  
24  import org.junit.Test;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  /***
29   * @author Abhishek Sanoujam
30   */
31  public class StorageStrategyConfigTest extends TestCase {
32  
33      private static final Logger LOG = LoggerFactory.getLogger(StorageStrategyConfigTest.class);
34  
35      @Test
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);
43  
44          cache = cacheManager.getCache("classicStorageStrategy");
45          storageStrategy = cache.getCacheConfiguration().getTerracottaConfiguration().getStorageStrategy();
46          LOG.info("classic storageStrategy: " + storageStrategy);
47          assertEquals(StorageStrategy.CLASSIC, storageStrategy);
48  
49          cache = cacheManager.getCache("DCV2StorageStrategy");
50          storageStrategy = cache.getCacheConfiguration().getTerracottaConfiguration().getStorageStrategy();
51          LOG.info("DCV2 storageStrategy: " + storageStrategy);
52          assertEquals(StorageStrategy.DCV2, storageStrategy);
53  
54          TerracottaConfiguration config = cache.getCacheConfiguration().getTerracottaConfiguration();
55          config.setStorageStrategy("classic");
56          assertEquals(StorageStrategy.CLASSIC, config.getStorageStrategy());
57  
58          config.setStorageStrategy("DCV2");
59          assertEquals(StorageStrategy.DCV2, config.getStorageStrategy());
60  
61          config.storageStrategy("classic");
62          assertEquals(StorageStrategy.CLASSIC, config.getStorageStrategy());
63  
64          config.storageStrategy("DCV2");
65          assertEquals(StorageStrategy.DCV2, config.getStorageStrategy());
66  
67          config.storageStrategy(StorageStrategy.CLASSIC);
68          assertEquals(StorageStrategy.CLASSIC, config.getStorageStrategy());
69  
70          config.storageStrategy(StorageStrategy.DCV2);
71          assertEquals(StorageStrategy.DCV2, config.getStorageStrategy());
72      }
73  
74  }