You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by se...@apache.org on 2001/05/30 01:05:58 UTC
cvs commit: jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/test TestAll.java TestAjp13.java
seguin 01/05/29 16:05:58
Modified: jk build.properties.sample build.xml
jk/src/java/org/apache/ajp/test TestAjp13.java
Added: jk/src/java/org/apache/ajp/test TestAll.java
Log:
the beginnings of some junit testing
Revision Changes Path
1.2 +17 -1 jakarta-tomcat-connectors/jk/build.properties.sample
Index: build.properties.sample
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/build.properties.sample,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- build.properties.sample 2001/05/29 05:47:29 1.1
+++ build.properties.sample 2001/05/29 23:05:52 1.2
@@ -2,9 +2,25 @@
# sample build.properties for ajp connector.
# edit to taste...
#
-# $Id: build.properties.sample,v 1.1 2001/05/29 05:47:29 seguin Exp $
+# $Id: build.properties.sample,v 1.2 2001/05/29 23:05:52 seguin Exp $
#
+#
+# tomcat 4 internals
+#
catalina.jar = ../../jakarta-tomcat-4.0/build/server/lib/catalina.jar
+
+#
+# servlet api 2.3
+#
servlet.jar = ../../jakarta-servletapi-4/dist/lib/servlet.jar
+
+#
+# utils.
+#
tomcat-util.jar = ../util/build/lib/tomcat-util.jar
+
+#
+# junit jar
+#
+junit.jar=f:/dev/junit/junit.jar
1.6 +40 -1 jakarta-tomcat-connectors/jk/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/build.xml,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- build.xml 2001/05/29 05:47:15 1.5
+++ build.xml 2001/05/29 23:05:53 1.6
@@ -6,6 +6,26 @@
<property name="jk.build" value="${basedir}/build"/>
+ <!-- Should all tests fail if one does? -->
+ <property name="test.failonerror" value="true"/>
+
+ <!-- The test runner to execute -->
+ <property name="test.runner" value="junit.textui.TestRunner"/>
+ <property name="test.entry" value="org.apache.ajp.test.TestAll"/>
+
+ <path id="test.classpath">
+ <pathelement location="${jk.build}/classes"/>
+ <pathelement location="${tomcat-util.jar}"/>
+ <pathelement location="${junit.jar}"/>
+ </path>
+
+ <path id="build-main.classpath">
+ <pathelement location="${tomcat-util.jar}"/>
+ <pathelement location="${catalina.jar}"/>
+ <pathelement location="${servlet.jar}"/>
+ <pathelement location="${junit.jar}"/>
+ </path>
+
<target name="build-prepare">
<mkdir dir="${jk.build}"/>
<mkdir dir="${jk.build}/classes"/>
@@ -16,13 +36,13 @@
<javac srcdir="src/java"
destdir="${jk.build}/classes"
- classpath="${tomcat-util.jar}:${catalina.jar}:${servlet.jar}"
deprecation="on"
debug="on"
optimize="off"
verbose="off"
excludes="**/CVS/**">
<exclude name="org/apache/ajp/tomcat4/**" if="tomcat4.skip"/>
+ <classpath refid="build-main.classpath"/>
</javac>
<!-- Copy static resource files -->
@@ -36,6 +56,25 @@
basedir="${jk.build}/classes"
/>
</target>
+
+ <target name="test" if="test.entry" depends="build-main"
+ description="Run all unit test cases">
+ <!--
+ <junit printsummary="yes" fork="on" haltonfailure="yes">
+ <formatter type="plain" usefile="false"/>
+ <test name="${test.entry}"/>
+ <classpath refid="test.classpath"/>
+ </junit>
+ -->
+
+ <java classname="${test.runner}" fork="yes"
+ failonerror="${test.failonerror}">
+ <!--<jvmarg value="${java.protocol.handler.pkgs}"/>-->
+ <arg value="${test.entry}"/>
+ <classpath refid="test.classpath"/>
+ </java>
+ </target>
+
<!-- ================ BUILD: Create Jk Javadocs =================== -->
<target name="javadoc">
1.3 +227 -57 jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/test/TestAjp13.java
Index: TestAjp13.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/test/TestAjp13.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestAjp13.java 2001/05/17 23:55:33 1.2
+++ TestAjp13.java 2001/05/29 23:05:57 1.3
@@ -7,79 +7,249 @@
import java.net.*;
import java.util.*;
-public class TestAjp13 {
+// junit
+import junit.framework.*;
- public static void main(String[] args) throws Exception {
- ServerSocket server = new ServerSocket(8009);
- System.out.println("TestAjp13 running...");
- Socket socket = server.accept();
- Ajp13 ajp13 = new Ajp13();
- MimeHeaders headers = new MimeHeaders();
- AjpRequest request = new AjpRequest();
- ajp13.setSocket(socket);
+public class TestAjp13 extends TestCase {
+
+ Ajp13Server server = null;
+
+ public TestAjp13(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestAjp13.class);
+ }
+
+ protected void my_setUp() {
+ println("setup...");
+
+ server = new Ajp13Server();
+ server.start();
+ }
+
+ protected void my_tearDown() {
+ println("tear down...");
+
+ server.shutdown();
+ }
+
+ public void test1() throws Exception {
+ System.out.println("running test1");
+
+ my_setUp();
+
+ Socket s = new Socket("localhost", 8009);
+
+ Ajp13Packet p = new Ajp13Packet(Ajp13.MAX_PACKET_SIZE);
+ p.appendInt(0x1234);
+ p.appendInt(0);
+ p.setByteOff(4);
+ p.appendByte(Ajp13.JK_AJP13_FORWARD_REQUEST);
+ p.appendByte((byte)2);
+ p.appendString("http");
+ p.appendString("/test_uri");
+ p.appendString("remote_addr");
+ p.appendString("remote_host");
+ p.appendString("server_name");
+ p.appendInt(80);
+ p.appendBool(false);
+ p.appendInt(3);
+ p.appendString("my header");
+ p.appendString("my header value");
+ p.appendInt((0xA0 << 8) + Ajp13.SC_REQ_AUTHORIZATION);
+ p.appendString("some auth string");
+ p.appendInt((0xA0 << 8) + Ajp13.SC_REQ_USER_AGENT);
+ p.appendString("TestAjp13 User Agent");
+ p.appendByte(Ajp13.SC_A_ARE_DONE);
+
+ int len = p.getByteOff() - 4;
+ p.setByteOff(2);
+ p.appendInt(len);
+
+ OutputStream os = s.getOutputStream();
+ os.write(p.getBuff(), 0, len + 4);
+
+ InputStream is = s.getInputStream();
+
+ System.out.println("decoding response...");
+
+ boolean done = false;
+ while (!done) {
+ int b1, b2;
+ // read a packet
+
+ // first 2 bytes should be AB
+ b1 = is.read();
+ assertTrue("byte 1 was " + (char)b1, b1 == (int)'A');
+ b2 = is.read();
+ assertTrue("byte 2 was " + (char)b2, b2 == (int)'B');
- boolean moreRequests = true;
- while (moreRequests) {
+ System.out.println("b1 = " + (char)b1 + "; b2 = " + (char)b2);
- int status = 0;
- try {
- status = ajp13.receiveNextRequest(request);
- } catch (IOException e) {
- System.out.println("process: ajp13.receiveNextRequest -> " + e);
- }
+ // next is length
+ b1 = is.read();
+ b1 &= 0xFF;
+ b2 = is.read();
+ b2 &= 0xFF;
- if( status==-2) {
- // special case - shutdown
- // XXX need better communication, refactor it
-// if( !doShutdown(socket.getLocalAddress(),
-// socket.getInetAddress())) {
-// moreRequests = false;
-// continue;
-// }
- break;
+ int l = (b1 << 8) + b2;
+
+ System.out.println("length = " + l);
+
+ // now get data
+ byte[] buf = new byte[l];
+ int n = 0;
+ int off = 0;
+ int total = 0;
+ while ((n = is.read(buf, off, l - off)) != -1 && (l - off != 0)) {
+ total += n;
+ off += n;
}
+
+ System.out.println("read " + total);
+
+ assertTrue("total read was " + total +
+ ", should have been " + l,
+ total == l);
+
- if( status != 200 )
+
+ int code = (int)buf[0];
+
+ switch (code) {
+ case 3:
+ System.out.println("AJP13_SEND_BODY_CHUNK ");
+ break;
+ case 4:
+ System.out.println("AJP13_SEND_HEADERS ");
+ break;
+ case 5:
+ System.out.println("AJP13_END_RESPONSE ");
+ done = true;
+ break;
+ case 6:
+ System.out.println("AJP13_GET_BODY_CHUNK ");
break;
+ default:
+ assertTrue("invalid prefix code: " + code, false);
+ break;
+ }
+ }
- System.out.println(request);
+ System.out.println("shutting down socket...");
+ s.shutdownOutput();
+ s.shutdownInput();
+ s.close();
+
+ System.out.println("shutting down server...");
+ my_tearDown();
+ }
+
+ protected static void println(String msg) {
+ System.out.println("[TestAjp13] " + msg);
+ }
- String message =
- "<html><body><pre>" +
- "hello from ajp13: " +
- System.getProperty("line.separator") +
- request.toString() +
- "</pre></body></html>";
-
- headers.addValue("content-type").setString( "text/html");
- headers.addValue("content-length").setInt(message.length());
- headers.addValue("my-header").setString( "my value");
- ajp13.sendHeaders(200, headers);
+ public static void main(String[] args) throws Exception {
+ }
+}
- byte[] b = message.getBytes();
- ajp13.doWrite(b, 0, b.length);
- ajp13.finish();
+class Ajp13Server extends Thread {
- request.recycle();
- headers.recycle();
- }
+ boolean shutdown = false;
+ void shutdown() {
+ this.shutdown = true;
+
+// try {
+ this.interrupt();
+// } catch (InterruptedException e) {
+// throw new RuntimeException(e.toString());
+// }
+ }
+
+ public void run() {
try {
- ajp13.close();
- } catch (IOException e) {
- System.out.println("process: ajp13.close ->" + e);
- }
-
- try {
- socket.close();
- } catch (IOException e) {
- System.out.println("process: socket.close ->" + e);
- }
- socket = null;
+ ServerSocket server = new ServerSocket(8009);
+ System.out.println("Ajp13Server running...");
+ Socket socket = server.accept();
+ Ajp13 ajp13 = new Ajp13();
+ MimeHeaders headers = new MimeHeaders();
+ AjpRequest request = new AjpRequest();
+ ajp13.setSocket(socket);
+
+ boolean moreRequests = true;
+ while (moreRequests && !shutdown) {
+
+ int status = 0;
+ try {
+ status = ajp13.receiveNextRequest(request);
+ } catch (IOException e) {
+ if (shutdown) {
+ System.out.println("Ajp13Server told to shutdown");
+ break;
+ }
+ System.out.println("process: ajp13.receiveNextRequest -> " + e);
+ }
+
+ if( status==-2) {
+ // special case - shutdown
+ // XXX need better communication, refactor it
+ // if( !doShutdown(socket.getLocalAddress(),
+ // socket.getInetAddress())) {
+ // moreRequests = false;
+ // continue;
+ // }
+ break;
+ }
+
+ if( status != 200 )
+ break;
- System.out.println("process: done");
+ System.out.println(request);
+
+ String message =
+ "<html><body><pre>" +
+ "hello from ajp13: " +
+ System.getProperty("line.separator") +
+ request.toString() +
+ "</pre></body></html>";
+
+ headers.addValue("content-type").setString( "text/html");
+ headers.addValue("content-length").setInt(message.length());
+ headers.addValue("my-header").setString( "my value");
+ ajp13.sendHeaders(200, headers);
+
+ byte[] b = message.getBytes();
+ ajp13.doWrite(b, 0, b.length);
+
+ ajp13.finish();
+
+ request.recycle();
+ headers.recycle();
+ }
+ try {
+ ajp13.close();
+ } catch (IOException e) {
+ System.out.println("process: ajp13.close ->" + e);
+ }
+
+ try {
+ socket.close();
+ } catch (IOException e) {
+ System.out.println("process: socket.close ->" + e);
+ }
+ socket = null;
+
+ System.out.println("process: done");
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.toString());
+ }
}
}
1.1 jakarta-tomcat-connectors/jk/src/java/org/apache/ajp/test/TestAll.java
Index: TestAll.java
===================================================================
package org.apache.ajp.test;
// junit
import junit.framework.*;
// ajp
import org.apache.ajp.*;
public class TestAll extends TestCase {
public TestAll(String testName) {
super(testName);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(TestAjp13.suite());
return suite;
}
public static void main(String args[]) {
String[] testCaseName = { TestAll.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
}