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