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(String loc) 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.FileCacheLoader</class>\n" + |
40 |
| " <properties>\n" + |
41 |
| " </properties>\n" + |
42 |
| " <async>false</async>\n" + |
43 |
| " <fetchPersistentState>false</fetchPersistentState>\n" + |
44 |
| " <ignoreModifications>false</ignoreModifications>\n" + |
45 |
| " </cacheloader>\n" + |
46 |
| " \n" + |
47 |
| " </config>"; |
48 |
1
| Element element = XmlHelper.stringToElement(xml);
|
49 |
1
| return XmlConfigurationParser.parseCacheLoaderConfig(element);
|
50 |
| } |
51 |
| |
52 |
1
| private CacheImpl createLocalCache() throws Exception
|
53 |
| { |
54 |
1
| CacheImpl cache = createCacheUnstarted(false);
|
55 |
1
| cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(getTempDir()));
|
56 |
| |
57 |
1
| cache.create();
|
58 |
1
| cache.start();
|
59 |
1
| return cache;
|
60 |
| } |
61 |
| |
62 |
1
| public void testPassivationLocal() throws Exception
|
63 |
| { |
64 |
1
| CacheImpl cache = createLocalCache();
|
65 |
1
| CacheLoader loader = cache.getCacheLoader();
|
66 |
| |
67 |
| |
68 |
1
| cache.remove(fqn);
|
69 |
1
| loader.remove(fqn);
|
70 |
| |
71 |
1
| Assert.assertNull(loader.get(fqn));
|
72 |
| |
73 |
1
| DummyTransactionManager mgr = DummyTransactionManager.getInstance();
|
74 |
| |
75 |
| |
76 |
1
| mgr.begin();
|
77 |
1
| cache.put(fqn, key, value);
|
78 |
1
| mgr.commit();
|
79 |
| |
80 |
| |
81 |
1
| Assert.assertEquals(value, cache.get(fqn, key));
|
82 |
1
| Assert.assertNull(loader.get(fqn));
|
83 |
| |
84 |
| |
85 |
1
| mgr.begin();
|
86 |
1
| cache.evict(fqn);
|
87 |
1
| mgr.commit();
|
88 |
| |
89 |
1
| mgr.begin();
|
90 |
| |
91 |
| |
92 |
| |
93 |
1
| Assert.assertEquals(value, loader.get(fqn).get(key));
|
94 |
| |
95 |
| |
96 |
1
| Assert.assertEquals(value, cache.get(fqn, key));
|
97 |
| |
98 |
| |
99 |
1
| Assert.assertNull(loader.get(fqn));
|
100 |
1
| mgr.commit();
|
101 |
| |
102 |
| |
103 |
1
| mgr.begin();
|
104 |
1
| cache.remove(fqn);
|
105 |
1
| loader.remove(fqn);
|
106 |
1
| mgr.commit();
|
107 |
| |
108 |
| } |
109 |
| } |