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 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 public PassivationToBdbjeCacheLoaderTest() 27 { 28 if (!dir.exists()) dir.mkdirs(); 29 } 30 31 protected void configureCache() throws Exception { 32 33 class MyFilter implements FileFilter { 34 public boolean accept(File file) { 35 return file.getName().endsWith(".jdb"); 36 } 37 } 38 39 File [] files=dir.listFiles(new MyFilter()); 40 if (files != null) { 41 for (int i = 0; i < files.length; i += 1) { 42 File 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 loc) throws Exception 56 { 57 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 Element 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 [] args) 82 { 83 junit.textui.TestRunner.run(suite()); 84 } 85 86 87 } 88 | Popular Tags |