Return-Path: Delivered-To: apmail-hc-commits-archive@www.apache.org Received: (qmail 36138 invoked from network); 1 Jul 2009 20:07:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Jul 2009 20:07:41 -0000 Received: (qmail 75548 invoked by uid 500); 1 Jul 2009 20:07:51 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 75519 invoked by uid 500); 1 Jul 2009 20:07:51 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 75509 invoked by uid 99); 1 Jul 2009 20:07:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Jul 2009 20:07:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Jul 2009 20:07:48 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 54D442388898; Wed, 1 Jul 2009 20:07:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r790352 - /httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java Date: Wed, 01 Jul 2009 20:07:28 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090701200728.54D442388898@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Wed Jul 1 20:07:27 2009 New Revision: 790352 URL: http://svn.apache.org/viewvc?rev=790352&view=rev Log: More test coverage Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java?rev=790352&r1=790351&r2=790352&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestSessionInOutBuffers.java Wed Jul 1 20:07:27 2009 @@ -305,6 +305,106 @@ } } + public void testReadByteBuffer() throws Exception { + byte[] pattern = "0123456789ABCDEF".getBytes("US-ASCII"); + ReadableByteChannel channel = newChannel(pattern); + HttpParams params = new BasicHttpParams(); + SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, params); + while (inbuf.fill(channel) > 0) { + } + ByteBuffer dst = ByteBuffer.allocate(10); + assertEquals(10, inbuf.read(dst)); + dst.flip(); + assertEquals(dst, ByteBuffer.wrap(pattern, 0, 10)); + dst.clear(); + assertEquals(6, inbuf.read(dst)); + dst.flip(); + assertEquals(dst, ByteBuffer.wrap(pattern, 10, 6)); + } + + public void testReadByteBufferWithMaxLen() throws Exception { + byte[] pattern = "0123456789ABCDEF".getBytes("US-ASCII"); + ReadableByteChannel channel = newChannel(pattern); + HttpParams params = new BasicHttpParams(); + SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, params); + while (inbuf.fill(channel) > 0) { + } + ByteBuffer dst = ByteBuffer.allocate(16); + assertEquals(10, inbuf.read(dst, 10)); + dst.flip(); + assertEquals(dst, ByteBuffer.wrap(pattern, 0, 10)); + dst.clear(); + assertEquals(3, inbuf.read(dst, 3)); + dst.flip(); + assertEquals(dst, ByteBuffer.wrap(pattern, 10, 3)); + assertEquals(3, inbuf.read(dst, 20)); + dst.flip(); + assertEquals(dst, ByteBuffer.wrap(pattern, 13, 3)); + } + + public void testReadToChannel() throws Exception { + byte[] pattern = "0123456789ABCDEF".getBytes("US-ASCII"); + ReadableByteChannel channel = newChannel(pattern); + HttpParams params = new BasicHttpParams(); + SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, params); + while (inbuf.fill(channel) > 0) { + } + + ByteArrayOutputStream outstream = new ByteArrayOutputStream(); + WritableByteChannel dst = newChannel(outstream); + + assertEquals(16, inbuf.read(dst)); + assertEquals(ByteBuffer.wrap(pattern), ByteBuffer.wrap(outstream.toByteArray())); + } + + public void testReadToChannelWithMaxLen() throws Exception { + byte[] pattern = "0123456789ABCDEF".getBytes("US-ASCII"); + ReadableByteChannel channel = newChannel(pattern); + HttpParams params = new BasicHttpParams(); + SessionInputBuffer inbuf = new SessionInputBufferImpl(4096, 1024, params); + while (inbuf.fill(channel) > 0) { + } + + ByteArrayOutputStream outstream = new ByteArrayOutputStream(); + WritableByteChannel dst = newChannel(outstream); + + assertEquals(10, inbuf.read(dst, 10)); + assertEquals(3, inbuf.read(dst, 3)); + assertEquals(3, inbuf.read(dst, 10)); + assertEquals(ByteBuffer.wrap(pattern), ByteBuffer.wrap(outstream.toByteArray())); + } + + public void testWriteByteBuffer() throws Exception { + byte[] pattern = "0123456789ABCDEF0123456789ABCDEF".getBytes("US-ASCII"); + + HttpParams params = new BasicHttpParams(); + SessionOutputBuffer outbuf = new SessionOutputBufferImpl(4096, 1024, params); + ReadableByteChannel src = newChannel(pattern); + outbuf.write(src); + + ByteArrayOutputStream outstream = new ByteArrayOutputStream(); + WritableByteChannel channel = newChannel(outstream); + while (outbuf.flush(channel) > 0) { + } + assertEquals(ByteBuffer.wrap(pattern), ByteBuffer.wrap(outstream.toByteArray())); + } + + public void testWriteFromChannel() throws Exception { + byte[] pattern = "0123456789ABCDEF0123456789ABCDEF".getBytes("US-ASCII"); + + HttpParams params = new BasicHttpParams(); + SessionOutputBuffer outbuf = new SessionOutputBufferImpl(4096, 1024, params); + outbuf.write(ByteBuffer.wrap(pattern, 0, 16)); + outbuf.write(ByteBuffer.wrap(pattern, 16, 10)); + outbuf.write(ByteBuffer.wrap(pattern, 26, 6)); + + ByteArrayOutputStream outstream = new ByteArrayOutputStream(); + WritableByteChannel channel = newChannel(outstream); + while (outbuf.flush(channel) > 0) { + } + assertEquals(ByteBuffer.wrap(pattern), ByteBuffer.wrap(outstream.toByteArray())); + } + static final int SWISS_GERMAN_HELLO [] = { 0x47, 0x72, 0xFC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xE4, 0x6D, 0xE4 };