1 |
| package org.jboss.cache.passivation; |
2 |
| |
3 |
| import junit.framework.Test; |
4 |
| import junit.framework.TestSuite; |
5 |
| import org.jboss.cache.config.CacheLoaderConfig; |
6 |
| import org.jboss.cache.factories.XmlConfigurationParser; |
7 |
| import org.jboss.cache.xml.XmlHelper; |
8 |
| import org.w3c.dom.Element; |
9 |
| |
10 |
| import java.io.File; |
11 |
| import java.io.FileFilter; |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| public class PassivationToBdbjeCacheLoaderTest extends PassivationTestsBase |
21 |
| { |
22 |
| |
23 |
| private String tmp_location = System.getProperty("java.io.tmpdir", "c:\\tmp"); |
24 |
| private File dir = new File(tmp_location); |
25 |
| |
26 |
45
| public PassivationToBdbjeCacheLoaderTest()
|
27 |
| { |
28 |
0
| if (!dir.exists()) dir.mkdirs();
|
29 |
| } |
30 |
| |
31 |
45
| protected void configureCache() throws Exception
|
32 |
| { |
33 |
| |
34 |
| class MyFilter implements FileFilter |
35 |
| { |
36 |
3195
| public boolean accept(File file)
|
37 |
| { |
38 |
3195
| return file.getName().endsWith(".jdb");
|
39 |
| } |
40 |
| } |
41 |
| |
42 |
45
| File[] files = dir.listFiles(new MyFilter());
|
43 |
45
| if (files != null)
|
44 |
| { |
45 |
45
| for (int i = 0; i < files.length; i += 1)
|
46 |
| { |
47 |
45
| File file = files[i];
|
48 |
45
| if (file.isFile())
|
49 |
| { |
50 |
45
| if (!file.delete())
|
51 |
| { |
52 |
0
| System.err.println("Unable to delete: " + file);
|
53 |
| } |
54 |
| } |
55 |
| } |
56 |
| } |
57 |
| |
58 |
45
| cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(tmp_location));
|
59 |
| } |
60 |
| |
61 |
| |
62 |
45
| protected CacheLoaderConfig getCacheLoaderConfig(String loc) throws Exception
|
63 |
| { |
64 |
45
| String xml = " <config>\n" +
|
65 |
| " \n" + |
66 |
| " <passivation>true</passivation>\n" + |
67 |
| " <preload></preload>\n" + |
68 |
| "\n" + |
69 |
| " <cacheloader>\n" + |
70 |
| " <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>\n" + |
71 |
| " <properties>\n" + |
72 |
| " </properties>\n" + |
73 |
| " <async>false</async>\n" + |
74 |
| " <fetchPersistentState>false</fetchPersistentState>\n" + |
75 |
| " <ignoreModifications>false</ignoreModifications>\n" + |
76 |
| " </cacheloader>\n" + |
77 |
| " \n" + |
78 |
| " </config>"; |
79 |
45
| Element element = XmlHelper.stringToElement(xml);
|
80 |
45
| return XmlConfigurationParser.parseCacheLoaderConfig(element);
|
81 |
| } |
82 |
| |
83 |
1
| public static Test suite()
|
84 |
| { |
85 |
1
| return new TestSuite(PassivationToBdbjeCacheLoaderTest.class);
|
86 |
| } |
87 |
| |
88 |
| |
89 |
0
| public static void main(String[] args)
|
90 |
| { |
91 |
0
| junit.textui.TestRunner.run(suite());
|
92 |
| } |
93 |
| |
94 |
| |
95 |
| } |