1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.buddyreplication; |
8 |
| |
9 |
| import org.jboss.cache.CacheImpl; |
10 |
| import org.jboss.cache.DefaultCacheFactory; |
11 |
| import org.jboss.cache.Fqn; |
12 |
| import org.jboss.cache.config.BuddyReplicationConfig; |
13 |
| import org.jboss.cache.config.Configuration; |
14 |
| import org.jboss.cache.config.Configuration.CacheMode; |
15 |
| import org.jboss.cache.factories.UnitTestCacheFactory; |
16 |
| import org.jboss.cache.factories.XmlConfigurationParser; |
17 |
| import org.w3c.dom.Document; |
18 |
| import org.w3c.dom.Element; |
19 |
| |
20 |
| import javax.xml.parsers.DocumentBuilder; |
21 |
| import javax.xml.parsers.DocumentBuilderFactory; |
22 |
| import java.util.HashMap; |
23 |
| import java.util.Map; |
24 |
| import java.util.Set; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| public class BuddyBackupActivationInactivationTest extends BuddyReplicationTestsBase |
33 |
| { |
34 |
| public static final Fqn A = Fqn.fromString("/a"); |
35 |
| public static final Fqn A_B = Fqn.fromString("/a/b"); |
36 |
| public static final String JOE = "JOE"; |
37 |
| |
38 |
| protected Map caches; |
39 |
| private ClassLoader orig_TCL; |
40 |
| |
41 |
2
| public void testBuddyBackupActivation() throws Exception
|
42 |
| { |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| } |
67 |
| |
68 |
2
| public void testReplToInactiveRegion() throws Exception
|
69 |
| { |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
| } |
101 |
| |
102 |
2
| public void testBuddyBackupInactivation() throws Exception
|
103 |
| { |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| } |
127 |
| |
128 |
0
| protected CacheImpl createCache(String cacheID,
|
129 |
| boolean sync, |
130 |
| boolean useMarshalling, |
131 |
| boolean startCache) |
132 |
| throws Exception |
133 |
| { |
134 |
0
| if (caches.get(cacheID) != null)
|
135 |
| { |
136 |
0
| throw new IllegalStateException(cacheID + " already created");
|
137 |
| } |
138 |
| |
139 |
0
| CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
140 |
| |
141 |
0
| CacheMode mode = sync ? CacheMode.REPL_SYNC : CacheMode.REPL_ASYNC;
|
142 |
0
| Configuration c = UnitTestCacheFactory.createConfiguration(mode);
|
143 |
| |
144 |
0
| cache.setConfiguration(c);
|
145 |
0
| cache.getConfiguration().setClusterName("Test");
|
146 |
0
| if (useMarshalling)
|
147 |
| { |
148 |
0
| cache.getConfiguration().setUseRegionBasedMarshalling(true);
|
149 |
0
| cache.getConfiguration().setInactiveOnStartup(true);
|
150 |
| } |
151 |
0
| cache.getConfiguration().setBuddyReplicationConfig(getBuddyConfig());
|
152 |
| |
153 |
| |
154 |
0
| caches.put(cacheID, cache);
|
155 |
| |
156 |
0
| if (startCache)
|
157 |
| { |
158 |
0
| cache.create();
|
159 |
0
| cache.start();
|
160 |
| } |
161 |
| |
162 |
0
| return cache;
|
163 |
| } |
164 |
| |
165 |
6
| protected void setUp() throws Exception
|
166 |
| { |
167 |
6
| super.setUp();
|
168 |
| |
169 |
6
| caches = new HashMap();
|
170 |
| |
171 |
| |
172 |
6
| orig_TCL = Thread.currentThread().getContextClassLoader();
|
173 |
| } |
174 |
| |
175 |
6
| protected void tearDown() throws Exception
|
176 |
| { |
177 |
6
| super.tearDown();
|
178 |
| |
179 |
| |
180 |
6
| Thread.currentThread().setContextClassLoader(orig_TCL);
|
181 |
| |
182 |
6
| Set keys = caches.keySet();
|
183 |
6
| String[] cacheIDs = new String[keys.size()];
|
184 |
6
| cacheIDs = (String[]) keys.toArray(cacheIDs);
|
185 |
6
| for (int i = 0; i < cacheIDs.length; i++)
|
186 |
| { |
187 |
0
| stopCache((CacheImpl) caches.get(cacheIDs[i]));
|
188 |
| } |
189 |
| } |
190 |
| |
191 |
0
| protected void stopCache(CacheImpl cache)
|
192 |
| { |
193 |
0
| if (cache != null)
|
194 |
| { |
195 |
0
| try
|
196 |
| { |
197 |
0
| cache.stop();
|
198 |
0
| cache.destroy();
|
199 |
| } |
200 |
| catch (Exception e) |
201 |
| { |
202 |
0
| System.out.println("Exception stopping cache " + e.getMessage());
|
203 |
0
| e.printStackTrace(System.out);
|
204 |
| } |
205 |
| } |
206 |
| } |
207 |
| |
208 |
0
| private BuddyReplicationConfig getBuddyConfig() throws Exception
|
209 |
| { |
210 |
| |
211 |
| |
212 |
0
| DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
213 |
0
| DocumentBuilder db = dbf.newDocumentBuilder();
|
214 |
0
| Document doc = db.newDocument();
|
215 |
0
| Element config = doc.createElement("config");
|
216 |
0
| doc.appendChild(config);
|
217 |
0
| Element replEnabled = doc.createElement("buddyReplicationEnabled");
|
218 |
0
| replEnabled.appendChild(doc.createTextNode("true"));
|
219 |
0
| config.appendChild(replEnabled);
|
220 |
0
| Element gravDisabled = doc.createElement("autoDataGravitation");
|
221 |
0
| gravDisabled.appendChild(doc.createTextNode("false"));
|
222 |
0
| config.appendChild(gravDisabled);
|
223 |
| |
224 |
0
| return XmlConfigurationParser.parseBuddyReplicationConfig(config);
|
225 |
| } |
226 |
| } |