1 |
| package org.jboss.cache.pojo; |
2 |
| |
3 |
| import junit.framework.Test; |
4 |
| import junit.framework.TestCase; |
5 |
| import junit.framework.TestSuite; |
6 |
| import org.apache.commons.logging.Log; |
7 |
| import org.apache.commons.logging.LogFactory; |
8 |
| import org.jboss.cache.Fqn; |
9 |
| import org.jboss.cache.config.Configuration.CacheMode; |
10 |
| import org.jboss.cache.factories.UnitTestCacheFactory; |
11 |
| import org.jboss.cache.pojo.test.Person; |
12 |
| import org.jboss.cache.pojo.test.SpecialSerializedAddress; |
13 |
| |
14 |
| import javax.naming.Context; |
15 |
| import java.util.Properties; |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| public class NewReplicatedTest extends TestCase |
26 |
| { |
27 |
| Log log_ = LogFactory.getLog(NewReplicatedTest.class); |
28 |
| PojoCache cache_; |
29 |
| PojoCache cache1_; |
30 |
| |
31 |
12
| public NewReplicatedTest(String name)
|
32 |
| { |
33 |
12
| super(name);
|
34 |
| } |
35 |
| |
36 |
12
| protected void setUp() throws Exception
|
37 |
| { |
38 |
12
| super.setUp();
|
39 |
12
| Properties prop = new Properties();
|
40 |
12
| prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
|
41 |
12
| boolean toStart = false;
|
42 |
12
| cache_ = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
|
43 |
12
| cache1_ = PojoCacheFactory.createCache(UnitTestCacheFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
|
44 |
12
| cache_.start();
|
45 |
12
| cache1_.start();
|
46 |
| } |
47 |
| |
48 |
12
| protected void tearDown() throws Exception
|
49 |
| { |
50 |
12
| super.tearDown();
|
51 |
12
| cache_.stop();
|
52 |
12
| cache1_.stop();
|
53 |
| } |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
2
| public void testRemoteRemove() throws Exception
|
91 |
| { |
92 |
2
| log_.info("testRemoteRemove() ....");
|
93 |
2
| Person test = new Person();
|
94 |
2
| test.setName("Ben");
|
95 |
2
| test.setAge(10);
|
96 |
2
| cache_.attach("/a", test);
|
97 |
2
| Person result = (Person) cache_.find("/a");
|
98 |
2
| assertEquals(" ", test, result);
|
99 |
| |
100 |
2
| Person remote = (Person) cache1_.find("/a");
|
101 |
2
| assertEquals("Age should be ", 10, remote.getAge());
|
102 |
| |
103 |
| |
104 |
2
| cache1_.detach("/a");
|
105 |
2
| assertNull("Object should be null ", cache_.find("/a"));
|
106 |
| |
107 |
2
| assertNull("Object should be null ", cache1_.find("/a"));
|
108 |
| |
109 |
2
| assertEquals("Age should be ", 0, remote.getAge());
|
110 |
| } |
111 |
| |
112 |
2
| public void testRemoteRemove2() throws Exception
|
113 |
| { |
114 |
2
| log_.info("testRemoteRemove() ....");
|
115 |
2
| Person test = new Person();
|
116 |
2
| test.setName("Ben");
|
117 |
2
| test.setAge(10);
|
118 |
2
| cache_.attach("/a", test);
|
119 |
2
| Person result = (Person) cache_.find("/a");
|
120 |
2
| assertEquals(" ", test, result);
|
121 |
| |
122 |
2
| Person remote = (Person) cache1_.find("/a");
|
123 |
2
| assertEquals("Age should be ", 10, remote.getAge());
|
124 |
| |
125 |
| |
126 |
2
| cache_.detach("/a");
|
127 |
2
| assertNull("Object should be null ", cache_.find("/a"));
|
128 |
| |
129 |
2
| assertNull("Object should be null ", cache1_.find("/a"));
|
130 |
| |
131 |
2
| try
|
132 |
| { |
133 |
2
| remote.getAge();
|
134 |
0
| fail("Should throw out exception here.");
|
135 |
| } |
136 |
| catch (PojoCacheAlreadyDetachedException pe) |
137 |
| { |
138 |
| } |
139 |
| } |
140 |
| |
141 |
| |
142 |
| |
143 |
| |
144 |
| |
145 |
| |
146 |
2
| public void testRemoteDetach() throws Exception
|
147 |
| { |
148 |
2
| log_.info("testRemoteDetach() ....");
|
149 |
2
| SpecialSerializedAddress addr = new SpecialSerializedAddress();
|
150 |
2
| addr.setZip(95123);
|
151 |
2
| addr.addResidents("Ben");
|
152 |
2
| addr.addResidents("Joe");
|
153 |
| |
154 |
2
| Fqn fqn = new Fqn("/plain");
|
155 |
2
| cache_.getCache().put(fqn, "test", addr);
|
156 |
2
| cache_.getCache().remove(fqn, "test");
|
157 |
| |
158 |
2
| cache_.attach("/a", addr);
|
159 |
2
| SpecialSerializedAddress result = (SpecialSerializedAddress) cache_.find("/a");
|
160 |
2
| assertEquals(" ", addr, result);
|
161 |
| |
162 |
| |
163 |
2
| cache_.detach("/a");
|
164 |
2
| assertNull("Object should be null ", cache_.find("/a"));
|
165 |
| |
166 |
| |
167 |
2
| cache_.getCache().put(fqn, "test", addr);
|
168 |
| |
169 |
2
| SpecialSerializedAddress remote = (SpecialSerializedAddress)
|
170 |
| cache1_.getCache().get(fqn, "test"); |
171 |
2
| assertEquals("Name should be ", 95123, remote.getZip());
|
172 |
| } |
173 |
| |
174 |
2
| public void testPutArray1() throws Exception
|
175 |
| { |
176 |
2
| log_.info("testPutArray1() ....");
|
177 |
2
| long[] arr = new long[]{1, 2};
|
178 |
2
| cache_.attach("array", arr);
|
179 |
| |
180 |
2
| long[] a2 = (long[]) cache1_.find("array");
|
181 |
2
| assertEquals("arr 0", 1, a2[0]);
|
182 |
| } |
183 |
| |
184 |
2
| public void testPutArray2() throws Exception
|
185 |
| { |
186 |
2
| log_.info("testPutArray2() ....");
|
187 |
2
| Person p1 = new Person();
|
188 |
2
| p1.setName("Ben");
|
189 |
2
| p1.setAge(10);
|
190 |
| |
191 |
2
| Person p2 = new Person();
|
192 |
2
| p2.setName("Joe");
|
193 |
2
| p2.setAge(20);
|
194 |
2
| Person[] arr = new Person[]{p1, p2};
|
195 |
| |
196 |
2
| cache_.attach("array", arr);
|
197 |
| |
198 |
2
| Person[] a2 = (Person[]) cache1_.find("array");
|
199 |
2
| assertEquals("arr 0", "Ben", a2[0].getName());
|
200 |
| } |
201 |
| |
202 |
| |
203 |
| |
204 |
| |
205 |
| |
206 |
| |
207 |
| |
208 |
2
| public void testStateTransfer() throws Exception
|
209 |
| { |
210 |
2
| log_.info("testStateTransfer() ....");
|
211 |
2
| Person test = new Person();
|
212 |
2
| test.setName("Ben");
|
213 |
2
| test.setAge(10);
|
214 |
2
| cache_.attach("/a", test);
|
215 |
2
| Person result = (Person) cache_.find("/a");
|
216 |
2
| assertEquals(" ", test, result);
|
217 |
| |
218 |
| |
219 |
2
| cache1_.stop();
|
220 |
2
| cache1_.getCache().removeNode(Fqn.fromString("/a"));
|
221 |
2
| cache1_.start();
|
222 |
| |
223 |
2
| Person remote = (Person) cache1_.find("/a");
|
224 |
2
| assertEquals("Age should be ", 10, remote.getAge());
|
225 |
| } |
226 |
| |
227 |
2
| public static Test suite() throws Exception
|
228 |
| { |
229 |
2
| return new TestSuite(NewReplicatedTest.class);
|
230 |
| } |
231 |
| |
232 |
| |
233 |
0
| public static void main(String[] args) throws Exception
|
234 |
| { |
235 |
0
| junit.textui.TestRunner.run(suite());
|
236 |
| } |
237 |
| |
238 |
| } |
239 |
| |