1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
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.config.Configuration.CacheMode; |
32 |
| import org.jboss.cache.factories.UnitTestCacheFactory; |
33 |
| import org.jboss.cache.pojo.PojoCache; |
34 |
| import org.jboss.cache.pojo.PojoCacheFactory; |
35 |
| import org.jboss.cache.pojo.test.Person; |
36 |
| import org.jboss.cache.pojo.test.Student; |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| public class ReplicatedTest extends TestCase |
44 |
| { |
45 |
| Log log = LogFactory.getLog(ReplicatedTest.class); |
46 |
| PojoCache cache, cache1; |
47 |
| |
48 |
| |
49 |
2
| public ReplicatedTest(String name)
|
50 |
| { |
51 |
2
| super(name);
|
52 |
| } |
53 |
| |
54 |
2
| protected void setUp() throws Exception
|
55 |
| { |
56 |
2
| super.setUp();
|
57 |
2
| log.info("setUp() ....");
|
58 |
| } |
59 |
| |
60 |
2
| protected void tearDown() throws Exception
|
61 |
| { |
62 |
2
| super.tearDown();
|
63 |
2
| cache.stop();
|
64 |
2
| cache1.stop();
|
65 |
| } |
66 |
| |
67 |
| |
68 |
| |
69 |
2
| private Person createPerson(String id, String name, int age)
|
70 |
| { |
71 |
2
| Person p = new Person();
|
72 |
2
| p.setName(name);
|
73 |
2
| p.setAge(age);
|
74 |
2
| cache.attach(id, p);
|
75 |
2
| return p;
|
76 |
| } |
77 |
| |
78 |
0
| private Student createStudent(String id, String name, int age, String grade)
|
79 |
| { |
80 |
0
| Student p = new Student();
|
81 |
0
| p.setName(name);
|
82 |
0
| p.setAge(age);
|
83 |
0
| p.setYear(grade);
|
84 |
0
| cache.attach(id, p);
|
85 |
0
| return p;
|
86 |
| } |
87 |
| |
88 |
2
| public void testSimple() throws Exception
|
89 |
| { |
90 |
2
| boolean toStart = true;
|
91 |
2
| cache = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
|
92 |
2
| Person ben = createPerson("/person/test1", "Ben Wang", 40);
|
93 |
| |
94 |
2
| System.out.println("\n*** I ***");
|
95 |
2
| System.out.println(((CacheImpl) cache.getCache()).printDetails());
|
96 |
2
| cache1 = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
|
97 |
2
| cache1.start();
|
98 |
| |
99 |
2
| System.out.println("\n*** II ***");
|
100 |
2
| System.out.println(((CacheImpl) cache1.getCache()).printDetails());
|
101 |
| |
102 |
2
| Person p = (Person) cache1.find("/person/test1");
|
103 |
| |
104 |
2
| log.info("testSimple() ....");
|
105 |
2
| assertEquals("Ben Wang", ben.getName());
|
106 |
2
| assertEquals("Ben Wang", ((Person) cache1.find("/person/test1")).getName());
|
107 |
2
| cache.detach("/person/test1");
|
108 |
| } |
109 |
| |
110 |
2
| public static Test suite() throws Exception
|
111 |
| { |
112 |
2
| return new TestSuite(ReplicatedTest.class);
|
113 |
| } |
114 |
| |
115 |
| |
116 |
0
| public static void main(String[] args) throws Exception
|
117 |
| { |
118 |
0
| junit.textui.TestRunner.run(suite());
|
119 |
| } |
120 |
| |
121 |
| } |