1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.optimistic; |
8 |
| |
9 |
| import junit.framework.Assert; |
10 |
| import org.jboss.cache.CacheImpl; |
11 |
| import org.jboss.cache.config.CacheLoaderConfig; |
12 |
| import org.jboss.cache.factories.XmlConfigurationParser; |
13 |
| import org.jboss.cache.loader.CacheLoader; |
14 |
| import org.jboss.cache.transaction.DummyTransactionManager; |
15 |
| import org.jboss.cache.xml.XmlHelper; |
16 |
| import org.w3c.dom.Element; |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| public class OptimisticWithPassivationTest extends AbstractOptimisticTestCase |
24 |
| { |
25 |
| |
26 |
1
| public OptimisticWithPassivationTest(String s)
|
27 |
| { |
28 |
1
| super(s);
|
29 |
| } |
30 |
| |
31 |
1
| protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
|
32 |
| { |
33 |
1
| String xml = " <config>\n" +
|
34 |
| " \n" + |
35 |
| " <passivation>true</passivation>\n" + |
36 |
| " <preload></preload>\n" + |
37 |
| "\n" + |
38 |
| " <cacheloader>\n" + |
39 |
| " <class>org.jboss.cache.loader.DummyInMemoryCacheLoader</class>\n" + |
40 |
| " <async>false</async>\n" + |
41 |
| " <fetchPersistentState>false</fetchPersistentState>\n" + |
42 |
| " <ignoreModifications>false</ignoreModifications>\n" + |
43 |
| " </cacheloader>\n" + |
44 |
| " \n" + |
45 |
| " </config>"; |
46 |
1
| Element element = XmlHelper.stringToElement(xml);
|
47 |
1
| return XmlConfigurationParser.parseCacheLoaderConfig(element);
|
48 |
| } |
49 |
| |
50 |
1
| private CacheImpl createLocalCache() throws Exception
|
51 |
| { |
52 |
1
| CacheImpl cache = createCacheUnstarted(false);
|
53 |
1
| cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig());
|
54 |
| |
55 |
1
| cache.create();
|
56 |
1
| cache.start();
|
57 |
1
| return cache;
|
58 |
| } |
59 |
| |
60 |
1
| public void testPassivationLocal() throws Exception
|
61 |
| { |
62 |
1
| CacheImpl cache = createLocalCache();
|
63 |
1
| CacheLoader loader = cache.getCacheLoader();
|
64 |
| |
65 |
| |
66 |
1
| cache.remove(fqn);
|
67 |
1
| loader.remove(fqn);
|
68 |
| |
69 |
1
| Assert.assertNull(loader.get(fqn));
|
70 |
| |
71 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
72 |
| |
73 |
| |
74 |
1
| mgr.begin();
|
75 |
1
| cache.put(fqn, key, value);
|
76 |
1
| mgr.commit();
|
77 |
| |
78 |
| |
79 |
1
| Assert.assertEquals(value, cache.get(fqn, key));
|
80 |
1
| Assert.assertNull(loader.get(fqn));
|
81 |
| |
82 |
| |
83 |
1
| mgr.begin();
|
84 |
1
| cache.evict(fqn);
|
85 |
1
| mgr.commit();
|
86 |
| |
87 |
1
| mgr.begin();
|
88 |
| |
89 |
| |
90 |
| |
91 |
1
| Assert.assertEquals(value, loader.get(fqn).get(key));
|
92 |
| |
93 |
| |
94 |
1
| Assert.assertEquals(value, cache.get(fqn, key));
|
95 |
| |
96 |
| |
97 |
1
| Assert.assertNull(loader.get(fqn));
|
98 |
1
| mgr.commit();
|
99 |
| |
100 |
| |
101 |
1
| mgr.begin();
|
102 |
1
| cache.remove(fqn);
|
103 |
1
| loader.remove(fqn);
|
104 |
1
| mgr.commit();
|
105 |
| |
106 |
| } |
107 |
| } |