Author: jfrederic.clere(a)jboss.com
Date: 2008-09-05 05:04:28 -0400 (Fri, 05 Sep 2008)
New Revision: 1775
Added:
trunk/mod_cluster/test/java/Clients/
trunk/mod_cluster/test/java/Clients/JBWEB-117/
trunk/mod_cluster/test/java/Clients/JBWEB-117/JBWEB-117.xml
trunk/mod_cluster/test/java/Clients/JBWEB-117/build.xml
trunk/mod_cluster/test/java/Clients/JBWEB-117/metainf/
trunk/mod_cluster/test/java/Clients/JBWEB-117/metainf/context.xml
trunk/mod_cluster/test/java/Clients/JBWEB-117/src/
trunk/mod_cluster/test/java/Clients/JBWEB-117/src/JBWEB_117.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java
Modified:
trunk/mod_cluster/test/java/build.xml
trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/JBossWeb.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/Maintest.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestAddDel.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestBase.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestFailover.java
Log:
Add a test for JBWEB-117.
Added: trunk/mod_cluster/test/java/Clients/JBWEB-117/JBWEB-117.xml
===================================================================
--- trunk/mod_cluster/test/java/Clients/JBWEB-117/JBWEB-117.xml
(rev 0)
+++ trunk/mod_cluster/test/java/Clients/JBWEB-117/JBWEB-117.xml 2008-09-05 09:04:28 UTC
(rev 1775)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+
+ <display-name>JFC test application</display-name>
+ <description>
+ Welcome to JFC test application
+ </description>
+
+ <servlet>
+ <servlet-name>JBWEB_117</servlet-name>
+ <servlet-class>JBWEB_117</servlet-class>
+ <load-on-startup>6</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JBWEB_117</servlet-name>
+ <url-pattern>/JBWEB_117</url-pattern>
+ </servlet-mapping>
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>Security Tests</web-resource-name>
+ <url-pattern>/JBWEB_117</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>manager</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>Tomcat Manager Application</realm-name>
+ </login-config>
+
+ <security-role>
+ <description>
+ The role that is required to log in to the application.
+ </description>
+ <role-name>manager</role-name>
+ </security-role>
+
+</web-app>
Added: trunk/mod_cluster/test/java/Clients/JBWEB-117/build.xml
===================================================================
--- trunk/mod_cluster/test/java/Clients/JBWEB-117/build.xml (rev
0)
+++ trunk/mod_cluster/test/java/Clients/JBWEB-117/build.xml 2008-09-05 09:04:28 UTC (rev
1775)
@@ -0,0 +1,29 @@
+<project name="test application" default="build"
basedir=".">
+ <property file="${user.home}/build.properties"/>
+ <property file="build.properties"/>
+ <property file="../../build.properties.default"/>
+
+ <path id="tomcat.test.classpath">
+ <fileset dir="${jbosswebjar}/">
+ <include name="jbossweb.jar"/>
+ <include name="servlet-api.jar"/>
+ </fileset>
+ </path>
+
+ <target name="build" depends="compile">
+ <copy file="JBWEB-117.war" todir="../../output/classes" />
+ </target>
+ <target name="compile">
+ <mkdir dir="classes" />
+ <javac srcdir="./src" destdir="./classes" debug="on"
debuglevel="lines,vars,source">
+ <classpath refid="tomcat.test.classpath" />
+ </javac>
+
+ <war destfile="JBWEB-117.war" webxml="JBWEB-117.xml">
+ <classes dir="./classes" />
+ <metainf dir="./metainf">
+ <include name="**/context.xml"/>
+ </metainf>
+ </war>
+ </target>
+</project>
Added: trunk/mod_cluster/test/java/Clients/JBWEB-117/metainf/context.xml
===================================================================
--- trunk/mod_cluster/test/java/Clients/JBWEB-117/metainf/context.xml
(rev 0)
+++ trunk/mod_cluster/test/java/Clients/JBWEB-117/metainf/context.xml 2008-09-05 09:04:28
UTC (rev 1775)
@@ -0,0 +1,2 @@
+<Context privileged="true">
+</Context>
Added: trunk/mod_cluster/test/java/Clients/JBWEB-117/src/JBWEB_117.java
===================================================================
--- trunk/mod_cluster/test/java/Clients/JBWEB-117/src/JBWEB_117.java
(rev 0)
+++ trunk/mod_cluster/test/java/Clients/JBWEB-117/src/JBWEB_117.java 2008-09-05 09:04:28
UTC (rev 1775)
@@ -0,0 +1,92 @@
+/*
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $
+ */
+
+import java.io.*;
+import java.text.*;
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+
+
+/**
+ * TestServlet for JBWEB-117
+ */
+
+public class JBWEB_117 extends HttpServlet {
+
+ public void doGet(HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ response.setContentType("text/html");
+
+ PrintWriter out = response.getWriter();
+ out.println("<html>");
+ out.println("<body bgcolor=\"white\">");
+ out.println("<head>");
+
+ out.println("<title>" + "JBWEB_117" +
"</title>");
+ out.println("</head>");
+ out.println("<body>");
+
+
+ // Read the inputstream.
+ InputStream in = request.getInputStream();
+ if (in!=null) {
+ byte[] buff = new byte[128];
+ int i=0;
+ try {
+ int ret=0;
+ while (ret!=-1) {
+ ret = in.read(buff);
+ if (ret>0) {
+ i = i + ret;
+ String str = new String(buff,0,ret);
+ out.println(str);
+ }
+ }
+ } catch (IOException ex) {
+ ex.printStackTrace(out);
+ out.println("Merde bug velu!!!");
+ out.println("<P>");
+ }
+ out.println("Size of input: " + i);
+ } else {
+ out.println("No input");
+ }
+
+ // Read session and create it if needed...
+ HttpSession session = request.getSession(true);
+ }
+
+ public void doPost(HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException
+ {
+ doGet(request, response);
+ }
+
+}
Property changes on: trunk/mod_cluster/test/java/Clients/JBWEB-117/src/JBWEB_117.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/mod_cluster/test/java/build.xml
===================================================================
--- trunk/mod_cluster/test/java/build.xml 2008-09-03 19:37:13 UTC (rev 1774)
+++ trunk/mod_cluster/test/java/build.xml 2008-09-05 09:04:28 UTC (rev 1775)
@@ -75,6 +75,10 @@
<include name="org/jboss/mod_cluster/**" />
</javac>
+ <!-- Build the client (servlets) applications -->
+ <ant dir="Clients/JBWEB-117/" target="build">
+ </ant>
+
</target>
<target name="all" depends="compile">
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-09-03 19:37:13 UTC
(rev 1774)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-09-05 09:04:28 UTC
(rev 1775)
@@ -30,11 +30,16 @@
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
+
public class Client extends Thread {
private String jsessionid = null;
+
private String URL = null;
- private String command = null;
+ String post = null;
+ String user = null;
+ String pass = null;
+
private int nbtest = 10;
private int delay = 1000;
private boolean checkcookie = true;
@@ -51,13 +56,13 @@
*/
public static void main(String[] args) throws Exception
{
- if (args.length != 2)
+ if (args.length != 1)
{
System.err.println("missing command line arguments");
System.exit(1);
}
Client client = new Client();
- client.runit(args[0], args[1], 10, true);
+ client.runit(args[0], 10, true);
client.start();
try {
client.join();
@@ -65,11 +70,17 @@
ex.printStackTrace();
}
}
+ public int runit(String URL, int nbtest, boolean checkcookie, String post, String
user, String pass) throws Exception
+ {
+ this.post = post;
+ this.user = user;
+ this.pass = pass;
+ return runit(URL, nbtest, checkcookie);
+ }
- public int runit(String URL, String command, int nbtest, boolean checkcookie)
throws Exception
+ public int runit(String URL, int nbtest, boolean checkcookie) throws Exception
{
this.URL = URL;
- this.command = command;
this.checkcookie = checkcookie;
this.nbtest = nbtest;
@@ -80,25 +91,46 @@
{
HttpClient httpClient = new HttpClient();
- GetMethod pm = new GetMethod(URL);
+ PostMethod pm = null;
+ GetMethod gm = null;
+ HttpMethodBase bm = null;
+ if (post == null) {
+ gm = new GetMethod(URL);
+ bm = gm;
+ } else {
+ pm = new PostMethod(URL);
+ pm.setRequestEntity(new StringRequestEntity(post,
+
"application/x-www-form-urlencoded",
+ "UTF8"));
+ bm = pm;
+ }
+ if (user != null) {
+ Credentials cred = new UsernamePasswordCredentials(user,pass);
+
httpClient.getState().setCredentials(org.apache.commons.httpclient.auth.AuthScope.ANY,
cred);
+ }
System.out.println("Connecting to " + URL);
Integer connectionTimeout = 40000;
- pm.getParams().setParameter("http.socket.timeout",
connectionTimeout);
- pm.getParams().setParameter("http.connection.timeout",
connectionTimeout);
+ bm.getParams().setParameter("http.socket.timeout",
connectionTimeout);
+ bm.getParams().setParameter("http.connection.timeout",
connectionTimeout);
httpClient.getParams().setParameter("http.socket.timeout",
connectionTimeout);
httpClient.getParams().setParameter("http.connection.timeout",
connectionTimeout);
if (jsessionid != null) {
System.out.println("jsessionid: " + jsessionid);
- pm.setRequestHeader("Cookie", "JSESSIONID=" +
jsessionid);
+ bm.setRequestHeader("Cookie", "JSESSIONID=" +
jsessionid);
}
int httpResponseCode = 0;
try {
- httpResponseCode = httpClient.executeMethod(pm);
+ if (gm == null) {
+ httpResponseCode = httpClient.executeMethod(pm);
+ } else {
+ httpResponseCode = httpClient.executeMethod(gm);
+ }
+
System.out.println("response: " + httpResponseCode);
- System.out.println("response: " + pm.getStatusLine());
+ System.out.println("response: " + bm.getStatusLine());
if (httpResponseCode == 200) {
Cookie[] cookies = httpClient.getState().getCookies();
System.out.println( "Cookies: " + cookies);
@@ -110,13 +142,13 @@
if (jsessionid == null) {
jsessionid = cookie.getValue();
System.out.println("cookie first time:
" + jsessionid);
- pm.releaseConnection();
+ bm.releaseConnection();
return 0; // first time ok.
} else {
System.out.println("cookie second time:
" + jsessionid);
if (jsessionid.compareTo(cookie.getValue()) == 0)
{
System.out.println("cookie ok");
- pm.releaseConnection();
+ bm.releaseConnection();
return 0;
}
}
@@ -124,9 +156,9 @@
}
} else {
// Look in the response to make sure that there is a cookie.
- int len = (int) pm.getResponseContentLength();
- if (pm.getResponseBodyAsString(len).indexOf(jsessionid) !=
-1) {
- pm.releaseConnection();
+ int len = (int) bm.getResponseContentLength();
+ if (bm.getResponseBodyAsString(len).indexOf(jsessionid) !=
-1) {
+ bm.releaseConnection();
return 0;
}
System.out.println("No cookies");
@@ -135,13 +167,13 @@
System.out.println("Not 200");
success = false;
}
- // System.out.println("response:\n" +
pm.getResponseBodyAsString(len));
+ // System.out.println("response:\n" +
bm.getResponseBodyAsString(len));
} catch(HttpException e) {
e.printStackTrace();
success = false;
}
System.out.println("DONE: " + httpResponseCode);
- pm.releaseConnection();
+ bm.releaseConnection();
return httpResponseCode;
}
public void run() {
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/JBossWeb.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/JBossWeb.java 2008-09-03 19:37:13
UTC (rev 1774)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/JBossWeb.java 2008-09-05 09:04:28
UTC (rev 1775)
@@ -46,6 +46,7 @@
import org.apache.tomcat.util.IntrospectionUtils;
import org.apache.catalina.realm.MemoryRealm;
import org.apache.catalina.core.*;
+import org.apache.catalina.startup.HostConfig;
import org.jboss.web.cluster.ClusterListener;
@@ -97,21 +98,43 @@
//Create Host
Host baseHost = createHost( host, appBase);
+ baseHost.setBackgroundProcessorDelay(10);
+ StandardHost stdhost = (StandardHost)baseHost;
+ HostConfig hostConfig = new HostConfig();
+ stdhost.addLifecycleListener(hostConfig);
baseEngine.addChild( baseHost );
//Create default context
Context rootContext = createContext("/",docBase);
rootContext.setIgnoreAnnotations(true);
+ rootContext.setPrivileged(true);
baseHost.addChild( rootContext );
addEngine( baseEngine );
baseEngine.setService(this);
}
+
+ public void addWAR(String file, String route) throws IOException {
+ File fd = new File ( route + "/" + route + "/webapps");
+ fd.mkdirs();
+
+ String sep = System.getProperty("file.separator");
+ String [] paths = file.split(sep);
+
+ fd = new File (route + "/" + route + "/webapps",
paths[paths.length-1]);
+ File fdin = new File (file);
+
+ copyFile(fdin, fd);
+ }
+
public void addConnector(int port) throws IOException {
+ addConnector(port, "http");
+ }
+
+ public void addConnector(int port, String scheme) throws IOException {
Connector connector = createConnector( (java.net.InetAddress) null,
- port, "http");
- // port, "ajp");
+ port, scheme);
// Look in StandardService to see why it works ;-)
addConnector( connector );
@@ -176,7 +199,7 @@
// Wait for it.
try {
- client.runit("http://localhost:7779/ROOT/MyCount", "cmd",
10, true);
+ client.runit("http://localhost:7779/ROOT/MyCount", 10, true);
client.start();
client.join();
} catch (Exception ex) {
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/Maintest.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/Maintest.java 2008-09-03 19:37:13
UTC (rev 1774)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Maintest.java 2008-09-05 09:04:28
UTC (rev 1775)
@@ -49,12 +49,16 @@
public static Test suite() {
TestSuite suite = new TestSuite();
server = (StandardServer) ServerFactory.getServer();
+/*
suite.addTest(new TestSuite(TestAddDel.class));
System.gc();
suite.addTest(new TestSuite(TestBase.class));
System.gc();
suite.addTest(new TestSuite(TestFailover.class));
System.gc();
+ */
+ suite.addTest(new TestSuite(TestJBWEB_117.class));
+ System.gc();
return suite;
}
static StandardServer getServer() {
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestAddDel.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestAddDel.java 2008-09-03 19:37:13
UTC (rev 1774)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestAddDel.java 2008-09-05 09:04:28
UTC (rev 1775)
@@ -86,7 +86,7 @@
// Wait until httpd as received the nodes information.
try {
- Thread.sleep(30000);
+ Thread.sleep(40000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
@@ -131,12 +131,15 @@
nodes.add(nodeinfo);
}
}
- } else
+ } else {
+ System.out.println("getProxyInfo failed");
clienterror = true;
+ }
// Check the nodes.
if (!clienterror) {
if (!NodeInfo.check(nodes, nodenames))
+ System.out.println("getProxyInfo nodes incorrect");
clienterror = true;
}
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestBase.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestBase.java 2008-09-03 19:37:13
UTC (rev 1774)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestBase.java 2008-09-05 09:04:28
UTC (rev 1775)
@@ -83,7 +83,7 @@
// Wait until httpd as received the nodes information.
try {
- Thread.sleep(20000);
+ Thread.sleep(30000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
@@ -93,7 +93,7 @@
// Wait for it.
try {
- client.runit("http://localhost:7779/ROOT/MyCount", "cmd",
10, true);
+ client.runit("http://localhost:7779/ROOT/MyCount", 10, true);
client.start();
client.join();
} catch (Exception ex) {
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestFailover.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestFailover.java 2008-09-03
19:37:13 UTC (rev 1774)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestFailover.java 2008-09-05
09:04:28 UTC (rev 1775)
@@ -89,7 +89,7 @@
// Wait for it.
try {
- if (client.runit("http://localhost:7779/ROOT/MyCount",
"cmd", 10, true) != 0)
+ if (client.runit("http://localhost:7779/ROOT/MyCount", 10, true) !=
0)
clienterror = true;
} catch (Exception ex) {
ex.printStackTrace();
Added: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java
(rev 0)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java 2008-09-05
09:04:28 UTC (rev 1775)
@@ -0,0 +1,129 @@
+/*
+ * mod_cluster
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision$
+ */
+
+package org.jboss.mod_cluster;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.catalina.Engine;
+import org.apache.catalina.ServerFactory;
+import org.apache.catalina.Service;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardServer;
+
+import org.jboss.web.cluster.ClusterListener;
+
+public class TestJBWEB_117 extends TestCase {
+
+ /* Test for JBWEB-117 */
+ public void testJBWEB_117() {
+
+ boolean clienterror = false;
+ StandardServer server = Maintest.getServer();
+ JBossWeb service = null;
+ ClusterListener cluster = null;
+ try {
+ // server = (StandardServer) ServerFactory.getServer();
+
+ service = new JBossWeb("node1", "localhost");
+ service.addConnector(8009, "ajp");
+ service.addWAR("JBWEB-117.war", "node1");
+ server.addService(service);
+
+ cluster = new ClusterListener();
+ cluster.setAdvertiseGroupAddress("232.0.0.2");
+ cluster.setAdvertisePort(23364);
+ cluster.setSsl(false);
+ // SSL ?
+ server.addLifecycleListener((LifecycleListener) cluster);
+
+ // Debug Stuff
+ Maintest.listServices();
+
+ } catch(IOException ex) {
+ ex.printStackTrace();
+ fail("can't start service");
+ }
+
+ // start the server thread.
+ ServerThread wait = new ServerThread(3000, server);
+ wait.start();
+
+ // Wait until httpd as received the nodes information.
+ try {
+ Thread.sleep(40000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+
+ // Start the client and wait for it.
+ Client client = new Client();
+
+ // Wait for it.
+ String data = "a";
+ for (int i=0; i<517; i++)
+ data = data.concat("a");
+ int ret = 0;
+ try {
+ ret = client.runit("http://localhost:7779/JBWEB-117/JBWEB_117", 1,
true, data, "manager" , "manager");
+ client.start();
+ client.join();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ clienterror = true;
+ }
+
+ // Stop the jboss and remove the services.
+ try {
+ wait.stopit();
+ wait.join();
+
+ server.removeService(service);
+ server.removeLifecycleListener(cluster);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ fail("can't stop service");
+ }
+ if (clienterror)
+ fail("Client error");
+
+ if (ret != 401)
+ fail("Should get 401 code");
+
+ // Wait until httpd as received the stop messages.
+ System.gc();
+ try {
+ Thread.sleep(20000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ }
+}