1 22 23 package org.jboss.test.cluster.test; 24 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.Set ; 28 29 import javax.management.MalformedObjectNameException ; 30 import javax.management.ObjectName ; 31 32 import junit.framework.Test; 33 34 import org.apache.commons.httpclient.HttpClient; 35 import org.jboss.cache.Fqn; 36 import org.jboss.cache.buddyreplication.BuddyManager; 37 import org.jboss.jmx.adaptor.rmi.RMIAdaptor; 38 import org.jboss.test.JBossClusteredTestCase; 39 40 48 public class StateTransferTestCase extends BaseTest 49 { 50 51 private static final Object [] NULL_ARGS = new Object [] {}; 52 private static final String [] NULL_TYPES = new String [] {}; 53 54 private static final ObjectName CACHE_OBJECT_NAME; 55 static 56 { 57 try 58 { 59 CACHE_OBJECT_NAME = 60 new ObjectName ("jboss.cache:service=TomcatClusteringCache"); 61 } 62 catch (MalformedObjectNameException e) 63 { 64 throw new ExceptionInInitializerError (e); 65 } 66 } 67 68 protected String setUrl_; 69 protected String getUrl_; 70 protected String setUrlBase_; 71 protected String getUrlBase_; 72 73 private ObjectName warObjectName; 74 private RMIAdaptor adaptor0_; 75 private RMIAdaptor adaptor1_; 76 private String warFqn_; 77 78 83 public StateTransferTestCase(String name) 84 { 85 super(name); 86 setUrlBase_ = "setSession.jsp"; 87 getUrlBase_ = "getAttribute.jsp"; 88 concatenate(); 89 } 90 91 protected void concatenate() 92 { 93 String contextPath = "/" + getWarName() + "/"; 94 setUrl_ = contextPath +setUrlBase_; 95 getUrl_ = contextPath +getUrlBase_; 96 } 97 98 public static Test suite() throws Exception 99 { 100 Test t1 = JBossClusteredTestCase.getDeploySetup(StateTransferTestCase.class, 101 "http-scoped.war"); 102 return t1; 103 } 104 105 protected void setUp() throws Exception 106 { 107 super.setUp(); 108 109 if (warObjectName == null) 110 { 111 String oname = "jboss.web:J2EEApplication=none,J2EEServer=none," + 112 "j2eeType=WebModule,name=//localhost/" + getWarName(); 113 warObjectName = new ObjectName (oname); 114 115 RMIAdaptor[] adaptors = getAdaptors(); 116 adaptor0_ = adaptors[0]; 117 adaptor1_ = adaptors[1]; 118 119 Object [] names = {"JSESSION", "localhost", getWarName() }; 120 Fqn fqn = new Fqn(names); 121 warFqn_ = fqn.toString(); 122 } 123 } 124 125 protected void tearDown() throws Exception 126 { 127 try 128 { 129 SessionTestUtil.uninstallHelper(adaptor0_); 130 } 131 catch (Exception e) {} 132 try 133 { 134 SessionTestUtil.uninstallHelper(adaptor1_); 135 } 136 catch (Exception e) {} 137 } 138 139 protected String getWarName() 140 { 141 return "http-scoped"; 142 } 143 144 public void testActivationInactivation() throws Exception 145 { 146 getLog().debug("Enter testActivationInactivation"); 147 148 getLog().debug(setUrl_ + ":::::::" + getUrl_); 149 150 SessionTestUtil.leaveHelperOnServer(adaptor1_); 152 adaptor1_.invoke(warObjectName, "stop" , NULL_ARGS, NULL_TYPES); 153 154 HttpClient client0 = new HttpClient(); 156 makeGetFailed(client0, baseURL1_ +setUrl_); 157 158 HttpClient[] clients = new HttpClient[3]; 160 String [] attrs = new String [clients.length]; 161 for (int i = 0; i < clients.length; i++) 162 { 163 clients[i] = new HttpClient(); 164 makeGet(clients[i], baseURL0_ +setUrl_); 165 attrs[i] = makeGet(clients[i], baseURL0_ + getUrl_); 166 this.setCookieDomainToThisServer(clients[i], servers_[1]); 168 } 169 170 getLog().debug("Sessions created"); 171 172 Set sessions = SessionTestUtil.getSessionIds(adaptor1_, warFqn_); 174 175 assertTrue("server1 has no cached sessions", sessions.size() == 0); 176 177 getLog().debug("Server1 has no cached sessions"); 178 179 adaptor1_.invoke(warObjectName, "start" , NULL_ARGS, NULL_TYPES); 181 182 getLog().debug("Server1 started"); 183 184 sessions = SessionTestUtil.getSessionIds(adaptor1_, warFqn_); 186 187 assertEquals("server1 has cached sessions", clients.length, sessions.size()); 188 189 getLog().debug("Server1 has cached sessions"); 190 191 for (int i = 0; i < clients.length; i++) 192 { 193 String attr = makeGet(clients[i], baseURL1_ + getUrl_); 194 assertEquals("attribute matches for client " + i, attrs[i], attr); 195 } 196 197 getLog().debug("Attributes match"); 198 199 sleep(500); 202 203 SessionTestUtil.leaveHelperOnServer(adaptor0_); 205 adaptor0_.invoke(warObjectName, "stop" , NULL_ARGS, NULL_TYPES); 206 207 sessions = SessionTestUtil.getSessionIds(adaptor0_, warFqn_); 209 210 assertTrue("server0 has no cached sessions", sessions.size() == 0); 211 212 getLog().debug("Server0 has no cached sessions"); 213 } 214 } 215 | Popular Tags |