Source Code Cross Referenced for WebSessionTestCase.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » cluster » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server JBoss 4.2.1 » testsuite » org.jboss.test.cluster.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.cluster.test;
023:
024:        import java.net.HttpURLConnection;
025:
026:        import junit.framework.Test;
027:
028:        import org.apache.commons.httpclient.Cookie;
029:        import org.apache.commons.httpclient.Header;
030:        import org.apache.commons.httpclient.HttpClient;
031:        import org.apache.commons.httpclient.HttpState;
032:        import org.apache.commons.httpclient.methods.GetMethod;
033:        import org.jboss.test.JBossClusteredTestCase;
034:
035:        /** Tests of http session replication
036:         *
037:         * @author  Scott.Stark@jboss.org
038:         * @version $Revision: 57211 $
039:         */
040:        public class WebSessionTestCase extends JBossClusteredTestCase {
041:            /** 
042:             * Standard number of ms to pause between http requests
043:             * to give session time to replicate
044:             */
045:            public static final long DEFAULT_SLEEP = BaseTest.DEFAULT_SLEEP;
046:
047:            public WebSessionTestCase(String name) {
048:                super (name);
049:            }
050:
051:            public static Test suite() throws Exception {
052:                Test t1 = getDeploySetup(WebSessionTestCase.class,
053:                        "dist-ss.war");
054:                return t1;
055:            }
056:
057:            /** This makes 2 requests to the jbosstest.cluster.node0 /dist-ss/StatefulSessionServlet
058:             * followed by 2 requests to the jbosstest.cluster.node1 /dist-ss/StatefulSessionServlet
059:             * using the same session ID to validate that the session is replicated
060:             * with the current value and updated correctly. The session AccessCount
061:             * value is returned via the X-AccessCount header which should be 4 after
062:             * the last request.
063:             * 
064:             * @throws Exception
065:             */
066:            public void testServletSessionFailover() throws Exception {
067:                getLog().debug("+++ testServletSessionFailover");
068:
069:                String[] servers = super .getServers();
070:                String[] httpURLs = super .getHttpURLs();
071:                // Access the StatefulSessionServlet of dist-ss.war@server0 twice
072:                String baseURL0 = httpURLs[0];
073:                HttpClient httpConn = new HttpClient();
074:                GetMethod servletGet0 = new GetMethod(baseURL0
075:                        + "/dist-ss/StatefulSessionServlet/");
076:                int responseCode = httpConn.executeMethod(servletGet0);
077:                assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
078:                Header accessCount = servletGet0
079:                        .getResponseHeader("X-AccessCount");
080:                int count = Integer.parseInt(accessCount.getValue());
081:                assertEquals("X-AccessCount ", 1, count);
082:                // Get the state for the JSESSIONID
083:                HttpState state = httpConn.getState();
084:                servletGet0 = new GetMethod(baseURL0
085:                        + "/dist-ss/StatefulSessionServlet/");
086:                responseCode = httpConn.executeMethod(servletGet0
087:                        .getHostConfiguration(), servletGet0, state);
088:                accessCount = servletGet0.getResponseHeader("X-AccessCount");
089:                count = Integer.parseInt(accessCount.getValue());
090:                assertEquals("X-AccessCount ", 2, count);
091:                // Get the JSESSIONID so we can reset the host
092:                Cookie[] cookies = state.getCookies();
093:                Cookie sessionID = null;
094:                for (int c = 0; c < cookies.length; c++) {
095:                    Cookie k = cookies[c];
096:                    if (k.getName().equalsIgnoreCase("JSESSIONID"))
097:                        sessionID = k;
098:                }
099:                log.info("Saw JSESSIONID=" + sessionID);
100:                // Reset the domain so that the cookie will be sent to server1
101:                sessionID.setDomain(servers[1]);
102:                state.addCookie(sessionID);
103:                _sleep(DEFAULT_SLEEP);
104:
105:                // Access the StatefulSessionServlet of dist-ss.war@server1 twice
106:                String baseURL1 = httpURLs[1];
107:                GetMethod servletGet1 = new GetMethod(baseURL1
108:                        + "/dist-ss/StatefulSessionServlet/");
109:                responseCode = httpConn.executeMethod(servletGet1
110:                        .getHostConfiguration(), servletGet1, state);
111:                assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
112:                accessCount = servletGet1.getResponseHeader("X-AccessCount");
113:                count = Integer.parseInt(accessCount.getValue());
114:                assertEquals("X-AccessCount ", 3, count);
115:                servletGet1 = new GetMethod(baseURL1
116:                        + "/dist-ss/StatefulSessionServlet/");
117:                responseCode = httpConn.executeMethod(servletGet1
118:                        .getHostConfiguration(), servletGet1, state);
119:                assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
120:                accessCount = servletGet1.getResponseHeader("X-AccessCount");
121:                count = Integer.parseInt(accessCount.getValue());
122:                assertEquals("X-AccessCount ", 4, count);
123:            }
124:
125:            /** This makes 4 requests alternating between the jbosstest.cluster.node0
126:             * /dist-ss/StatefulSessionServlet and jbosstest.cluster.node1 /dist-ss/StatefulSessionServlet
127:             * using the same session ID to validate that the session is replicated
128:             * with the current value and updated correctly. The session AccessCount
129:             * value is returned via the X-AccessCount header which should be 4 after
130:             * the last request.
131:             * 
132:             * Note: this test is not currently working since current http session
133:             * replication assumes sticky session. It does not support random load
134:             * balancing.
135:             * bwang.
136:             *
137:             * @throws Exception
138:             */
139:            public void testServletSessionLoadBalancing() throws Exception {
140:                getLog().debug("+++ testServletSessionLoadBalancing");
141:
142:                String[] servers = getServers();
143:                String[] httpURLs = super .getHttpURLs();
144:                String baseURL0 = httpURLs[0];
145:                String baseURL1 = baseURL0;
146:                if (servers.length > 1) {
147:                    baseURL1 = httpURLs[1];
148:                }
149:                // Access the StatefulSessionServlet of dist-ss.war@server0 twice
150:                HttpClient httpConn = new HttpClient();
151:                GetMethod servletGet0 = new GetMethod(baseURL0
152:                        + "/dist-ss/StatefulSessionServlet/");
153:                int responseCode = httpConn.executeMethod(servletGet0);
154:                assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
155:                Header accessCount = servletGet0
156:                        .getResponseHeader("X-AccessCount");
157:                int count = Integer.parseInt(accessCount.getValue());
158:                assertEquals("X-AccessCount ", 1, count);
159:                // Get the state for the JSESSIONID
160:                HttpState state = httpConn.getState();
161:                // Get the JSESSIONID so we can reset the host
162:                Cookie[] cookies = state.getCookies();
163:                Cookie sessionID = null;
164:                for (int c = 0; c < cookies.length; c++) {
165:                    Cookie k = cookies[c];
166:                    if (k.getName().equalsIgnoreCase("JSESSIONID"))
167:                        sessionID = k;
168:                }
169:                log.info("Saw JSESSIONID=" + sessionID);
170:                // Reset the domain so that the cookie will be sent to server1
171:                sessionID.setDomain(servers[1]);
172:                state.addCookie(sessionID);
173:                _sleep(DEFAULT_SLEEP);
174:                // Access the StatefulSessionServlet of dist-ss.war@server1 twice
175:                GetMethod servletGet1 = new GetMethod(baseURL1
176:                        + "/dist-ss/StatefulSessionServlet/");
177:                responseCode = httpConn.executeMethod(servletGet1
178:                        .getHostConfiguration(), servletGet1, state);
179:                assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
180:                accessCount = servletGet1.getResponseHeader("X-AccessCount");
181:                count = Integer.parseInt(accessCount.getValue());
182:                assertEquals("X-AccessCount ", 2, count);
183:
184:                _sleep(DEFAULT_SLEEP);
185:                // Reset the domain so that the cookie will be sent to server0
186:                sessionID.setDomain(servers[0]);
187:                state.addCookie(sessionID);
188:                servletGet0 = new GetMethod(baseURL0
189:                        + "/dist-ss/StatefulSessionServlet/");
190:                responseCode = httpConn.executeMethod(servletGet0
191:                        .getHostConfiguration(), servletGet0, state);
192:                accessCount = servletGet0.getResponseHeader("X-AccessCount");
193:                count = Integer.parseInt(accessCount.getValue());
194:                assertEquals("X-AccessCount ", 3, count);
195:
196:                _sleep(DEFAULT_SLEEP);
197:                // Reset the domain so that the cookie will be sent to server1
198:                sessionID.setDomain(servers[1]);
199:                state.addCookie(sessionID);
200:                servletGet1 = new GetMethod(baseURL1
201:                        + "/dist-ss/StatefulSessionServlet/");
202:                responseCode = httpConn.executeMethod(servletGet1
203:                        .getHostConfiguration(), servletGet1, state);
204:                assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
205:                accessCount = servletGet1.getResponseHeader("X-AccessCount");
206:                count = Integer.parseInt(accessCount.getValue());
207:                assertEquals("X-AccessCount ", 4, count);
208:            }
209:
210:            /**
211:             * Sleep for specified time
212:             *
213:             * @param msecs
214:             */
215:            protected void _sleep(long msecs) {
216:                try {
217:                    Thread.sleep(msecs);
218:                } catch (InterruptedException e) {
219:                    e.printStackTrace();
220:                }
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.