You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2014/11/04 16:25:23 UTC
svn commit: r1636606 - in
/tomcat/trunk/test/org/apache/coyote/http11/filters:
TestGzipOutputFilter.java TesterOutputBuffer.java
Author: markt
Date: Tue Nov 4 15:25:23 2014
New Revision: 1636606
URL: http://svn.apache.org/r1636606
Log:
Simplify
Modified:
tomcat/trunk/test/org/apache/coyote/http11/filters/TestGzipOutputFilter.java
tomcat/trunk/test/org/apache/coyote/http11/filters/TesterOutputBuffer.java
Modified: tomcat/trunk/test/org/apache/coyote/http11/filters/TestGzipOutputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/filters/TestGzipOutputFilter.java?rev=1636606&r1=1636605&r2=1636606&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/filters/TestGzipOutputFilter.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http11/filters/TestGzipOutputFilter.java Tue Nov 4 15:25:23 2014
@@ -51,28 +51,26 @@ public class TestGzipOutputFilter {
public void testFlushingWithGzip() throws Exception {
// set up response, InternalOutputBuffer, and ByteArrayOutputStream
Response res = new Response();
- TesterOutputBuffer iob = new TesterOutputBuffer(res, 8 * 1024);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- iob.outputStream = bos;
- res.setOutputBuffer(iob);
+ TesterOutputBuffer tob = new TesterOutputBuffer(res, 8 * 1024);
+ res.setOutputBuffer(tob);
- // set up GzipOutputFilter to attach to the InternalOutputBuffer
+ // set up GzipOutputFilter to attach to the TesterOutputBuffer
GzipOutputFilter gf = new GzipOutputFilter();
- iob.addFilter(gf);
- iob.addActiveFilter(gf);
+ tob.addFilter(gf);
+ tob.addActiveFilter(gf);
// write a chunk out
ByteChunk chunk = new ByteChunk(1024);
byte[] d = "Hello there tomcat developers, there is a bug in JDK".getBytes();
chunk.append(d, 0, d.length);
- iob.doWrite(chunk, res);
+ tob.doWrite(chunk, res);
// flush the InternalOutputBuffer
- iob.flush();
+ tob.flush();
// read from the ByteArrayOutputStream to find out what's being written
// out (flushed)
- byte[] dataFound = bos.toByteArray();
+ byte[] dataFound = tob.toByteArray();
// find out what's expected by writing to GZIPOutputStream and close it
// (to force flushing)
Modified: tomcat/trunk/test/org/apache/coyote/http11/filters/TesterOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/filters/TesterOutputBuffer.java?rev=1636606&r1=1636605&r2=1636606&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/filters/TesterOutputBuffer.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http11/filters/TesterOutputBuffer.java Tue Nov 4 15:25:23 2014
@@ -17,8 +17,8 @@
package org.apache.coyote.http11.filters;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
import java.net.Socket;
import org.apache.coyote.OutputBuffer;
@@ -29,12 +29,9 @@ import org.apache.tomcat.util.net.Abstra
import org.apache.tomcat.util.net.SocketWrapper;
/**
- * Output buffer.
- *
- * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
+ * Output buffer for use in unit tests. This is a minimal implementation.
*/
-public class TesterOutputBuffer extends AbstractOutputBuffer<Socket>
- implements ByteChunk.ByteOutputChannel {
+public class TesterOutputBuffer extends AbstractOutputBuffer<Socket> {
// ----------------------------------------------------------- Constructors
@@ -42,46 +39,14 @@ public class TesterOutputBuffer extends
* Default constructor.
*/
public TesterOutputBuffer(Response response, int headerBufferSize) {
-
super(response, headerBufferSize);
-
outputStreamOutputBuffer = new OutputStreamOutputBuffer();
-
- socketBuffer = new ByteChunk();
- socketBuffer.setByteOutputChannel(this);
}
/**
- * Underlying output stream. Note: protected to assist with unit testing
- */
- protected OutputStream outputStream;
-
-
- /**
- * Socket buffer.
- */
- private final ByteChunk socketBuffer;
-
-
- /**
- * Socket buffer (extra buffering to reduce number of packets sent).
+ * Underlying output stream.
*/
- private boolean useSocketBuffer = false;
-
-
- /**
- * Set the socket buffer size.
- */
- @Override
- public void setSocketBuffer(int socketBufferSize) {
-
- if (socketBufferSize > 500) {
- useSocketBuffer = true;
- socketBuffer.allocate(socketBufferSize, socketBufferSize);
- } else {
- useSocketBuffer = false;
- }
- }
+ private ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// --------------------------------------------------------- Public Methods
@@ -89,8 +54,7 @@ public class TesterOutputBuffer extends
@Override
public void init(SocketWrapper<Socket> socketWrapper,
AbstractEndpoint<Socket> endpoint) throws IOException {
-
- outputStream = socketWrapper.getSocket().getOutputStream();
+ // NO-OP: Unused
}
@@ -105,129 +69,66 @@ public class TesterOutputBuffer extends
}
- /**
- * End processing of current HTTP request.
- * Note: All bytes of the current request should have been already
- * consumed. This method only resets all the pointers so that we are ready
- * to parse the next HTTP request.
- */
- @Override
- public void nextRequest() {
- super.nextRequest();
- socketBuffer.recycle();
- }
-
-
// ------------------------------------------------ HTTP/1.1 Output Methods
/**
* Send an acknowledgement.
*/
@Override
- public void sendAck()
- throws IOException {
-
- if (!committed)
- outputStream.write(org.apache.coyote.http11.Constants.ACK_BYTES);
-
+ public void sendAck() {
+ // NO-OP: Unused
}
- // ------------------------------------------------------ Protected Methods
-
-
- /**
- * Commit the response.
- *
- * @throws IOException an underlying I/O error occurred
- */
- @Override
- protected void commit()
- throws IOException {
-
- // The response is now committed
- committed = true;
- response.setCommitted(true);
-
- if (pos > 0) {
- // Sending the response header buffer
- if (useSocketBuffer) {
- socketBuffer.append(headerBuffer, 0, pos);
- } else {
- outputStream.write(headerBuffer, 0, pos);
- }
- }
-
- }
-
-
- /**
- * Callback to write data from the buffer.
- */
@Override
- public void realWriteBytes(byte cbuf[], int off, int len)
- throws IOException {
- if (len > 0) {
- outputStream.write(cbuf, off, len);
- }
+ protected void commit() {
+ // NO-OP: Unused
}
- //-------------------------------------------------- Non-blocking IO methods
-
@Override
protected boolean hasMoreDataToFlush() {
- // The blocking connector always blocks until the previous write is
- // complete so there is never data remaining to flush. This effectively
- // allows non-blocking code to work with the blocking connector but -
- // obviously - every write will always block.
+ // Unused
return false;
}
@Override
protected void registerWriteInterest() {
- // NO-OP for non-blocking connector
+ // NO-OP: Unused
}
@Override
protected boolean flushBuffer(boolean block) throws IOException {
- // Blocking connector so ignore block parameter as this will always use
+ // Blocking IO so ignore block parameter as this will always use
// blocking IO.
- if (useSocketBuffer) {
- socketBuffer.flushBuffer();
- }
// Always blocks so never any data left over.
return false;
}
- // ----------------------------------- OutputStreamOutputBuffer Inner Class
+ /*
+ * Expose data written for use by unit tests.
+ */
+ byte[] toByteArray() {
+ return outputStream.toByteArray();
+ }
+
/**
* This class is an output buffer which will write data to an output
* stream.
*/
- protected class OutputStreamOutputBuffer
- implements OutputBuffer {
-
+ protected class OutputStreamOutputBuffer implements OutputBuffer {
/**
* Write chunk.
*/
@Override
- public int doWrite(ByteChunk chunk, Response res)
- throws IOException {
-
+ public int doWrite(ByteChunk chunk, Response res) throws IOException {
int length = chunk.getLength();
- if (useSocketBuffer) {
- socketBuffer.append(chunk.getBuffer(), chunk.getStart(),
- length);
- } else {
- outputStream.write(chunk.getBuffer(), chunk.getStart(),
- length);
- }
+ outputStream.write(chunk.getBuffer(), chunk.getStart(), length);
byteCount += chunk.getLength();
return chunk.getLength();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org