KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > buddyreplication > BuddyReplicationConfigTest


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

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 JavaDoc;
18
19 /**
20  * Tests basic configuration options by passing stuff into the CacheImpl.
21  *
22  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
23  */

24 public class BuddyReplicationConfigTest extends TestCase
25 {
26    public void testNullConfig() throws Exception JavaDoc
27    {
28       CacheImpl cache = new CacheImpl();
29       cache.getConfiguration().setBuddyReplicationConfig(null);
30       assertNull(cache.getBuddyManager());
31    }
32
33    public void testDisabledConfig() throws Exception JavaDoc
34    {
35       String JavaDoc xmlConfig = "<config><buddyReplicationEnabled>false</buddyReplicationEnabled></config>";
36       Element JavaDoc 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 JavaDoc
44    {
45       String JavaDoc xmlConfig = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled></config>";
46       Element JavaDoc 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 JavaDoc
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       // test Data Gravitator
79
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