1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| package org.jboss.cache.pojo; |
9 |
| |
10 |
| import junit.framework.Test; |
11 |
| import junit.framework.TestCase; |
12 |
| import junit.framework.TestSuite; |
13 |
| import org.apache.commons.logging.Log; |
14 |
| import org.apache.commons.logging.LogFactory; |
15 |
| import org.jboss.cache.config.Configuration.CacheMode; |
16 |
| import org.jboss.cache.factories.UnitTestCacheConfigurationFactory; |
17 |
| import org.jboss.cache.pojo.test.Address; |
18 |
| import org.jboss.cache.pojo.test.Person; |
19 |
| |
20 |
| import javax.naming.Context; |
21 |
| import java.util.ArrayList; |
22 |
| import java.util.List; |
23 |
| import java.util.Properties; |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| public class ReplicatedPutWithBulkRemoveTest extends TestCase |
32 |
| { |
33 |
| Log log_ = LogFactory.getLog(ReplicatedPutWithBulkRemoveTest.class); |
34 |
| PojoCache cache_; |
35 |
| PojoCache cache1_; |
36 |
| |
37 |
3
| public ReplicatedPutWithBulkRemoveTest(String name)
|
38 |
| { |
39 |
3
| super(name);
|
40 |
| } |
41 |
| |
42 |
3
| protected void setUp() throws Exception
|
43 |
| { |
44 |
3
| super.setUp();
|
45 |
3
| Properties prop = new Properties();
|
46 |
3
| prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
|
47 |
3
| boolean toStart = false;
|
48 |
3
| cache_ = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
|
49 |
3
| cache1_ = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), toStart);
|
50 |
3
| cache_.start();
|
51 |
3
| cache1_.start();
|
52 |
| } |
53 |
| |
54 |
3
| protected void tearDown() throws Exception
|
55 |
| { |
56 |
3
| super.tearDown();
|
57 |
3
| cache_.stop();
|
58 |
3
| cache1_.stop();
|
59 |
| } |
60 |
| |
61 |
1
| public void testPutPutLocal() throws Exception
|
62 |
| { |
63 |
1
| log_.info("testPutPut() ....");
|
64 |
1
| Person test = new Person();
|
65 |
1
| test.setName("Ben");
|
66 |
1
| test.setAge(10);
|
67 |
1
| Address addr = new Address();
|
68 |
1
| addr.setZip(95123);
|
69 |
1
| addr.setCity("Sunnyvale");
|
70 |
1
| test.setAddress(addr);
|
71 |
1
| cache_.attach("/a", test);
|
72 |
1
| Person result = (Person) cache_.find("/a");
|
73 |
1
| assertEquals(" ", test, result);
|
74 |
| |
75 |
1
| Person joe = new Person();
|
76 |
1
| joe.setName("joe");
|
77 |
1
| joe.setAge(20);
|
78 |
1
| cache_.attach("/a", joe);
|
79 |
1
| Person joe1 = (Person) cache_.find("/a");
|
80 |
1
| assertEquals("Age should be ", 20, joe1.getAge());
|
81 |
| |
82 |
1
| assertEquals("Age should be ", 10, result.getAge());
|
83 |
1
| assertEquals("Zip should be ", 95123, result.getAddress().getZip());
|
84 |
| |
85 |
| |
86 |
1
| cache_.attach("/a", test);
|
87 |
1
| Person result1 = (Person) cache_.find("/a");
|
88 |
1
| assertEquals("Zip should be ", 95123, result1.getAddress().getZip());
|
89 |
| |
90 |
| } |
91 |
| |
92 |
1
| public void testPutPut() throws Exception
|
93 |
| { |
94 |
1
| log_.info("testPutPut() ....");
|
95 |
1
| Person test = new Person();
|
96 |
1
| test.setName("Ben");
|
97 |
1
| test.setAge(10);
|
98 |
1
| Address addr = new Address();
|
99 |
1
| addr.setZip(95123);
|
100 |
1
| addr.setCity("Sunnyvale");
|
101 |
1
| test.setAddress(addr);
|
102 |
1
| cache_.attach("/a", test);
|
103 |
1
| Person result = (Person) cache_.find("/a");
|
104 |
1
| assertEquals(" ", test, result);
|
105 |
| |
106 |
1
| Person result1 = (Person) cache1_.find("/a");
|
107 |
1
| assertEquals("Age should be ", 10, result1.getAge());
|
108 |
1
| assertEquals("Zip should be ", 95123, result1.getAddress().getZip());
|
109 |
| |
110 |
1
| Person joe = new Person();
|
111 |
1
| joe.setName("joe");
|
112 |
1
| joe.setAge(20);
|
113 |
1
| cache_.attach("/a", joe);
|
114 |
1
| Person joe1 = (Person) cache_.find("/a");
|
115 |
1
| assertEquals("Age should be ", 20, joe1.getAge());
|
116 |
| |
117 |
1
| assertEquals("Age should be ", 10, result.getAge());
|
118 |
1
| assertEquals("Zip should be ", 95123, result.getAddress().getZip());
|
119 |
| } |
120 |
| |
121 |
1
| Address getAddress(String city)
|
122 |
| { |
123 |
1
| Address addr = new Address();
|
124 |
1
| addr.setCity(city);
|
125 |
1
| addr.setZip(95123);
|
126 |
1
| addr.setStreet("Sunnyvale");
|
127 |
1
| return addr;
|
128 |
| } |
129 |
| |
130 |
1
| public void testPutCollection() throws Exception
|
131 |
| { |
132 |
1
| log_.info("testPutCollection() ....");
|
133 |
1
| Person p1 = new Person();
|
134 |
1
| p1.setName("Ben");
|
135 |
1
| p1.setAge(10);
|
136 |
1
| p1.setAddress(getAddress("Sunnyvale"));
|
137 |
| |
138 |
1
| List<String> lang = new ArrayList<String>();
|
139 |
1
| lang.add("English");
|
140 |
1
| lang.add("Spanish");
|
141 |
1
| p1.setLanguages(lang);
|
142 |
| |
143 |
1
| cache_.attach("/a", p1);
|
144 |
1
| Person result = (Person) cache_.find("/a");
|
145 |
1
| assertEquals(" ", p1, result);
|
146 |
1
| assertEquals("English", result.getLanguages().get(0));
|
147 |
1
| assertEquals("Spanish", result.getLanguages().get(1));
|
148 |
| |
149 |
1
| Person result1 = (Person) cache1_.find("/a");
|
150 |
1
| assertEquals("Age should be ", 10, result1.getAge());
|
151 |
1
| assertEquals("Zip should be ", 95123, result1.getAddress().getZip());
|
152 |
1
| assertEquals("English", result1.getLanguages().get(0));
|
153 |
1
| assertEquals("Spanish", result1.getLanguages().get(1));
|
154 |
| |
155 |
1
| Person p2 = new Person();
|
156 |
1
| p2.setName("joe");
|
157 |
1
| p2.setAge(20);
|
158 |
1
| List<String> lang2 = new ArrayList<String>();
|
159 |
1
| lang2.add("French");
|
160 |
1
| p2.setLanguages(lang2);
|
161 |
| |
162 |
1
| cache_.attach("/a", p2);
|
163 |
1
| Person joe1 = (Person) cache_.find("/a");
|
164 |
1
| assertEquals("Age should be ", 20, joe1.getAge());
|
165 |
1
| assertEquals("French", joe1.getLanguages().get(0));
|
166 |
| |
167 |
| |
168 |
1
| cache_.attach("/a", p1);
|
169 |
| |
170 |
| |
171 |
1
| Person p3 = (Person) cache_.detach("/a");
|
172 |
1
| assertEquals("Zip should be ", 95123, p3.getAddress().getZip());
|
173 |
1
| assertEquals("English", p3.getLanguages().get(0));
|
174 |
1
| assertEquals("Spanish", p3.getLanguages().get(1));
|
175 |
| |
176 |
1
| assertEquals("Age should be ", 10, result.getAge());
|
177 |
1
| assertEquals("Zip should be ", 95123, result.getAddress().getZip());
|
178 |
1
| assertEquals("English", result.getLanguages().get(0));
|
179 |
1
| assertEquals("Spanish", result.getLanguages().get(1));
|
180 |
| } |
181 |
| |
182 |
1
| public static Test suite() throws Exception
|
183 |
| { |
184 |
1
| return new TestSuite(ReplicatedPutWithBulkRemoveTest.class);
|
185 |
| } |
186 |
| |
187 |
| |
188 |
0
| public static void main(String[] args) throws Exception
|
189 |
| { |
190 |
0
| junit.textui.TestRunner.run(ReplicatedPutWithBulkRemoveTest.suite());
|
191 |
| } |
192 |
| |
193 |
| } |