1 22 23 package org.jboss.cache.pojo.statetransfer; 24 25 import junit.framework.Test; 26 import junit.framework.TestCase; 27 import junit.framework.TestSuite; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.jboss.cache.CacheImpl; 31 import org.jboss.cache.pojo.PojoCache; 32 import org.jboss.cache.pojo.PojoCacheFactory; 33 import org.jboss.cache.pojo.test.Person; 34 import org.jboss.cache.pojo.test.Student; 35 36 41 public class ReplicatedTest extends TestCase 42 { 43 Log log = LogFactory.getLog(ReplicatedTest.class); 44 PojoCache cache, cache1; 45 46 47 public ReplicatedTest(String name) 48 { 49 super(name); 50 } 51 52 protected void setUp() throws Exception 53 { 54 super.setUp(); 55 log.info("setUp() ...."); 56 } 57 58 protected void tearDown() throws Exception 59 { 60 super.tearDown(); 61 cache.stop(); 62 cache1.stop(); 63 } 64 65 67 private Person createPerson(String id, String name, int age) 68 { 69 Person p = new Person(); 70 p.setName(name); 71 p.setAge(age); 72 cache.attach(id, p); 73 return p; 74 } 75 76 private Student createStudent(String id, String name, int age, String grade) 77 { 78 Student p = new Student(); 79 p.setName(name); 80 p.setAge(age); 81 p.setYear(grade); 82 cache.attach(id, p); 83 return p; 84 } 85 86 public void testSimple() throws Exception 87 { 88 String configFile = "META-INF/replSync-service.xml"; 89 boolean toStart = true; 90 cache = PojoCacheFactory.createCache(configFile, toStart); 91 Person ben = createPerson("/person/test1", "Ben Wang", 40); 92 93 System.out.println("\n*** I ***"); 94 System.out.println(((CacheImpl) cache.getCache()).printDetails()); 95 cache1 = PojoCacheFactory.createCache(configFile, toStart); 96 cache1.start(); 97 98 System.out.println("\n*** II ***"); 99 System.out.println(((CacheImpl) cache1.getCache()).printDetails()); 100 101 Person p = (Person) cache1.find("/person/test1"); 102 103 log.info("testSimple() ...."); 104 assertEquals("Ben Wang", ben.getName()); 105 assertEquals("Ben Wang", ((Person) cache1.find("/person/test1")).getName()); 106 cache.detach("/person/test1"); 107 } 108 109 public static Test suite() throws Exception 110 { 111 return new TestSuite(ReplicatedTest.class); 112 } 113 114 115 public static void main(String [] args) throws Exception 116 { 117 junit.textui.TestRunner.run(suite()); 118 } 119 120 } 121 | Popular Tags |