1 7 package org.jboss.cache.buddyreplication; 8 9 import org.jboss.cache.CacheImpl; 10 import org.jboss.cache.Fqn; 11 import org.jboss.cache.config.BuddyReplicationConfig; 12 import org.jboss.cache.factories.XmlConfigurationParser; 13 import org.w3c.dom.Document ; 14 import org.w3c.dom.Element ; 15 16 import javax.xml.parsers.DocumentBuilder ; 17 import javax.xml.parsers.DocumentBuilderFactory ; 18 import java.util.HashMap ; 19 import java.util.Map ; 20 import java.util.Set ; 21 22 28 public class BuddyBackupActivationInactivationTest extends BuddyReplicationTestsBase 29 { 30 public static final Fqn A = Fqn.fromString("/a"); 31 public static final Fqn A_B = Fqn.fromString("/a/b"); 32 public static final String JOE = "JOE"; 33 34 protected Map caches; 35 private ClassLoader orig_TCL; 36 37 public void testBuddyBackupActivation() throws Exception 38 { 39 62 } 63 64 public void testReplToInactiveRegion() throws Exception 65 { 66 96 } 97 98 public void testBuddyBackupInactivation() throws Exception 99 { 100 121 122 } 123 124 protected CacheImpl createCache(String cacheID, 125 boolean sync, 126 boolean useMarshalling, 127 boolean startCache) 128 throws Exception 129 { 130 if (caches.get(cacheID) != null) 131 throw new IllegalStateException (cacheID + " already created"); 132 133 CacheImpl cache = new CacheImpl(); 134 135 String configFile = sync ? "META-INF/replSync-service.xml" 136 : "META-INF/replAsync-service.xml"; 137 cache.setConfiguration(new XmlConfigurationParser().parseFile(configFile)); 138 cache.getConfiguration().setClusterName("Test"); 139 if (useMarshalling) 140 { 141 cache.getConfiguration().setUseRegionBasedMarshalling(true); 142 cache.getConfiguration().setInactiveOnStartup(true); 143 } 144 cache.getConfiguration().setBuddyReplicationConfig(getBuddyConfig()); 145 caches.put(cacheID, cache); 148 149 if (startCache) 150 { 151 cache.create(); 152 cache.start(); 153 } 154 155 return cache; 156 } 157 158 protected void setUp() throws Exception 159 { 160 super.setUp(); 161 162 caches = new HashMap (); 163 164 orig_TCL = Thread.currentThread().getContextClassLoader(); 166 } 167 168 protected void tearDown() throws Exception 169 { 170 super.tearDown(); 171 172 Thread.currentThread().setContextClassLoader(orig_TCL); 174 175 Set keys = caches.keySet(); 176 String [] cacheIDs = new String [keys.size()]; 177 cacheIDs = (String []) keys.toArray(cacheIDs); 178 for (int i = 0; i < cacheIDs.length; i++) 179 { 180 stopCache((CacheImpl) caches.get(cacheIDs[i])); 181 } 182 } 183 184 protected void stopCache(CacheImpl cache) 185 { 186 if (cache != null) 187 { 188 try 189 { 190 cache.stop(); 191 cache.destroy(); 192 } 193 catch (Exception e) 194 { 195 System.out.println("Exception stopping cache " + e.getMessage()); 196 e.printStackTrace(System.out); 197 } 198 } 199 } 200 201 private BuddyReplicationConfig getBuddyConfig() throws Exception 202 { 203 205 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 206 DocumentBuilder db = dbf.newDocumentBuilder(); 207 Document doc = db.newDocument(); 208 Element config = doc.createElement("config"); 209 doc.appendChild(config); 210 Element replEnabled = doc.createElement("buddyReplicationEnabled"); 211 replEnabled.appendChild(doc.createTextNode("true")); 212 config.appendChild(replEnabled); 213 Element gravDisabled = doc.createElement("autoDataGravitation"); 214 gravDisabled.appendChild(doc.createTextNode("false")); 215 config.appendChild(gravDisabled); 216 217 return XmlConfigurationParser.parseBuddyReplicationConfig(config); 218 } 219 } 220 | Popular Tags |