String xml = "<region name=\"/test/\" policyClass=\"org.jboss.cache.eviction.LFUPolicy\">" +
"<attribute name=\"minNodes\">10</attribute>" +
"<attribute name=\"maxNodes\">20</attribute>" +
"</region>";
Element element = XmlHelper.stringToElement(xml);
RegionManager regionManager = new RegionManager();
regionManager.setUsingEvictions(true);
EvictionRegionConfig erc = XmlConfigurationParser.parseEvictionRegionConfig(element, null, EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
Region region = regionManager.getRegion(erc.getRegionFqn(), true);
region.setEvictionPolicy(erc.getEvictionPolicyConfig());
assertTrue(region.getEvictionPolicy() instanceof LFUPolicy);
assertTrue(region.getEvictionPolicyConfig() instanceof LFUConfiguration);
LFUConfiguration config = (LFUConfiguration) region.getEvictionPolicyConfig();
assertEquals(20, config.getMaxNodes());
assertEquals(10, config.getMinNodes());
assertEquals(Fqn.fromString("/test/"), region.getFqn());
// test the 1.2.x style configuration
xml = "<region name=\"abc\">" +
"<attribute name=\"minNodes\">10</attribute>" +
"<attribute name=\"maxNodes\">20</attribute>" +
"</region>";
element = XmlHelper.stringToElement(xml);
erc = XmlConfigurationParser.parseEvictionRegionConfig(element, "org.jboss.cache.eviction.LFUPolicy", EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
regionManager = new RegionManager();
regionManager.setUsingEvictions(true);
region = regionManager.getRegion(erc.getRegionFqn(), true);
region.setEvictionPolicy(erc.getEvictionPolicyConfig());
assertTrue(region.getEvictionPolicy() instanceof LFUPolicy);
assertTrue(region.getEvictionPolicyConfig() instanceof LFUConfiguration);
config = (LFUConfiguration) region.getEvictionPolicyConfig();