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;
18  
19  import junit.framework.Assert;
20  
21  import org.junit.After;
22  import org.junit.Before;
23  import org.junit.Test;
24  
25  public class InfiniteCapacityCacheTest {
26  
27      private static final int INFINITY = 1000;
28  
29      /***
30       * the CacheManager instance
31       */
32      protected CacheManager manager;
33  
34      /***
35       * setup test
36       */
37      @Before
38      public void setUp() throws Exception {
39          manager = new CacheManager(AbstractCacheTest.TEST_CONFIG_DIR + "ehcache-infinite-capacity.xml");
40      }
41  
42      /***
43       * teardown
44       */
45      @After
46      public void tearDown() throws Exception {
47          if (manager != null) {
48              manager.shutdown();
49          }
50      }
51  
52      @Test
53      public void testDefaultStoreCapacities() {
54          Cache defined = manager.getCache("defined");
55          manager.addCache("defaults");
56          Cache defaults = manager.getCache("defaults");
57  
58          Assert.assertEquals(0, defined.getCacheConfiguration().getMaxElementsInMemory());
59          Assert.assertEquals(0, defaults.getCacheConfiguration().getMaxElementsInMemory());
60  
61          for (int i = 0; i < INFINITY; i++) {
62              defined.put(new Element(Integer.valueOf(i), new Object()));
63              defaults.put(new Element(Integer.valueOf(i), new Object()));
64          }
65  
66          Assert.assertEquals(INFINITY, defined.getSize());
67          Assert.assertEquals(INFINITY, defined.getMemoryStoreSize());
68          Assert.assertEquals(0, defined.getDiskStoreSize());
69  
70          Assert.assertEquals(INFINITY, defaults.getSize());
71          Assert.assertEquals(INFINITY, defaults.getMemoryStoreSize());
72          Assert.assertEquals(0, defaults.getDiskStoreSize());
73      }
74  }