1 7 package org.jboss.cache.loader; 8 9 import junit.framework.Test; 10 import junit.framework.TestSuite; 11 import org.jboss.cache.Fqn; 12 13 import java.util.Properties ; 14 15 28 public class JDBCCacheLoaderTest 29 extends CacheLoaderTestsBase 30 { 31 protected void configureCache() throws Exception 32 { 33 Properties prop = new Properties (); 34 try{ 35 prop.load(this.getClass().getClassLoader().getResourceAsStream("cache-jdbc.properties")); 36 }catch(Exception e){ 37 System.out.println("Error loading jdbc properties "); 38 } 39 String props = "cache.jdbc.driver =" + prop.getProperty("cache.jdbc.driver") + "\n" + 40 "cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") +"\n" + 41 "cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" + 42 "cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" + 43 "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type"); 44 cache.getConfiguration().setCacheLoaderConfig( getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false) ); 45 } 46 47 public void testLargeObject() 48 { 49 try { 50 String key = "LargeObj"; 51 StringBuffer text = new StringBuffer ("LargeObject"); 53 while (text.toString().getBytes().length < (1024*100)) { 54 text.append(text); 55 } 56 String initialValue = text.toString(); 57 loader.remove(Fqn.fromString("/")); 59 60 Object retVal = loader.put(FQN, key, initialValue); 61 assertNull(retVal); 62 addDelay(); 63 assertEquals(initialValue, (String ) loader.get(FQN).get(key)); 65 String updatedValue = initialValue.concat(("UpdatedValue")); 67 retVal = loader.put(FQN, key, updatedValue); 68 assertEquals(initialValue, (String ) retVal); 69 assertEquals(updatedValue, (String ) loader.get(FQN).get(key)); 70 } catch(Exception e) { 71 fail(e.toString()); 72 } 73 } 74 75 76 public static Test suite() 77 { 78 return new TestSuite(JDBCCacheLoaderTest.class); 79 } 80 81 public static void main(String [] args) 82 { 83 junit.textui.TestRunner.run(suite()); 84 } 85 } 86 | Popular Tags |