1 7 package org.jboss.cache.eviction; 8 9 import junit.framework.TestCase; 10 import org.jboss.cache.CacheImpl; 11 import org.jboss.cache.Fqn; 12 import org.jboss.cache.Region; 13 import org.jboss.cache.RegionManager; 14 import org.jboss.cache.config.Configuration; 15 import org.jboss.cache.factories.XmlConfigurationParser; 16 import org.jboss.cache.lock.IsolationLevel; 17 18 24 public class EvictionConfigurationTest extends TestCase 25 { 26 CacheImpl cache; 27 RegionManager regionManager; 28 29 public void setUp() throws Exception 30 { 31 super.setUp(); 32 } 33 34 public void tearDown() throws Exception 35 { 36 super.tearDown(); 37 } 38 39 public void testPolicyPerRegion() throws Exception 40 { 41 this.setupCache("META-INF/policyPerRegion-eviction-service.xml"); 42 assertEquals(5, cache.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds()); 43 44 Region region = regionManager.getRegion("/org/jboss/data", true); 45 EvictionPolicy policy = region.getEvictionPolicy(); 46 EvictionPolicyConfig configuration = region.getEvictionPolicyConfig(); 47 assertEquals(Fqn.fromString("/org/jboss/data"), region.getFqn()); 48 assertTrue(policy instanceof LFUPolicy); 49 assertTrue(configuration instanceof LFUConfiguration); 50 assertEquals(5000, ((LFUConfiguration) configuration).getMaxNodes()); 51 assertEquals(1000, ((LFUConfiguration) configuration).getMinNodes()); 52 53 region = regionManager.getRegion("/org/jboss/test/data", true); 54 policy = region.getEvictionPolicy(); 55 configuration = region.getEvictionPolicyConfig(); 56 assertEquals(Fqn.fromString("/org/jboss/test/data"), region.getFqn()); 57 assertTrue(policy instanceof FIFOPolicy); 58 assertTrue(configuration instanceof FIFOConfiguration); 59 assertEquals(5, ((FIFOConfiguration) configuration).getMaxNodes()); 60 61 region = regionManager.getRegion("/test", true); 62 policy = region.getEvictionPolicy(); 63 configuration = region.getEvictionPolicyConfig(); 64 assertEquals(Fqn.fromString("/test"), region.getFqn()); 65 assertTrue(policy instanceof MRUPolicy); 66 assertTrue(configuration instanceof MRUConfiguration); 67 assertEquals(10000, ((MRUConfiguration) configuration).getMaxNodes()); 68 69 region = regionManager.getRegion("/maxAgeTest", true); 70 policy = region.getEvictionPolicy(); 71 configuration = region.getEvictionPolicyConfig(); 72 assertEquals(Fqn.fromString("/maxAgeTest"), region.getFqn()); 73 assertTrue(policy instanceof LRUPolicy); 74 assertTrue(configuration instanceof LRUConfiguration); 75 assertEquals(10000, ((LRUConfiguration) configuration).getMaxNodes()); 76 assertEquals(8, ((LRUConfiguration) configuration).getTimeToLiveSeconds()); 77 assertEquals(10, ((LRUConfiguration) configuration).getMaxAgeSeconds()); 78 79 region = regionManager.getRegion("/a/b/c", false); 81 policy = region.getEvictionPolicy(); 82 configuration = region.getEvictionPolicyConfig(); 83 assertEquals(Fqn.ROOT, region.getFqn()); 84 assertTrue(policy instanceof LRUPolicy); 85 assertTrue(configuration instanceof LRUConfiguration); 86 assertEquals(5000, ((LRUConfiguration) configuration).getMaxNodes()); 87 assertEquals(1000, ((LRUConfiguration) configuration).getTimeToLiveSeconds()); 88 assertEquals(0, ((LRUConfiguration) configuration).getMaxAgeSeconds()); 89 90 cache.stop(); 91 } 92 93 public void testMixedPolicies() throws Exception 94 { 95 this.setupCache("META-INF/mixedPolicy-eviction-service.xml"); 96 assertEquals(5, cache.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds()); 97 98 Region region = regionManager.getRegion("/org/jboss/data", true); 99 EvictionPolicy policy = region.getEvictionPolicy(); 100 EvictionPolicyConfig configuration = region.getEvictionPolicyConfig(); 101 assertEquals(Fqn.fromString("/org/jboss/data/"), region.getFqn()); 102 assertTrue(policy instanceof FIFOPolicy); 103 assertTrue(configuration instanceof FIFOConfiguration); 104 assertEquals(5000, ((FIFOConfiguration) configuration).getMaxNodes()); 105 106 region = regionManager.getRegion("/test", true); 107 policy = region.getEvictionPolicy(); 108 configuration = region.getEvictionPolicyConfig(); 109 assertEquals(Fqn.fromString("/test/"), region.getFqn()); 110 assertTrue(policy instanceof MRUPolicy); 111 assertTrue(configuration instanceof MRUConfiguration); 112 assertEquals(10000, ((MRUConfiguration) configuration).getMaxNodes()); 113 114 region = regionManager.getRegion("/a/b/c", false); 116 policy = region.getEvictionPolicy(); 117 configuration = region.getEvictionPolicyConfig(); 118 assertEquals(Fqn.ROOT, region.getFqn()); 119 assertTrue(policy instanceof LRUPolicy); 120 assertTrue(configuration instanceof LRUConfiguration); 121 assertEquals(5000, ((LRUConfiguration) configuration).getMaxNodes()); 122 assertEquals(1000, ((LRUConfiguration) configuration).getTimeToLiveSeconds()); 123 assertEquals(0, ((LRUConfiguration) configuration).getMaxAgeSeconds()); 124 125 region = regionManager.getRegion("/maxAgeTest", false); 126 policy = region.getEvictionPolicy(); 127 configuration = region.getEvictionPolicyConfig(); 128 assertEquals(Fqn.fromString("/maxAgeTest/"), region.getFqn()); 129 assertTrue(policy instanceof LRUPolicy); 130 assertTrue(configuration instanceof LRUConfiguration); 131 assertEquals(10000, ((LRUConfiguration) configuration).getMaxNodes()); 132 assertEquals(8, ((LRUConfiguration) configuration).getTimeToLiveSeconds()); 133 assertEquals(10, ((LRUConfiguration) configuration).getMaxAgeSeconds()); 134 135 cache.stop(); 136 } 137 138 public void testLegacyPolicyConfiguration() throws Exception 139 { 140 this.setupCache("META-INF/local-lru-eviction-service.xml"); 141 assertEquals(5, cache.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds()); 142 143 Region region = regionManager.getRegion("/org/jboss/data", false); 144 EvictionPolicy policy = region.getEvictionPolicy(); 145 EvictionPolicyConfig configuration = region.getEvictionPolicyConfig(); 146 assertEquals(Fqn.fromString("/org/jboss/data/"), region.getFqn()); 147 assertTrue(policy instanceof LRUPolicy); 148 assertTrue(configuration instanceof LRUConfiguration); 149 assertEquals(5000, ((LRUConfiguration) configuration).getMaxNodes()); 150 assertEquals(1000, ((LRUConfiguration) configuration).getTimeToLiveSeconds()); 151 152 region = regionManager.getRegion("/org/jboss/test/data", false); 153 policy = region.getEvictionPolicy(); 154 configuration = region.getEvictionPolicyConfig(); 155 assertEquals(Fqn.fromString("/org/jboss/test/data/"), region.getFqn()); 156 assertTrue(policy instanceof LRUPolicy); 157 assertTrue(configuration instanceof LRUConfiguration); 158 assertEquals(5, ((LRUConfiguration) configuration).getMaxNodes()); 159 assertEquals(4, ((LRUConfiguration) configuration).getTimeToLiveSeconds()); 160 161 region = regionManager.getRegion("/test", true); 162 policy = region.getEvictionPolicy(); 163 configuration = region.getEvictionPolicyConfig(); 164 assertEquals(Fqn.fromString("/test/"), region.getFqn()); 165 assertTrue(policy instanceof LRUPolicy); 166 assertTrue(configuration instanceof LRUConfiguration); 167 assertEquals(10000, ((LRUConfiguration) configuration).getMaxNodes()); 168 assertEquals(4, ((LRUConfiguration) configuration).getTimeToLiveSeconds()); 169 170 region = regionManager.getRegion("/maxAgeTest", true); 171 policy = region.getEvictionPolicy(); 172 configuration = region.getEvictionPolicyConfig(); 173 assertEquals(Fqn.fromString("/maxAgeTest/"), region.getFqn()); 174 assertTrue(policy instanceof LRUPolicy); 175 assertTrue(configuration instanceof LRUConfiguration); 176 assertEquals(10000, ((LRUConfiguration) configuration).getMaxNodes()); 177 assertEquals(8, ((LRUConfiguration) configuration).getTimeToLiveSeconds()); 178 assertEquals(10, ((LRUConfiguration) configuration).getMaxAgeSeconds()); 179 180 region = regionManager.getRegion("/a/b/c", false); 182 policy = region.getEvictionPolicy(); 183 configuration = region.getEvictionPolicyConfig(); 184 assertEquals(Fqn.ROOT, region.getFqn()); 185 assertTrue(policy instanceof LRUPolicy); 186 assertTrue(configuration instanceof LRUConfiguration); 187 assertEquals(5000, ((LRUConfiguration) configuration).getMaxNodes()); 188 assertEquals(1000, ((LRUConfiguration) configuration).getTimeToLiveSeconds()); 189 assertEquals(0, ((LRUConfiguration) configuration).getMaxAgeSeconds()); 190 191 cache.stop(); 192 193 } 194 195 public void testTwoCacheInstanceConfiguration() throws Exception 196 { 197 this.setupCache("META-INF/local-lru-eviction-service.xml"); 198 CacheImpl cache1 = cache; 199 this.setupCache("META-INF/local-lru-eviction-service.xml"); 200 } 201 202 public void testNoEviction() throws Exception 203 { 204 this.setupCache("META-INF/tree-service.xml"); 205 assertEquals(0, regionManager.getAllRegions().size()); 206 } 207 208 private void setupCache(String configurationName) throws Exception 209 { 210 cache = new CacheImpl(); 211 XmlConfigurationParser parser = new XmlConfigurationParser(); 212 Configuration c = parser.parseFile(configurationName); 213 c.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 214 c.setIsolationLevel(IsolationLevel.SERIALIZABLE); 215 cache.setConfiguration(c); 216 cache.start(); 217 regionManager = cache.getRegionManager(); 218 } 219 } 220 | Popular Tags |