1 7 package org.jboss.cache.buddyreplication; 8 9 import junit.framework.TestCase; 10 import org.jboss.cache.CacheImpl; 11 import org.jboss.cache.config.BuddyReplicationConfig; 12 import org.jboss.cache.config.Configuration; 13 import org.jboss.cache.factories.XmlConfigurationParser; 14 import org.jboss.cache.interceptors.DataGravitatorInterceptor; 15 import org.jboss.cache.interceptors.Interceptor; 16 import org.jboss.cache.xml.XmlHelper; 17 import org.w3c.dom.Element ; 18 19 24 public class BuddyReplicationConfigTest extends TestCase 25 { 26 public void testNullConfig() throws Exception 27 { 28 CacheImpl cache = new CacheImpl(); 29 cache.getConfiguration().setBuddyReplicationConfig(null); 30 assertNull(cache.getBuddyManager()); 31 } 32 33 public void testDisabledConfig() throws Exception 34 { 35 String xmlConfig = "<config><buddyReplicationEnabled>false</buddyReplicationEnabled></config>"; 36 Element element = XmlHelper.stringToElement(xmlConfig); 37 BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element); 38 CacheImpl cache = new CacheImpl(); 39 cache.getConfiguration().setBuddyReplicationConfig(config); 40 assertNull(cache.getBuddyManager()); 41 } 42 43 public void testBasicConfig() throws Exception 44 { 45 String xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>"; 46 Element element = XmlHelper.stringToElement(xmlConfig); 47 BuddyReplicationConfig config = XmlConfigurationParser.parseBuddyReplicationConfig(element); 48 CacheImpl cache = new CacheImpl(); 49 cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC); 50 cache.getConfiguration().setBuddyReplicationConfig(config); 51 cache.create(); 52 assertNotNull(cache.getBuddyManager()); 53 BuddyManager mgr = cache.getBuddyManager(); 54 assertTrue(mgr.isEnabled()); 55 assertNull(mgr.getBuddyPoolName()); 56 assertEquals(NextMemberBuddyLocator.class, mgr.buddyLocator.getClass()); 57 NextMemberBuddyLocatorConfig blc = (NextMemberBuddyLocatorConfig) mgr.buddyLocator.getConfig(); 58 assertEquals(1, blc.getNumBuddies()); 59 assertTrue(blc.isIgnoreColocatedBuddies()); 60 } 61 62 public void testXmlConfig() throws Exception 63 { 64 CacheImpl cache = new CacheImpl(); 65 cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/buddyreplication-service.xml")); 66 cache.create(); 67 BuddyManager bm = cache.getBuddyManager(); 68 assertNotNull(bm); 69 assertTrue(bm.isEnabled()); 70 assertTrue(bm.buddyLocator instanceof NextMemberBuddyLocator); 71 NextMemberBuddyLocator bl = (NextMemberBuddyLocator) bm.buddyLocator; 72 NextMemberBuddyLocatorConfig blc = (NextMemberBuddyLocatorConfig) bl.getConfig(); 73 assertTrue(blc.isIgnoreColocatedBuddies()); 74 assertEquals(1, blc.getNumBuddies()); 75 assertEquals("myBuddyPoolReplicationGroup", bm.getConfig().getBuddyPoolName()); 76 assertEquals(2000, bm.getConfig().getBuddyCommunicationTimeout()); 77 78 boolean hasDG = false; 80 for (Interceptor interceptor : cache.getInterceptors()) 81 { 82 hasDG = hasDG || (interceptor instanceof DataGravitatorInterceptor); 83 } 84 85 System.out.println(cache.getInterceptorChain()); 86 87 assertTrue("Should have a data gravitator!!", hasDG); 88 } 89 } 90 | Popular Tags |