KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cluster.test;
23
24 import java.io.IOException JavaDoc;
25 import java.net.HttpURLConnection JavaDoc;
26
27 import javax.management.ObjectName JavaDoc;
28
29 import junit.framework.Test;
30
31 import org.apache.commons.httpclient.Cookie;
32 import org.apache.commons.httpclient.Header;
33 import org.apache.commons.httpclient.HttpClient;
34 import org.apache.commons.httpclient.HttpState;
35 import org.apache.commons.httpclient.methods.GetMethod;
36 import org.apache.commons.httpclient.methods.PostMethod;
37 import org.jboss.cache.Fqn;
38 import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
39 import org.jboss.test.JBossClusteredTestCase;
40
41 /**
42  * Clustering test case of get/set under scoped class loader.
43  *
44  * @author Ben Wang
45  * @version $Revision: 1.0
46  */

47 public class ScopedTestCase
48       extends BaseTest
49 {
50    protected String JavaDoc setUrl;
51    protected String JavaDoc getUrl;
52    protected String JavaDoc modifyUrl;
53    protected String JavaDoc modifyNoSetUrl;
54    protected String JavaDoc removeUrl;
55    protected String JavaDoc invalidateUrl;
56    protected String JavaDoc clearUrl;
57    protected String JavaDoc attrListUrl;
58    protected String JavaDoc bindUrl_;
59    protected String JavaDoc protectedUrl_;
60    protected String JavaDoc securityCheckUrl_;
61    protected String JavaDoc loginFormUrl_;
62    protected String JavaDoc setSecuritySubjectUrl_;
63    protected String JavaDoc getSecuritySubjectUrl_;
64    protected String JavaDoc warName_;
65    protected String JavaDoc setUrlBase_;
66    protected String JavaDoc getUrlBase_;
67    protected String JavaDoc modifyUrlBase_;
68    protected String JavaDoc modifyNoSetUrlBase_;
69    protected String JavaDoc removeUrlBase_;
70    protected String JavaDoc invalidateUrlBase_;
71    protected String JavaDoc clearUrlBase_;
72    protected String JavaDoc bindUrlBase_;
73    protected String JavaDoc attrListUrlBase_;
74    protected String JavaDoc protectedUrlBase_;
75    protected String JavaDoc securityCheckUrlBase_;
76    protected String JavaDoc loginFormUrlBase_;
77    protected String JavaDoc setSecuritySubjectUrlBase_;
78    protected String JavaDoc getSecuritySubjectUrlBase_;
79    
80    private ObjectName JavaDoc warObjectName;
81    private String JavaDoc warFqn_;
82
83    public ScopedTestCase(String JavaDoc name)
84    {
85       super(name);
86       warName_ = "/http-scoped/";
87       setUrlBase_ = "setSession.jsp";
88       getUrlBase_ = "getAttribute.jsp";
89       modifyUrlBase_ = "modifyAttribute.jsp";
90       modifyNoSetUrlBase_ = "modifyAttributeNoSet.jsp";
91       removeUrlBase_ = "removeAttribute.jsp";
92       invalidateUrlBase_ = "invalidateSession.jsp";
93       clearUrlBase_ = "clearCache.jsp";
94       bindUrlBase_ = "bindSession.jsp?Binding=";
95       protectedUrlBase_ = "index.html";
96       securityCheckUrlBase_ = "j_security_check";
97       loginFormUrlBase_ = "login.html";
98       attrListUrlBase_ = "attributeNames.jsp";
99       setSecuritySubjectUrlBase_ = "setSecuritySubject.jsp";
100       getSecuritySubjectUrlBase_ = "getSecuritySubject.jsp";
101
102       concatenate();
103    }
104
105    protected void concatenate()
106    {
107       setUrl = warName_ +setUrlBase_;
108       getUrl = warName_ +getUrlBase_;
109       modifyUrl = warName_ +modifyUrlBase_;
110       modifyNoSetUrl = warName_ +modifyNoSetUrlBase_;
111       removeUrl = warName_ +removeUrlBase_;
112       invalidateUrl = warName_ +invalidateUrlBase_;
113       clearUrl = warName_ +clearUrlBase_;
114       bindUrl_ = warName_ + bindUrlBase_;
115       protectedUrl_ = warName_ + protectedUrlBase_;
116       securityCheckUrl_ = warName_ + securityCheckUrlBase_;
117       loginFormUrl_ = warName_ + loginFormUrlBase_;
118       attrListUrl = warName_ + attrListUrlBase_;
119       setSecuritySubjectUrl_ = warName_ + setSecuritySubjectUrlBase_;
120       getSecuritySubjectUrl_ = warName_ + getSecuritySubjectUrlBase_;
121    }
122    
123    protected String JavaDoc getWarName()
124    {
125       return "http-scoped";
126    }
127
128    public static Test suite() throws Exception JavaDoc
129    {
130       Test t1 = JBossClusteredTestCase.getDeploySetup(ScopedTestCase.class,
131             "http-scoped.war");
132       return t1;
133    }
134
135    protected void setUp() throws Exception JavaDoc
136    {
137       super.setUp();
138       
139       if (warObjectName == null)
140       {
141          String JavaDoc oname = "jboss.web:J2EEApplication=none,J2EEServer=none," +
142                         "j2eeType=WebModule,name=//localhost/" + getWarName();
143          warObjectName = new ObjectName JavaDoc(oname);
144          
145          RMIAdaptor[] adaptors = getAdaptors();
146          
147          Object JavaDoc[] names = {"JSESSION", "localhost", getWarName() };
148          Fqn fqn = new Fqn(names);
149          warFqn_ = fqn.toString();
150       }
151    }
152
153    protected void tearDown() throws Exception JavaDoc
154    {
155 // clear();
156
super.tearDown();
157    }
158
159    /**
160     * Main method that deals with the Http Session Replication Test
161     *
162     * @throws Exception
163     */

164    public void testNonPrimitiveGet()
165          throws Exception JavaDoc
166    {
167       String JavaDoc attr = "";
168       getLog().debug("Enter testNonPrimitiveGet");
169
170       getLog().debug(setUrl + ":::::::" + getUrl);
171
172       // Create an instance of HttpClient.
173
HttpClient client = new HttpClient();
174
175       // Set the session attribute first
176
makeGet(client, baseURL0_ +setUrl);
177
178       // Create a method instance.
179
// Get the Attribute set
180
attr = makeGet(client, baseURL0_ +getUrl);
181
182       sleepThread(DEFAULT_SLEEP);
183
184       // Make connection to server 1 and get
185
setCookieDomainToThisServer(client, servers_[1]);
186       String JavaDoc attr2 = makeGet(client, baseURL1_ +getUrl);
187
188       assertEquals("Get attribute should be but is ", attr, attr2);
189       getLog().debug("Exit testNonPrimitiveGet");
190    }
191
192    /**
193     * Test session modify with non-primitive get/modify.
194     *
195     * @throws Exception
196     */

197    public void testNonPrimitiveModify()
198          throws Exception JavaDoc
199    {
200       String JavaDoc attr = "";
201       getLog().debug("Enter testNonPrimitiveModify");
202
203       getLog().debug(setUrl + ":::::::" + getUrl);
204
205       // Create an instance of HttpClient.
206
HttpClient client = new HttpClient();
207
208       // Set the session attribute first
209
makeGet(client, baseURL0_ +setUrl);
210
211       // Get the Attribute set
212
String JavaDoc attrOld = makeGet(client, baseURL0_ +getUrl);
213
214       // Modify a method instance.
215
makeGet(client, baseURL0_ +modifyUrl);
216
217       // Get the Attribute set
218
attr = makeGet(client, baseURL0_ +getUrl);
219
220       sleepThread(DEFAULT_SLEEP);
221
222       // Make connection to server 1 and get
223
setCookieDomainToThisServer(client, servers_[1]);
224       String JavaDoc attr2 = makeGet(client, baseURL1_ +getUrl);
225
226       // Check the result
227
assertNotSame("Old attribute should be different from new one.",
228             attrOld, attr);
229       assertEquals("Attributes should be the same", attr, attr2);
230       getLog().debug("Exit testNonPrimitiveModify");
231    }
232
233    /**
234     * Test session modify with non-primitive get/modify.
235     *
236     * @throws Exception
237     */

238    public void testNonPrimitiveRepeatedModify()
239          throws Exception JavaDoc
240    {
241       String JavaDoc attr = "";
242       getLog().info("Enter testNonPrimitiveRepeatedModify");
243
244       getLog().debug(setUrl + ":::::::" + getUrl);
245
246       // Create an instance of HttpClient.
247
HttpClient client = new HttpClient();
248
249       // Set the session attribute first
250
makeGet(client, baseURL0_ +setUrl);
251
252       // Get the Attribute set
253
String JavaDoc attrOld = makeGetWithState(client, baseURL0_ +getUrl);
254
255       // Modify a method instance.
256
makeGet(client, baseURL0_ +modifyUrl);
257
258       // Get the Attribute set
259
attr = makeGetWithState(client, baseURL0_ +getUrl);
260
261       sleepThread(DEFAULT_SLEEP);
262
263       // Make connection to server 1 and get
264
setCookieDomainToThisServer(client, servers_[1]);
265       String JavaDoc attr2 = makeGetWithState(client, baseURL1_ +getUrl);
266
267       // Check the result
268
assertNotSame("Old attribute should be different from new one.",
269             attrOld, attr);
270       assertEquals("Attributes should be the same", attr, attr2);
271
272
273       // Modify a method instance.
274
makeGet(client, baseURL1_ +modifyUrl);
275
276       // Get the Attribute set
277
attr = makeGetWithState(client, baseURL1_ +getUrl);
278
279       sleepThread(DEFAULT_SLEEP);
280
281       // Make connection to server 1 and get
282
setCookieDomainToThisServer(client, servers_[0]);
283       attr2 = makeGetWithState(client, baseURL0_ +getUrl);
284
285       // Check the result
286
assertEquals("Attributes should be the same after second modify", attr, attr2);
287       getLog().debug("Exit testNonPrimitiveRepeatedModify");
288    }
289
290    /**
291     * Test session modify with non-primitive remove.
292     *
293     * @throws Exception
294     */

295    public void testNonPrimitiveRemove()
296          throws Exception JavaDoc
297    {
298       getLog().debug("Enter testNonPrimitiveRemove");
299
300       getLog().debug(setUrl + ":::::::" + getUrl);
301
302       // Create an instance of HttpClient.
303
HttpClient client = new HttpClient();
304
305       // Set the session attribute first
306
makeGet(client, baseURL0_ +setUrl);
307
308       // Modify a method instance.
309
makeGet(client, baseURL0_ +modifyUrl);
310
311       // Get the Attribute set
312
makeGet(client, baseURL0_ +getUrl);
313
314       // Get the list of attributes
315
String JavaDoc attrList = makeGet(client, baseURL0_ +attrListUrl);
316       
317       assertTrue("TEST_PERSON is an attribute", attrList.indexOf("TEST_PERSON") > -1);
318
319       sleepThread(DEFAULT_SLEEP);
320
321       // Make connection to server 1 and get
322
setCookieDomainToThisServer(client, servers_[1]);
323       // Get the Attribute set
324
makeGet(client, baseURL1_ +getUrl);
325       // Get the list of attributes
326
String JavaDoc attrList1 = makeGet(client, baseURL1_ +attrListUrl);
327       
328       assertTrue("TEST_PERSON is an attribute on server1", attrList1.indexOf("TEST_PERSON") > -1);
329       
330       // Remove the attribute
331
makeGet(client, baseURL1_ +removeUrl);
332       // Attribute is now null. Should have not OK response.
333
makeGetFailed(client, baseURL1_ +getUrl);
334
335       // Confirm the attribute is gone from the list
336
attrList1 = makeGet(client, baseURL1_ +attrListUrl);
337       
338       assertTrue("TEST_PERSON should not be an attribute", attrList1.indexOf("TEST_PERSON") == -1);
339       
340       sleepThread(DEFAULT_SLEEP);
341       // Make connection to server 1 and get
342
setCookieDomainToThisServer(client, servers_[0]);
343       // Attribute is now null. Should have not OK response.
344
makeGetFailed(client, baseURL0_ +getUrl);
345
346       // Confirm the attribute is gone from the list
347
attrList = makeGet(client, baseURL0_ +attrListUrl);
348       
349       assertTrue("TEST_PERSON is not an attribute on server0", attrList.indexOf("TEST_PERSON") == -1);
350
351       getLog().debug("Exit testNonPrimitiveRemove");
352    }
353
354    /**
355     * Test session modify with non-primitive get/modify from node2 and see if it replicates correctly
356     * on node1 or not.
357     *
358     * @throws Exception
359     */

360    public void testNonPrimitiveModifyFromAlternativeNode()
361          throws Exception JavaDoc
362    {
363       String JavaDoc attr = "";
364       getLog().debug("Enter testNonPrimitiveModifyFromAlternativeNode");
365
366       getLog().debug(setUrl + ":::::::" + getUrl);
367
368       // Create an instance of HttpClient.
369
HttpClient client = new HttpClient();
370
371       // Set the session attribute first
372
makeGet(client, baseURL0_ +setUrl);
373
374       // Get the Attribute set
375
String JavaDoc attrOld = makeGet(client, baseURL0_ +getUrl);
376       
377       sleepThread(DEFAULT_SLEEP);
378       
379       // Switch to server 1 and get the attribute
380
setCookieDomainToThisServer(client, servers_[1]);
381       String JavaDoc attrOld1 = makeGet(client, baseURL1_ +getUrl);
382       
383       assertEquals("Attributes should be the same", attrOld, attrOld1);
384
385       // Modify the attribute.
386
makeGet(client, baseURL1_ +modifyUrl);
387       String JavaDoc attr2 = makeGet(client, baseURL1_ +getUrl);
388
389       sleepThread(400);
390       
391       // Switch back to server 0 and get the attribute
392
setCookieDomainToThisServer(client, servers_[0]);
393       attr = makeGet(client, baseURL0_ +getUrl);
394
395       assertEquals("Attributes should be the same", attr, attr2);
396       getLog().debug("Exit testNonPrimitiveModifyModifyFromAlternativeNode");
397    }
398
399    /**
400     * Test invalidate session
401     *
402     * @throws Exception
403     */

404    public void testInvalidate()
405          throws Exception JavaDoc
406    {
407       getLog().debug("Enter testInvalidate");
408
409       getLog().debug(setUrl + ":::::::" + getUrl);
410
411       invalidate();
412       
413       getLog().debug("Exit testInvalidate");
414    }
415    
416    public void testSessionBindingEvent()
417       throws Exception JavaDoc
418    {
419       String JavaDoc attr = "";
420       getLog().debug("Enter testSessionBindingEvent");
421
422       // Create an instance of HttpClient.
423
HttpClient client = new HttpClient();
424       
425       // Bind a new HttpSessionListener to the session
426
// and check that there is a valueBound() event
427
attr = makeGet(client, baseURL0_ + bindUrl_ + "new");
428       assertTrue("Got OK when binding a new listener",
429                  (attr != null && attr.indexOf("OK") >= 0 ) );
430       
431       // Rebind the same HttpSessionListener to the session
432
// and check that there is no valueUnbound()
433
attr = makeGet(client, baseURL0_ + bindUrl_ + "rebind");
434       assertTrue("Got OK when rebinding an existing listener",
435                  (attr != null && attr.indexOf("OK") >= 0 ) );
436       
437       // Replace the HttpSessionListener with another one
438
// and check that there is a valueUnbound()
439
attr = makeGet(client, baseURL0_ + bindUrl_ + "replace");
440       assertTrue("Got OK when replacing a listener",
441                  (attr != null && attr.indexOf("OK") >= 0 ) );
442       
443       // Remove the same HttpSessionListener
444
// and check that there is a valueUnbound()
445
attr = makeGet(client, baseURL0_ + bindUrl_ + "remove");
446       assertTrue("Got OK when removing a listener",
447                  (attr != null && attr.indexOf("OK") >= 0 ) );
448    }
449    
450    public void testExcludeSecuritySubject() throws Exception JavaDoc
451    {
452       getLog().debug("Enter testExcludeSecuritySubject");
453    
454       getLog().debug(setSecuritySubjectUrl_ + ":::::::" + getSecuritySubjectUrl_);
455    
456       // Create an instance of HttpClient.
457
HttpClient client = new HttpClient();
458    
459       // Set the session attribute first
460
makeGet(client, baseURL0_ +setSecuritySubjectUrl_);
461    
462       // Confirm the attribute is available from the server where it was set
463
String JavaDoc attrOrig = makeGet(client, baseURL0_ +getSecuritySubjectUrl_);
464       assertTrue("javax.security.auth.subject available locally",
465             attrOrig.indexOf("javax.security.auth.Subject") > -1);
466       
467       sleepThread(DEFAULT_SLEEP);
468       
469       // Check if the attribute replicated
470
setCookieDomainToThisServer(client, servers_[1]);
471       String JavaDoc attrRepl = makeGet(client, baseURL1_ +getSecuritySubjectUrl_);
472       assertTrue("javax.security.Subject did not replicate", attrRepl.indexOf("java.lang.String") > -1);
473    }
474    
475    /**
476     * Test for JBAS-3528 (http://jira.jboss.com/jira/browse/JBAS-3528).
477     *
478     * @throws Exception
479     */

480    public void testIsNew() throws Exception JavaDoc
481    {
482       getLog().debug("Enter testIsNew");
483
484       getLog().debug(setUrl + ":::::::" + getUrl);
485
486       // Create an instance of HttpClient.
487
HttpClient client = new HttpClient();
488
489       // Set the session attribute first
490
makeGet(client, baseURL0_ +setUrl);
491       
492       sleepThread(DEFAULT_SLEEP);
493
494       // Let's switch to server 2 to retrieve the session attribute.
495
setCookieDomainToThisServer(client, servers_[1]);
496       assertFalse("Session is not new", checkNew(client, baseURL1_ + getUrl));
497       
498       sleepThread(DEFAULT_SLEEP);
499
500       // Let's switch to server 1 to ensure its correct there as well.
501
setCookieDomainToThisServer(client, servers_[0]);
502       assertFalse("Session is not new", checkNew(client, baseURL0_ + getUrl));
503    }
504
505
506    /**
507     * Makes a http call to the given url and confirms that a non-null
508     * header X-SessionIsNew is returned. Converts the value
509     * of the header to a boolean and returns it.
510     *
511     * @param client
512     * @param url
513     */

514    protected boolean checkNew(HttpClient client, String JavaDoc url)
515    {
516       getLog().info("checkNew(): trying to get from url " +url);
517
518       GetMethod method = new GetMethod(url);
519       int responseCode = 0;
520       try
521       {
522          responseCode = client.executeMethod(method);
523       } catch (IOException JavaDoc e)
524       {
525          e.printStackTrace();
526          fail("HttpClient executeMethod fails." +e.toString());
527       }
528       assertTrue("Get OK with url: " +url + " responseCode: " +responseCode
529         , responseCode == HttpURLConnection.HTTP_OK);
530
531       Header hdr = method.getResponseHeader("X-SessionIsNew");
532       assertNotNull("Got X-SessionIsNew header", hdr);
533       String JavaDoc value = hdr.getValue();
534       assertNotNull("Got non-nullX-SessionIsNew header", value);
535       
536       return Boolean.valueOf(value).booleanValue();
537    }
538
539    protected void invalidate() throws Exception JavaDoc
540    {
541       // Create an instance of HttpClient.
542
HttpClient client = new HttpClient();
543
544       // Set the session attribute first
545
makeGet(client, baseURL0_ +setUrl);
546
547       // Get the Attribute set
548
String JavaDoc attr0 = makeGet(client, baseURL0_ +getUrl);
549
550       sleepThread(DEFAULT_SLEEP);
551       
552       // Make connection to server 1 and get
553
setCookieDomainToThisServer(client, servers_[1]);
554       String JavaDoc attr1 = makeGet(client, baseURL1_ + getUrl);
555       
556       assertEquals("attributes match", attr0, attr1);
557       
558       // Invalidate the session
559
makeGet(client, baseURL1_ +invalidateUrl);
560
561       sleepThread(DEFAULT_SLEEP + 200); // wait a bit longer to propagate
562

563       // Make connection to server 0 and get
564
setCookieDomainToThisServer(client, servers_[0]);
565       // Session is invalidated. Should have not OK response.
566
makeGetFailed(client, baseURL0_ + getUrl);
567    }
568
569    protected void clear() throws Exception JavaDoc
570    {
571       // Create an instance of HttpClient.
572
HttpClient client = new HttpClient();
573
574       // Set the session attribute first
575
makeGet(client, baseURL0_ +clearUrl);
576    }
577
578    /**
579     * Test ability for a FORM auth based app to have failover without requiring
580     * a new sign-on
581     *
582     * This test will not pass until a FormAuthenticator that makes
583     * use of cached usernames and passwords is available.
584     *
585     * @throws Exception
586     */

587    public void badtestFormAuthFailover() throws Exception JavaDoc
588    {
589       log.info("+++ testFormAuthFailover");
590       
591       // Start by accessing the war's protected url
592
HttpClient client = new HttpClient();
593       
594       String JavaDoc body = makeGet(client, baseURL0_ + protectedUrl_);
595       if( body.indexOf("j_security_check") < 0 )
596          fail("get of "+protectedUrl_+" not redirected to login page");
597       
598       HttpState state = client.getState();
599       Cookie[] cookies = state.getCookies();
600       String JavaDoc sessionID = null;
601       for(int c = 0; c < cookies.length; c ++)
602       {
603          Cookie k = cookies[c];
604          if( k.getName().equalsIgnoreCase("JSESSIONID") )
605             sessionID = k.getValue();
606       }
607       log.debug("Saw JSESSIONID="+sessionID);
608
609       // Submit the login form
610
PostMethod formPost = new PostMethod(baseURL0_ + securityCheckUrl_);
611       formPost.addRequestHeader("Referer", baseURL0_ + loginFormUrl_);
612       formPost.addParameter("j_username", "admin");
613       formPost.addParameter("j_password", "admin");
614       int responseCode = client.executeMethod(formPost.getHostConfiguration(),
615          formPost, state);
616       String JavaDoc response = formPost.getStatusText();
617       log.debug("responseCode="+responseCode+", response="+response);
618       assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")",
619          responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
620
621       // Follow the redirect to the index.html page
622
body = makeGet(client, baseURL0_ + protectedUrl_);
623       if( body.indexOf("j_security_check") > 0 )
624          fail("get of "+baseURL0_ + protectedUrl_+" redirected to login page");
625
626       // Switch to the second server
627
setCookieDomainToThisServer(client, servers_[1]);
628
629       sleepThread(DEFAULT_SLEEP);
630       
631       // Now try getting the protected url on the second server
632
body = makeGet(client, baseURL1_ + protectedUrl_);
633       if( body.indexOf("j_security_check") > 0 )
634          fail("get of "+baseURL1_ + protectedUrl_+" redirected to login page");
635    }
636    
637    /**
638     * Tests the ability to passivate session when max idle for session is reached
639     *
640     * @throws Exception
641     */

642    // FIXME disabled pending resolving JBAS-3571
643
public void XtestSessionPassivationWMaxIdle() throws Exception JavaDoc
644    {
645       getLog().debug("Enter testSessionPassivationWMaxActive");
646
647       getLog().debug(setUrl + ":::::::" + getUrl);
648
649       // Create an instance of HttpClient.
650
HttpClient client = new HttpClient();
651       // Set the session attribute first
652
makeGet(client, baseURL0_ +setUrl);
653       
654       // Get the Attribute set
655
String JavaDoc attr0 = makeGet(client, baseURL0_ +getUrl);
656       
657       // Find out the session id and use it to build an FQN
658
String JavaDoc sessionID = getSessionID(client, servers_[0]);
659       // Strip off the jvmRoute, if there is one
660
sessionID = stripJvmRoute(sessionID);
661       String JavaDoc sessionFqn = "/JSESSION/localhost" + warName_ + sessionID;
662       
663       sleepThread(DEFAULT_SLEEP);
664       
665       // Make connection to server 1 and get
666
setCookieDomainToThisServer(client, servers_[1]);
667       String JavaDoc attr1 = makeGet(client, baseURL1_ + getUrl);
668       
669       // check for replication first
670
assertEquals("attributes match", attr0, attr1);
671       
672       // sleep up to 11 secs to allow max idle to be reached
673
// and tomcat background process to run
674
// assuming that max idle in jboss-web.xml = 10 secs
675
// and tomcat background process is using the default = 10 secs
676
sleepThread(11000);
677       
678       RMIAdaptor[] adaptors = getAdaptors();
679       getLog().debug("Session in the cache = " + SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn));
680       //session is passivate should not exist in the cache
681
assertNull("Session is passivated therefore it is not in the cache...", SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn));
682       
683       // activate the session by requesting the attrribute
684
// Make connection to server 0 and get
685
setCookieDomainToThisServer(client, servers_[0]);
686       String JavaDoc attr2 = makeGet(client, baseURL0_ + getUrl);
687       
688       assertEquals("attribute match after activation", attr0, attr2);
689    }
690    
691    /**
692     * Tests the ability to passivate session when max number of active sessions reached
693     *
694     * @throws Exception
695     */

696    // FIXME disabled pending resolving JBAS-3571
697
public void XtestSessionPassivationWMaxActive() throws Exception JavaDoc
698    {
699       getLog().debug("Enter testSessionPassivationWMaxActive");
700
701       getLog().debug(setUrl + ":::::::" + getUrl);
702
703       RMIAdaptor[] adaptors = getAdaptors();
704       // Create an instance of HttpClient.
705
HttpClient client = new HttpClient();
706       // Set the session attribute first
707
makeGet(client, baseURL0_ +setUrl);
708       
709       // Get the Attribute set
710
String JavaDoc attr0 = makeGet(client, baseURL0_ +getUrl);
711       
712       // Find out the session id and use it to build an FQN
713
String JavaDoc sessionID = getSessionID(client, servers_[0]);
714       // Strip off the jvmRoute, if there is one
715
sessionID = stripJvmRoute(sessionID);
716       String JavaDoc sessionFqn = "/JSESSION/localhost" + warName_ + sessionID;
717       
718       sleepThread(DEFAULT_SLEEP);
719       
720       // Make connection to server 1 and get
721
setCookieDomainToThisServer(client, servers_[1]);
722       String JavaDoc attr1 = makeGet(client, baseURL1_ + getUrl);
723       
724       // check for replication first
725
assertEquals("attributes match", attr0, attr1);
726       
727       // Create 3 more sessions on server0
728
// assuming that max-active-sessions is set to 20 in jboss-web.xml
729
getLog().debug("current active sessions = " + SessionTestUtil.getSessionIds(adaptors[0], warFqn_));
730       int numberOfActiveSessions = SessionTestUtil.getSessionIds(adaptors[0], warFqn_).size();
731       HttpClient[] clients = new HttpClient[(20 - numberOfActiveSessions + 1)];
732       String JavaDoc[] attrs = new String JavaDoc[clients.length];
733       for (int i = 0; i < clients.length; i++)
734       {
735          clients[i] = new HttpClient();
736          makeGet(clients[i], baseURL0_ +setUrl);
737          attrs[i] = makeGet(clients[i], baseURL0_ + getUrl);
738          // Set cookie domain to server1
739
this.setCookieDomainToThisServer(clients[i], servers_[1]);
740       }
741       getLog().debug("to reach max active sessions we needed to create " + clients.length + " clients");
742       
743       getLog().debug("Session in the cache = " + SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn));
744       //session is passivate should not exist in the cache
745
assertNull("Session is passivated therefore it is not in the cache...", SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn));
746       
747       // activate the session by requesting the attrribute
748
// Make connection to server 0 and get
749
setCookieDomainToThisServer(client, servers_[0]);
750       String JavaDoc attr2 = makeGet(client, baseURL0_ + getUrl);
751       
752       assertEquals("attribute match after activation", attr0, attr2);
753    }
754 }
755
Popular Tags