1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache; |
8 |
| |
9 |
| import junit.framework.TestCase; |
10 |
| import org.jboss.cache.config.Configuration; |
11 |
| import org.jboss.cache.factories.XmlConfigurationParser; |
12 |
| import org.jboss.cache.lock.IsolationLevel; |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| public class CacheFactoryTest extends TestCase |
18 |
| { |
19 |
| Configuration expected; |
20 |
| String configFile = "META-INF/replSync-service.xml"; |
21 |
| private CacheImpl cache; |
22 |
| |
23 |
5
| protected void setUp()
|
24 |
| { |
25 |
5
| XmlConfigurationParser parser = new XmlConfigurationParser();
|
26 |
5
| expected = parser.parseFile(configFile);
|
27 |
| } |
28 |
| |
29 |
5
| protected void tearDown()
|
30 |
| { |
31 |
5
| if (cache != null)
|
32 |
| { |
33 |
5
| cache.stop();
|
34 |
| } |
35 |
| } |
36 |
| |
37 |
1
| public void testFromConfigFileStarted()
|
38 |
| { |
39 |
1
| cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFile);
|
40 |
| |
41 |
| |
42 |
| |
43 |
1
| assertTrue("Should have started", cache.isStarted());
|
44 |
1
| doSimpleConfTests(cache.getConfiguration());
|
45 |
| } |
46 |
| |
47 |
1
| public void testFromConfigFileUnstarted()
|
48 |
| { |
49 |
1
| cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFile, false);
|
50 |
| |
51 |
| |
52 |
| |
53 |
1
| assertFalse("Should not have started", cache.isStarted());
|
54 |
| |
55 |
1
| doSimpleConfTests(cache.getConfiguration());
|
56 |
| } |
57 |
| |
58 |
1
| public void testFromConfigObjStarted()
|
59 |
| { |
60 |
1
| cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected);
|
61 |
| |
62 |
1
| assertTrue("Should have started", cache.isStarted());
|
63 |
| |
64 |
1
| doSimpleConfTests(cache.getConfiguration());
|
65 |
| } |
66 |
| |
67 |
1
| public void testFromConfigObjUnstarted()
|
68 |
| { |
69 |
1
| cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected, false);
|
70 |
| |
71 |
1
| assertFalse("Should not have started", cache.isStarted());
|
72 |
| |
73 |
1
| doSimpleConfTests(cache.getConfiguration());
|
74 |
| } |
75 |
| |
76 |
4
| private void doSimpleConfTests(Configuration tc)
|
77 |
| { |
78 |
4
| assertEquals(Configuration.CacheMode.REPL_SYNC, tc.getCacheMode());
|
79 |
4
| assertEquals(10000, tc.getLockAcquisitionTimeout());
|
80 |
4
| assertEquals(IsolationLevel.REPEATABLE_READ, tc.getIsolationLevel());
|
81 |
4
| assertEquals(true, tc.isUseRegionBasedMarshalling());
|
82 |
| |
83 |
| |
84 |
| } |
85 |
| |
86 |
1
| public void testLifecycle() throws Exception
|
87 |
| { |
88 |
1
| cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected, false);
|
89 |
1
| assertFalse(cache.isStarted());
|
90 |
1
| cache.start();
|
91 |
1
| assertTrue(cache.isStarted());
|
92 |
1
| cache.stop();
|
93 |
1
| assertFalse(cache.isStarted());
|
94 |
| } |
95 |
| |
96 |
| } |