KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > passivation > PassivationToBdbjeCacheLoaderTest


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 JavaDoc;
10
11 import java.io.File JavaDoc;
12 import java.io.FileFilter JavaDoc;
13
14 /**
15  * Runs the same tests as {@link PassivationToFileCacheLoaderTest}, but with
16  * Berkeley DB instead of a file-based CacheLoader
17  *
18  * @author <a HREF="mailto:{hmesha@novell.com}">{Hany Mesha}</a>
19  * @version $Id: PassivationToBdbjeCacheLoaderTest.java,v 1.12 2006/10/25 04:50:20 bstansberry Exp $
20  */

21 public class PassivationToBdbjeCacheLoaderTest extends PassivationTestsBase {
22
23     private String JavaDoc tmp_location = System.getProperty("java.io.tmpdir", "c:\\tmp");
24     private File JavaDoc dir = new File JavaDoc(tmp_location);
25
26     public PassivationToBdbjeCacheLoaderTest()
27     {
28         if (!dir.exists()) dir.mkdirs();
29     }
30
31    protected void configureCache() throws Exception JavaDoc {
32
33       class MyFilter implements FileFilter JavaDoc {
34          public boolean accept(File JavaDoc file) {
35             return file.getName().endsWith(".jdb");
36          }
37       }
38
39       File JavaDoc[] files=dir.listFiles(new MyFilter());
40       if (files != null) {
41          for (int i = 0; i < files.length; i += 1) {
42             File JavaDoc file = files[i];
43             if (file.isFile()) {
44                if (!file.delete()) {
45                   System.err.println("Unable to delete: " + file);
46                }
47             }
48          }
49       }
50
51        cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(tmp_location));
52    }
53
54
55     protected CacheLoaderConfig getCacheLoaderConfig(String JavaDoc loc) throws Exception JavaDoc
56     {
57         String JavaDoc 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         Element JavaDoc element = XmlHelper.stringToElement(xml);
73         return XmlConfigurationParser.parseCacheLoaderConfig(element);
74     }
75
76    public static Test suite() {
77       return new TestSuite(PassivationToBdbjeCacheLoaderTest.class);
78    }
79
80
81     public static void main(String JavaDoc[] args)
82     {
83         junit.textui.TestRunner.run(suite());
84     }
85
86
87 }
88
Popular Tags