Author: sjlee
Date: Tue Sep 1 23:24:00 2009
New Revision: 810307
URL: http://svn.apache.org/viewvc?rev=810307&view=rev
Log:
ASYNCWEB-36
Added another unit test that tests the boundary condition.
Modified:
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/ChunkedTest.java
Modified:
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/ChunkedTest.java
URL:
http://svn.apache.org/viewvc/mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/ChunkedTest.java?rev=810307&r1=810306&r2=810307&view=diff
==============================================================================
---
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/ChunkedTest.java
(original)
+++
mina/asyncweb/branches/1.0-mina1/client/src/test/java/org/apache/asyncweb/client/ChunkedTest.java
Tue Sep 1 23:24:00 2009
@@ -86,5 +86,30 @@
assertTrue(
Arrays.equals(response.getContent(),
"abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes()));
}
-
+
+ public void testChunkingBoundary() throws Exception {
+ // create a boundary condition where the last CRLF is around the edge
of the buffer
+ int size = FAKE_HTTP.length();
+ ByteBuffer buffer = ByteBuffer.allocate(size-1);
+ buffer.put(FAKE_HTTP.getBytes(), 0, size-1);
+ buffer.flip();
+
+ HttpRequestMessage request = new HttpRequestMessage(null, null);
+ IoSession session = new FakeIoSession();
+ session.setAttribute(HttpIoHandler.CURRENT_REQUEST, request);
+ HttpResponseDecoder decoder = new HttpResponseDecoder();
+ FakeProtocolDecoderOutput out = new FakeProtocolDecoderOutput();
+ decoder.decode(session, buffer, out);
+
+ // create a new buffer that carries the last remaining byte
+ buffer = ByteBuffer.allocate(size-1);
+ buffer.put(FAKE_HTTP.getBytes(), size-1, 1);
+ buffer.flip();
+ // finish decoding
+ decoder.decode(session, buffer, out);
+
+ HttpResponseMessage response = (HttpResponseMessage)out.getObject();
+ assertTrue(
+ Arrays.equals(response.getContent(),
"abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes()));
+ }
}