KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > factories > CacheFactoryTest


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.factories;
8
9 import junit.framework.TestCase;
10 import org.jboss.cache.CacheImpl;
11 import org.jboss.cache.config.Configuration;
12 import org.jboss.cache.lock.IsolationLevel;
13
14 /**
15  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
16  */

17 public class CacheFactoryTest extends TestCase
18 {
19    Configuration expected;
20    String JavaDoc configFile = "META-INF/replSync-service.xml";
21    private CacheImpl cache;
22
23    protected void setUp()
24    {
25       XmlConfigurationParser parser = new XmlConfigurationParser();
26       expected = parser.parseFile(configFile);
27    }
28
29    protected void tearDown()
30    {
31       if (cache != null)
32       {
33          cache.stop();
34       }
35    }
36
37    public void testFromConfigFileStarted()
38    {
39       cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFile);
40       assertEquals(expected, cache.getConfiguration());
41
42       assertTrue("Should have started", cache.isStarted());
43       doSimpleConfTests(cache.getConfiguration());
44    }
45
46    public void testFromConfigFileUnstarted()
47    {
48       cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFile, false);
49       assertEquals(expected, cache.getConfiguration());
50
51       assertFalse("Should not have started", cache.isStarted());
52
53       doSimpleConfTests(cache.getConfiguration());
54    }
55
56    public void testFromConfigObjStarted()
57    {
58       cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected);
59
60       assertTrue("Should have started", cache.isStarted());
61
62       doSimpleConfTests(cache.getConfiguration());
63    }
64
65    public void testFromConfigObjUnstarted()
66    {
67       cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected, false);
68
69       assertFalse("Should not have started", cache.isStarted());
70
71       doSimpleConfTests(cache.getConfiguration());
72    }
73
74    private void doSimpleConfTests(Configuration tc)
75    {
76       assertEquals(Configuration.CacheMode.REPL_SYNC, tc.getCacheMode());
77       assertEquals(10000, tc.getLockAcquisitionTimeout());
78       assertEquals(IsolationLevel.REPEATABLE_READ, tc.getIsolationLevel());
79       assertEquals(true, tc.isUseRegionBasedMarshalling());
80       // test some of the XML content.
81
assertEquals("UDP(ip_mcast=true;ip_ttl=64;loopback=false;mcast_addr=228.1.2.3;mcast_port=48866;mcast_recv_buf_size=80000;mcast_send_buf_size=150000;ucast_recv_buf_size=80000;ucast_send_buf_size=150000):PING(down_thread=false;num_initial_members=3;timeout=2000;up_thread=false):MERGE2(max_interval=20000;min_interval=10000):FD_SOCK:VERIFY_SUSPECT(down_thread=false;timeout=1500;up_thread=false):pbcast.NAKACK(down_thread=false;gc_lag=50;max_xmit_size=8192;retransmit_timeout=600,1200,2400,4800;up_thread=false):UNICAST(down_thread=false;min_threshold=10;timeout=600,1200,2400;window_size=100):pbcast.STABLE(desired_avg_gossip=20000;down_thread=false;up_thread=false):FRAG(down_thread=false;frag_size=8192;up_thread=false):pbcast.GMS(join_retry_timeout=2000;join_timeout=5000;print_local_addr=true;shun=true):pbcast.STATE_TRANSFER(down_thread=true;up_thread=true)", tc.getClusterConfig());
82    }
83
84    public void testLifecycle() throws Exception JavaDoc
85    {
86       cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected, false);
87       assertFalse(cache.isStarted());
88       cache.start();
89       assertTrue(cache.isStarted());
90       cache.stop();
91       assertFalse(cache.isStarted());
92    }
93
94 }
95
Popular Tags