View Javadoc

1   package net.sf.ehcache.pool;
2   
3   import net.sf.ehcache.Cache;
4   import net.sf.ehcache.CacheManager;
5   import net.sf.ehcache.Element;
6   import org.junit.After;
7   import org.junit.Before;
8   import org.junit.Test;
9   
10  import static org.hamcrest.CoreMatchers.nullValue;
11  import static org.junit.Assert.assertEquals;
12  import static org.junit.Assert.assertThat;
13  
14  /***
15   * @author Ludovic Orban
16   */
17  public class PoolableStoresTest {
18  
19      public static final String DEFAULT_CACHE_MANAGER_SIZE_OF_ENGINE_PROP = "net.sf.ehcache.sizeofengine.default";
20  
21      @Before
22      public void setUp() throws Exception {
23          System.getProperties().setProperty(DEFAULT_CACHE_MANAGER_SIZE_OF_ENGINE_PROP,
24                  "net.sf.ehcache.pool.impl.ConstantSizeOfEngine");
25      }
26  
27      @After
28      public void tearDown() throws Exception {
29          System.getProperties().remove(DEFAULT_CACHE_MANAGER_SIZE_OF_ENGINE_PROP);
30          assertThat(System.getProperties().getProperty(DEFAULT_CACHE_MANAGER_SIZE_OF_ENGINE_PROP), nullValue());
31      }
32  
33      @Test
34      public void test() throws Exception {
35          CacheManager cm = new CacheManager(PoolableStoresTest.class.getResourceAsStream("/pool/ehcache-heap-disk.xml"));
36  
37          Cache memoryOnlyCache = cm.getCache("memoryOnly");
38          Cache overflowToDiskCache = cm.getCache("overflowToDisk");
39  
40          for (int i = 0; i < 100; i++) {
41              memoryOnlyCache.put(new Element(i, "" + i));
42          }
43  
44          assertEquals(64, memoryOnlyCache.getSize());
45  
46          for (int i = 0; i < 100; i++) {
47              overflowToDiskCache.put(new Element(i, "" + i));
48          }
49  
50          assertEquals(64, memoryOnlyCache.getSize() + overflowToDiskCache.getSize());
51  
52  
53          cm.shutdown();
54      }
55  
56  }