You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2008/06/14 17:56:44 UTC
svn commit: r667823 - in /tomcat/sandbox/tomcat-lite/test/org/apache/coyote:
./ adapters/ adapters/StaticAdapterTest.java client/
client/HttpProcessorTest.java client/HttpProcessorThreadedTest.java
Author: costin
Date: Sat Jun 14 08:56:43 2008
New Revision: 667823
URL: http://svn.apache.org/viewvc?rev=667823&view=rev
Log:
More tests
Added:
tomcat/sandbox/tomcat-lite/test/org/apache/coyote/
tomcat/sandbox/tomcat-lite/test/org/apache/coyote/adapters/
tomcat/sandbox/tomcat-lite/test/org/apache/coyote/adapters/StaticAdapterTest.java (with props)
tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/
tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorTest.java (with props)
tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorThreadedTest.java (with props)
Added: tomcat/sandbox/tomcat-lite/test/org/apache/coyote/adapters/StaticAdapterTest.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/test/org/apache/coyote/adapters/StaticAdapterTest.java?rev=667823&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/test/org/apache/coyote/adapters/StaticAdapterTest.java (added)
+++ tomcat/sandbox/tomcat-lite/test/org/apache/coyote/adapters/StaticAdapterTest.java Sat Jun 14 08:56:43 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.adapters;
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.test.CoyoteTestHelper;
+
+public class StaticAdapterTest extends TestCase {
+
+ public void testStaticAdapter() throws Exception {
+ CoyoteServer server = CoyoteTestHelper.getTestServer(8001);
+
+ assertEquals("Hello world",
+ CoyoteTestHelper.getUrl("http://localhost:8001/hello").toString());
+ assertEquals("Hello world2",
+ CoyoteTestHelper.getUrl("http://localhost:8001/2nd").toString());
+
+ server.stop();
+ }
+
+}
Propchange: tomcat/sandbox/tomcat-lite/test/org/apache/coyote/adapters/StaticAdapterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorTest.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorTest.java?rev=667823&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorTest.java (added)
+++ tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorTest.java Sat Jun 14 08:56:43 2008
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.client;
+
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.coyote.adapters.CoyoteServer;
+import org.apache.tomcat.test.CoyoteTestHelper;
+import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.buf.MessageBytes;
+
+public class HttpProcessorTest extends TestCase {
+ CoyoteServer staticMain = CoyoteTestHelper.getTestServer(8802);
+ AsyncHttp acstate;
+ BlockingHttp cstate;
+ ByteChunk bodyRecvBuffer = new ByteChunk(1024);
+ int to = 10000;
+
+ public void setUp() {
+ acstate = AsyncHttpPool.getDefault().get(); // client);
+ cstate = acstate.getBlockingHttp();
+ bodyRecvBuffer.recycle();
+ }
+
+ public void tearDown() throws Exception {
+ acstate.release(); // async
+ }
+
+ /**
+ * Want to run the same tests few times.
+ */
+ public static TestSuite suite() {
+ TestSuite s = new TestSuite();
+ for (int i = 0; i < 5; i++) {
+ s.addTestSuite(HttpProcessorTest.class);
+ }
+ return s;
+ }
+
+ public void testSimpleRequest() throws Exception {
+ acstate.getRequest().requestURI().setString("/hello");
+ acstate.connect("localhost", 8802);
+ cstate.readAll(bodyRecvBuffer, to);
+ assertEquals("Hello world", bodyRecvBuffer.toString());
+ }
+
+ public void testSimpleChunkedRequest() throws Exception {
+
+ acstate.getRequest().requestURI().setString("/chunked/foo");
+ acstate.connect("localhost", 8802);
+ cstate.readAll(bodyRecvBuffer, to);
+ assertTrue(bodyRecvBuffer.toString().indexOf("AAA") >= 0);
+ }
+
+ // Check waitResponseHead()
+ public void testRequestHead() throws Exception {
+ acstate.getRequest().requestURI().setString("/echo/foo");
+
+ // Send the request, wait response
+ acstate.connect("localhost", 8802);
+
+ // cstate.waitResponseHead(10000);
+// dumpHead(cstate);
+
+ cstate.readAll(bodyRecvBuffer, to);
+// System.err.println("DATA\n" + cstate.output.toString() + "\n----");
+
+ }
+
+ private void dumpHead(AsyncHttp cstate) throws IOException {
+ ByteChunk resHead = new ByteChunk();
+ cstate.serializeResponse(cstate.getResponse(),
+ resHead);
+ System.err.println("RECEIVED HEAD:\n" + resHead + "\n----");
+ }
+
+ public void testNotFound() throws Exception {
+ for (int i = 0; i < 10; i++) {
+ testSimpleRequest();
+ tearDown();
+ setUp();
+
+ notFound();
+ tearDown();
+ setUp();
+
+ testSimpleRequest();
+ tearDown();
+ setUp();
+ }
+ }
+
+ public void notFound() throws Exception {
+ acstate.getRequest().requestURI().setString("/foo");
+ acstate.connect("localhost", 8802);
+ cstate.readAll(bodyRecvBuffer, to);
+ }
+
+ public void testGzipRequest() throws Exception {
+ System.err.println("----------------------");
+ acstate.getRequest().requestURI().setString("/hello");
+ MessageBytes addValue =
+ acstate.req.getMimeHeaders().addValue("accept-encoding");
+ addValue.setString("gzip");
+
+
+ // Send the request, wait response
+ acstate.connect("localhost", 8802);
+ //cstate.waitResponseHead(10000); // headers are received
+ //ByteChunk data = new ByteChunk(1024);
+ //acstate.serializeResponse(acstate.res, data);
+
+
+ //System.err.println(bodyRecvBuffer.toString());
+
+ cstate.readAll(bodyRecvBuffer, to);
+ // Done
+ }
+
+}
Propchange: tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorThreadedTest.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorThreadedTest.java?rev=667823&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorThreadedTest.java (added)
+++ tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorThreadedTest.java Sat Jun 14 08:56:43 2008
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.client;
+
+
+import java.io.IOException;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.coyote.Request;
+import org.apache.coyote.Response;
+import org.apache.coyote.adapters.CoyoteServer;
+import org.apache.tomcat.test.CoyoteTestHelper;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+public class HttpProcessorThreadedTest extends TestCase {
+ CoyoteServer staticMain;
+
+ void initServers() {
+ staticMain = CoyoteTestHelper.getTestServer(8802);
+ }
+
+ public void setUp() {
+ initServers();
+ }
+
+ public void tearDown() throws Exception {
+ staticMain.stop();
+ }
+
+ int tCount = 1;
+ Thread[] threads = new Thread[tCount];
+ int[] ok = new int[tCount];
+ private int rCount = 100;
+
+ public void xtestSimpleRequest() throws Exception {
+ long t0 = System.currentTimeMillis();
+ for (int i = 0; i < tCount; i++) {
+ final int j = i;
+ threads[i] = new Thread(new Runnable() {
+ public void run() {
+ makeRequests(j, true);
+ }
+ });
+ threads[i].start();
+ }
+
+ int res = 0;
+ for (int i = 0; i < tCount; i++) {
+ threads[i].join();
+ res += ok[i];
+ }
+ long t1 = System.currentTimeMillis();
+ System.err.println("Time: " + (t1 - t0) + " " + res);
+ }
+
+ public void testSimpleRequestNB() throws Exception {
+ long t0 = System.currentTimeMillis();
+ for (int i = 0; i < tCount; i++) {
+ final int j = i;
+ threads[i] = new Thread(new Runnable() {
+ public void run() {
+ makeRequests(j, false);
+ }
+ });
+ threads[i].start();
+ }
+
+ int res = 0;
+ for (int i = 0; i < tCount; i++) {
+ threads[i].join();
+ res += ok[i];
+ }
+ long t1 = System.currentTimeMillis();
+ System.err.println("TimeNB: " + (t1 - t0) + " " + res);
+ }
+
+ void makeRequests(int t, boolean b) {
+ for (int i = 0; i < rCount ; i++) {
+ try {
+ //System.err.println("MakeReq " + t + " " + i);
+ makeRequest(t, b);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ static class ReqCallback extends AsyncHttpCallback {
+
+ public void bodyReceived(AsyncHttp cstate,
+ Request req,
+ Response res, boolean error, Throwable exception) throws IOException {
+ //dumpHead(cstate);
+ //System.err.println("DATA\n" + cstate.output.toString() + "\n----");
+ //assertTrue(cstate.bodyRecvBuffer.toString().indexOf("AAA") >= 0);
+ cstate.release();
+ }
+
+ @Override
+ public void headersReceived(AsyncHttp client,
+ Request req,
+ Response res) {
+ }
+
+ @Override
+ public void dataReceived(AsyncHttp client, Response res,
+ ByteChunk data, ByteChunk buffer, List<String> encodings) {
+ }
+
+
+ @Override
+ public void dataWritten(ByteChunk bc) {
+ }
+
+ }
+
+ void makeRequest(int i, boolean block) throws Exception {
+ AsyncHttp cstate = AsyncHttpPool.getDefault().get();
+
+ cstate.getRequest().requestURI().setString("/hello");
+ cstate.setCallback(new ReqCallback());
+
+ // Send the request, wait response
+ cstate.connect("localhost", 8802);
+ }
+
+}
Propchange: tomcat/sandbox/tomcat-lite/test/org/apache/coyote/client/HttpProcessorThreadedTest.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org