KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cluster > test > UndeployTestCase


1 package org.jboss.test.cluster.test;
2
3 import junit.framework.Test;
4
5 import org.apache.commons.httpclient.HttpClient;
6 import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
7 import org.jboss.test.JBossClusteredTestCase;
8
9 /**
10  * Tests that a clustered session still functions properly on the second
11  * node after the webapp is undeployed from the first node.
12  * <p/>
13  * This version tests a SessionBasedClusteredSession.
14  *
15  * @author Brian Stansberry
16  * @version $Id: UndeployTestCase.java 58602 2006-11-18 11:53:24Z bstansberry@jboss.com $
17  */

18 public class UndeployTestCase extends BaseTest
19 {
20    protected String JavaDoc setUrl_;
21    protected String JavaDoc getUrl_;
22    protected String JavaDoc setUrlBase_;
23    protected String JavaDoc getUrlBase_;
24    
25    protected boolean deployed0_ = true;
26    protected boolean deployed1_ = true;
27    
28    public UndeployTestCase(String JavaDoc name)
29    {
30       super(name);
31       setUrlBase_ = "setSession.jsp";
32       getUrlBase_ = "getAttribute.jsp";
33
34       concatenate();
35    }
36    
37    protected String JavaDoc getContextPath()
38    {
39       return "/http-scoped/";
40    }
41    
42    protected String JavaDoc getWarName()
43    {
44       return "http-scoped.war";
45    }
46
47    public static Test suite() throws Exception JavaDoc
48    {
49       Test t1 = JBossClusteredTestCase.getDeploySetup(UndeployTestCase.class,
50             "http-scoped.war");
51       return t1;
52    }
53
54    /**
55     * Main method that deals with the Http Session Replication Test
56     *
57     * @throws Exception
58     */

59    public void testNonPrimitiveGet()
60          throws Exception JavaDoc
61    {
62       String JavaDoc attr = "";
63       getLog().info("Enter testNonPrimitiveGet");
64
65       getLog().debug(setUrl_ + ":::::::" + getUrl_);
66
67       // Create an instance of HttpClient.
68
HttpClient client = new HttpClient();
69
70       // Set the session attribute first
71
makeGet(client, baseURL0_ +setUrl_);
72
73       // Create a method instance.
74
// Get the Attribute set
75
attr = makeGetWithState(client, baseURL0_ +getUrl_);
76       
77       reconfigureCluster();
78
79       sleepThread(DEFAULT_SLEEP);
80
81       // Make connection to server 1 and get
82
setCookieDomainToThisServer(client, servers_[1]);
83       String JavaDoc attr2 = makeGetWithState(client, baseURL1_ + getUrl_);
84
85       assertEquals("Get attribute should be but is ", attr, attr2);
86       getLog().debug("Exit testNonPrimitiveGet");
87    }
88    
89    /**
90     * Tests the ability to passivate sessions on undeployment of an application
91     * and to activate it on restart or redeployment of an application
92     * @throws Exception
93     */

94    public void XtestSessionPassivationActivation() throws Exception JavaDoc
95    {
96        getLog().info("Enter testSessionPassivationActivation");
97        
98        getLog().debug(setUrl_ + ":::::::" + getUrl_);
99        
100        // force deployment
101
RMIAdaptor[] adaptors = getAdaptors();
102        String JavaDoc warName = getWarName();
103        deploy(adaptors[0], warName);
104        deploy(adaptors[1], warName);
105        
106        sleep(2000);
107           
108         // the code above should be removed when we figure out what's wrong
109
// with configure cluster.
110

111        // Create an instance of HttpClient.
112
HttpClient client = new HttpClient();
113
114        // Set the session attribute first
115
makeGet(client, baseURL0_ +setUrl_);
116        
117        // replicate the session to server1
118
sleepThread(DEFAULT_SLEEP);
119        
120        // Get the Attribute set
121
String JavaDoc attr = makeGetWithState(client, baseURL0_ +getUrl_);
122        
123        // Make connection to server 1 and get
124
setCookieDomainToThisServer(client, servers_[1]);
125        String JavaDoc attr2 = makeGetWithState(client, baseURL1_ + getUrl_);
126        
127        assertEquals("attribute match", attr, attr2);
128        
129        
130        
131        // undeploy server0, which passivates the session to the distributed store
132
undeploy(adaptors[0], warName);
133        
134
135        sleep(2000);
136        // redeploy the application on server 0
137
deploy(adaptors[0], warName);
138
139        sleep(2000);
140        
141        // Get the Attribute using the same session ID
142
setCookieDomainToThisServer(client, servers_[0]);
143        String JavaDoc attr0 = makeGet(client, baseURL0_ +getUrl_);
144        
145        assertEquals("attributeMatches after activation", attr0, attr);
146        
147        getLog().debug("Exit testSessionPassivationActivation");
148        
149    }
150
151    protected void concatenate()
152    {
153       setUrl_ = getContextPath() +setUrlBase_;
154       getUrl_ = getContextPath() +getUrlBase_;
155    }
156    
157    protected void setUp() throws Exception JavaDoc
158    {
159       super.setUp();
160       configureCluster();
161    }
162
163    protected void configureCluster() throws Exception JavaDoc
164    {
165       RMIAdaptor[] adaptors = getAdaptors();
166       String JavaDoc warName = getWarName();
167       if (!deployed0_)
168       {
169          deploy(adaptors[0], warName);
170          getLog().debug("Deployed " + warName + " on server0");
171          deployed0_ = true;
172       }
173       if (!deployed1_)
174       {
175          deploy(adaptors[1], warName);
176          getLog().debug("Deployed " + warName + " on server1");
177          deployed1_ = true;
178       }
179    
180       sleep(2000);
181    }
182    
183    protected void reconfigureCluster() throws Exception JavaDoc
184    {
185       RMIAdaptor[] adaptors = getAdaptors();
186       deploy(adaptors[1], getWarName());
187       deployed1_ = true;
188       
189       sleep(2000);
190       
191       undeploy(adaptors[0], getWarName());
192       deployed0_ = false;
193       
194       sleep(2000);
195    }
196
197 }
198
Popular Tags