Author: jfrederic.clere(a)jboss.com
Date: 2008-09-11 10:30:52 -0400 (Thu, 11 Sep 2008)
New Revision: 1799
Added:
trunk/mod_cluster/test/java/README.txt
trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_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/Maintest.java
trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java
Log:
Add some more test and allow a single test by:
ant one -Dtest=test
Added: trunk/mod_cluster/test/java/README.txt
===================================================================
--- trunk/mod_cluster/test/java/README.txt (rev 0)
+++ trunk/mod_cluster/test/java/README.txt 2008-09-11 14:30:52 UTC (rev 1799)
@@ -0,0 +1,7 @@
+The test directory contains to kind of tests:
+1 - small test using httpclient that allows to read directly information from httpd
(TestHttpClient).
+2 - small test suite:
+ to run it:
+ ant
+ to run a single test:
+ ant one -Dtest=test where test is for example Test_Chunk_JBWEB_117
Modified: trunk/mod_cluster/test/java/build.xml
===================================================================
--- trunk/mod_cluster/test/java/build.xml 2008-09-11 12:06:47 UTC (rev 1798)
+++ trunk/mod_cluster/test/java/build.xml 2008-09-11 14:30:52 UTC (rev 1799)
@@ -89,4 +89,13 @@
</java>
</target>
+ <target name="one" depends="compile">
+ <copy file="conf/web.xml" todir="${test.classes}/conf"/>
+ <java dir="${test.classes}" classname="${test.runner}"
fork="yes" failonerror="${test.failonerror}">
+ <arg value="org.jboss.mod_cluster.Maintest"/>
+ <jvmarg value="-Dtest=${test}"/>
+ <classpath refid="tomcat.test.classpath"/>
+ </java>
+
+ </target>
</project>
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-11 12:06:47 UTC
(rev 1798)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Client.java 2008-09-11 14:30:52 UTC
(rev 1799)
@@ -27,6 +27,10 @@
package org.jboss.mod_cluster;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
@@ -39,6 +43,7 @@
String post = null;
String user = null;
String pass = null;
+ InputStream fd = null;
private int nbtest = 10;
private int delay = 1000;
@@ -70,6 +75,32 @@
ex.printStackTrace();
}
}
+
+ /**
+ * Run the first test.
+ *
+ * @param URL URL to connect to.
+ * @param nbtest number of test the thread will run (not counting this one).
+ * @param checkcookie check that the jsessionid cookie is not changing during
the test.
+ * @param post data to send in the POST.
+ * @param user username of the BASIC authentication.
+ * @param pass password of the usr for the BASIC authentication.
+ * @param fd file containing the data to send chuncked in the POST (post content
is ignored in this case).
+ *
+ * @return The http code returned by the server.
+ *
+ * @throws IOException for any failures.
+ */
+ public int runit(String URL, int nbtest, boolean checkcookie, String post, String
user, String pass, InputStream fd) throws Exception
+ {
+ this.fd = fd;
+ return runit(URL, nbtest, checkcookie, post, user, pass);
+ }
+ public int runit(String URL, int nbtest, boolean checkcookie, String post, String
user, String pass, File fd) throws Exception
+ {
+ this.fd = new FileInputStream(fd);
+ return runit(URL, nbtest, checkcookie, post, user, pass);
+ }
public int runit(String URL, int nbtest, boolean checkcookie, String post, String
user, String pass) throws Exception
{
this.post = post;
@@ -94,16 +125,22 @@
PostMethod pm = null;
GetMethod gm = null;
HttpMethodBase bm = null;
- if (post == null) {
- gm = new GetMethod(URL);
- bm = gm;
- } else {
+ if (fd != null) {
pm = new PostMethod(URL);
+ pm.setRequestBody(fd);
+ pm.setHttp11(true);
+ pm.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
+ bm = pm;
+ } else if (post != null) {
+ pm = new PostMethod(URL);
pm.setRequestEntity(new StringRequestEntity(post,
"application/x-www-form-urlencoded",
"UTF8"));
bm = pm;
- }
+ } else {
+ gm = new GetMethod(URL);
+ bm = gm;
+ }
if (user != null) {
Credentials cred = new UsernamePasswordCredentials(user,pass);
httpClient.getState().setCredentials(org.apache.commons.httpclient.auth.AuthScope.ANY,
cred);
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-11 12:06:47
UTC (rev 1798)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Maintest.java 2008-09-11 14:30:52
UTC (rev 1799)
@@ -49,16 +49,32 @@
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();
+
+ // Read the -Dtest="value".
+ String test = System.getProperty("test");
+ if (test != null) {
+ System.out.println("Running single test: " + test);
+ try {
+ Class clazz = Class.forName("org.jboss.mod_cluster." + test);
+ suite.addTest(new TestSuite(clazz));
+ } catch (ClassNotFoundException ex) {
+ System.out.println("Running single test: " + test + "Not
found");
+ return null;
+ }
+ } else {
+ 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();
+ suite.addTest(new TestSuite(Test_Native_JBWEB_117.class));
+ System.gc();
+ suite.addTest(new TestSuite(Test_Chunk_JBWEB_117.class));
+ System.gc();
+ }
return suite;
}
static StandardServer getServer() {
Modified: trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java 2008-09-11
12:06:47 UTC (rev 1798)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/TestJBWEB_117.java 2008-09-11
14:30:52 UTC (rev 1799)
@@ -28,6 +28,10 @@
package org.jboss.mod_cluster;
import java.io.IOException;
+import java.io.File;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.ByteArrayInputStream;
import junit.framework.TestCase;
@@ -47,6 +51,20 @@
/* Test for JBWEB-117 */
public void testJBWEB_117() {
+ testJBWEB_117(false, (File) null);
+ }
+ public void testJBWEB_117(boolean nat, File fd) {
+ InputStream in = null;
+ if (fd != null)
+ try {
+ in = new FileInputStream(fd);
+ } catch(IOException ex) {
+ ex.printStackTrace();
+ fail("can't start service");
+ }
+ testJBWEB_117(nat, in);
+ }
+ public void testJBWEB_117(boolean nat, InputStream fd) {
boolean clienterror = false;
StandardServer server = Maintest.getServer();
@@ -55,8 +73,12 @@
try {
// server = (StandardServer) ServerFactory.getServer();
- service = new JBossWeb("node1", "localhost", true);
- service.addConnector(8009,
"org.apache.coyote.ajp.AjpAprProtocol");
+ service = new JBossWeb("node1", "localhost", nat);
+ if (nat)
+ service.addConnector(8009,
"org.apache.coyote.ajp.AjpAprProtocol");
+ else
+ service.addConnector(8009, "ajp");
+
service.addWAR("JBWEB-117.war", "node1");
server.addService(service);
@@ -68,8 +90,10 @@
server.addLifecycleListener((LifecycleListener) cluster);
// Add AprLifecycleListener.
- AprLifecycleListener listener = new AprLifecycleListener();
- server.addLifecycleListener((LifecycleListener) listener);
+ if (nat) {
+ AprLifecycleListener listener = new AprLifecycleListener();
+ server.addLifecycleListener((LifecycleListener) listener);
+ }
// Debug Stuff
Maintest.listServices();
@@ -99,7 +123,7 @@
data = data.concat("a");
int ret = 0;
try {
- ret = client.runit("http://localhost:7779/JBWEB-117/JBWEB_117", 1,
true, data, "manager" , "manager");
+ ret = client.runit("http://localhost:7779/JBWEB-117/JBWEB_117", 1,
true, data, "manager" , "manager", fd);
client.start();
client.join();
} catch (Exception ex) {
Added: trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java
===================================================================
--- trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java
(rev 0)
+++ trunk/mod_cluster/test/java/org/jboss/mod_cluster/Test_Chunk_JBWEB_117.java 2008-09-11
14:30:52 UTC (rev 1799)
@@ -0,0 +1,59 @@
+/*
+ * 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 java.io.File;
+import java.io.FileOutputStream;
+import java.io.ByteArrayInputStream;
+
+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;
+
+import org.apache.catalina.core.AprLifecycleListener;
+
+public class Test_Chunk_JBWEB_117 extends TestJBWEB_117 {
+
+ /* Test for JBWEB-117 */
+ public void test_Chunk_JBWEB_117() {
+ byte [] buf = new byte[1024*6];
+ for (int i=0; i<buf.length;i++)
+ buf[i] = 'a';
+ ByteArrayInputStream fd = new ByteArrayInputStream(buf);
+ super.testJBWEB_117(false, fd);
+ }
+}