hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r600155 - /jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
Date Sat, 01 Dec 2007 16:18:09 GMT
Author: olegk
Date: Sat Dec  1 08:18:08 2007
New Revision: 600155

URL: http://svn.apache.org/viewvc?rev=600155&view=rev
Log:
Updated NIOSSL test cases

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java?rev=600155&r1=600154&r2=600155&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestNIOSSLHttp.java
Sat Dec  1 08:18:08 2007
@@ -36,7 +36,6 @@
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Random;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -52,6 +51,7 @@
 import org.apache.http.entity.StringEntity;
 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
 import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.mockup.ByteSequence;
 import org.apache.http.mockup.RequestCount;
 import org.apache.http.mockup.SimpleEventListener;
 import org.apache.http.nio.NHttpClientHandler;
@@ -95,26 +95,17 @@
      * This test case executes a series of simple (non-pipelined) GET requests 
      * over multiple connections. 
      */
-    @SuppressWarnings("unchecked")
     public void testSimpleHttpGets() throws Exception {
         final int connNo = 3;
         final int reqNo = 20;
         final RequestCount requestCount = new RequestCount(connNo * reqNo); 
         
-        Random rnd = new Random();
+        final ByteSequence requestData = new ByteSequence();
+        requestData.rnd(reqNo);
         
-        // Prepare some random data
-        final List testData = new ArrayList(reqNo);
-        for (int i = 0; i < reqNo; i++) {
-            int size = rnd.nextInt(5000);
-            byte[] data = new byte[size];
-            rnd.nextBytes(data);
-            testData.add(data);
-        }
-        
-        List[] responseData = new List[connNo];
-        for (int i = 0; i < responseData.length; i++) {
-            responseData[i] = new ArrayList();
+        List<ByteSequence> responseData = new ArrayList<ByteSequence>(connNo);
+        for (int i = 0; i < connNo; i++) {
+            responseData.add(new ByteSequence());
         }
         
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
@@ -132,8 +123,8 @@
                     throw new HttpException("Invalid request URI: " + s);
                 }
                 int index = Integer.parseInt(uri.getQuery());
-                byte[] data = (byte []) testData.get(index);
-                ByteArrayEntity entity = new ByteArrayEntity(data); 
+                byte[] bytes = requestData.getBytes(index);
+                ByteArrayEntity entity = new ByteArrayEntity(bytes); 
                 response.setEntity(entity);
             }
             
@@ -142,7 +133,7 @@
         HttpRequestExecutionHandler requestExecutionHandler = new HttpRequestExecutionHandler()
{
 
             public void initalizeContext(final HttpContext context, final Object attachment)
{
-                context.setAttribute("LIST", (List) attachment);
+                context.setAttribute("LIST", (ByteSequence) attachment);
                 context.setAttribute("REQ-COUNT", new Integer(0));
                 context.setAttribute("RES-COUNT", new Integer(0));
             }
@@ -164,7 +155,7 @@
                 NHttpConnection conn = (NHttpConnection) context.getAttribute(
                         ExecutionContext.HTTP_CONNECTION);
                 
-                List list = (List) context.getAttribute("LIST");
+                ByteSequence list = (ByteSequence) context.getAttribute("LIST");
                 int i = ((Integer) context.getAttribute("RES-COUNT")).intValue();
                 i++;
                 context.setAttribute("RES-COUNT", new Integer(i));
@@ -172,7 +163,7 @@
                 try {
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
-                    list.add(data);
+                    list.addBytes(data);
                     requestCount.decrement();
                 } catch (IOException ex) {
                     requestCount.abort();
@@ -201,10 +192,10 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
         
-        for (int i = 0; i < responseData.length; i++) {
+        for (int i = 0; i < responseData.size(); i++) {
             this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()), 
-                    responseData[i]);
+                    responseData.get(i));
         }
      
         requestCount.await(10000);
@@ -213,13 +204,13 @@
         this.client.shutdown();
         this.server.shutdown();
 
-        for (int c = 0; c < responseData.length; c++) {
-            List receivedPackets = responseData[c];
-            List expectedPackets = testData;
+        for (int c = 0; c < responseData.size(); c++) {
+            ByteSequence receivedPackets = responseData.get(c);
+            ByteSequence expectedPackets = requestData;
             assertEquals(expectedPackets.size(), receivedPackets.size());
-            for (int p = 0; p < testData.size(); p++) {
-                byte[] expected = (byte[]) testData.get(p);
-                byte[] received = (byte[]) receivedPackets.get(p);
+            for (int p = 0; p < requestData.size(); p++) {
+                byte[] expected = requestData.getBytes(p);
+                byte[] received = receivedPackets.getBytes(p);
                 
                 assertEquals(expected.length, received.length);
                 for (int i = 0; i < expected.length; i++) {
@@ -234,27 +225,18 @@
      * This test case executes a series of simple (non-pipelined) POST requests 
      * with content length delimited content over multiple connections. 
      */
-    @SuppressWarnings("unchecked")
     public void testSimpleBasicHttpEntityEnclosingRequestsWithContentLength() throws Exception
{
         
         final int connNo = 3;
         final int reqNo = 20;
         final RequestCount requestCount = new RequestCount(connNo * reqNo); 
         
-        Random rnd = new Random();
-        
-        // Prepare some random data
-        final List testData = new ArrayList(reqNo);
-        for (int i = 0; i < reqNo; i++) {
-            int size = rnd.nextInt(5000);
-            byte[] data = new byte[size];
-            rnd.nextBytes(data);
-            testData.add(data);
-        }
+        final ByteSequence requestData = new ByteSequence();
+        requestData.rnd(reqNo);
         
-        List[] responseData = new List[connNo];
-        for (int i = 0; i < responseData.length; i++) {
-            responseData[i] = new ArrayList();
+        List<ByteSequence> responseData = new ArrayList<ByteSequence>(connNo);
+        for (int i = 0; i < connNo; i++) {
+            responseData.add(new ByteSequence());
         }
         
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
@@ -282,7 +264,7 @@
         HttpRequestExecutionHandler requestExecutionHandler = new HttpRequestExecutionHandler()
{
 
             public void initalizeContext(final HttpContext context, final Object attachment)
{
-                context.setAttribute("LIST", (List) attachment);
+                context.setAttribute("LIST", (ByteSequence) attachment);
                 context.setAttribute("REQ-COUNT", new Integer(0));
                 context.setAttribute("RES-COUNT", new Integer(0));
             }
@@ -295,8 +277,8 @@
                 BasicHttpEntityEnclosingRequest post = null;
                 if (i < reqNo) {
                     post = new BasicHttpEntityEnclosingRequest("POST", "/?" + i);
-                    byte[] data = (byte[]) testData.get(i);
-                    ByteArrayEntity outgoing = new ByteArrayEntity(data);
+                    byte[] bytes = requestData.getBytes(i);
+                    ByteArrayEntity outgoing = new ByteArrayEntity(bytes);
                     post.setEntity(outgoing);
                     
                     context.setAttribute("REQ-COUNT", new Integer(i + 1));
@@ -308,7 +290,7 @@
                 NHttpConnection conn = (NHttpConnection) context.getAttribute(
                         ExecutionContext.HTTP_CONNECTION);
                 
-                List list = (List) context.getAttribute("LIST");
+                ByteSequence list = (ByteSequence) context.getAttribute("LIST");
                 int i = ((Integer) context.getAttribute("RES-COUNT")).intValue();
                 i++;
                 context.setAttribute("RES-COUNT", new Integer(i));
@@ -316,7 +298,7 @@
                 try {
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
-                    list.add(data);
+                    list.addBytes(data);
                     requestCount.decrement();
                 } catch (IOException ex) {
                     requestCount.abort();
@@ -345,10 +327,10 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
         
-        for (int i = 0; i < responseData.length; i++) {
+        for (int i = 0; i < responseData.size(); i++) {
             this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()), 
-                    responseData[i]);
+                    responseData.get(i));
         }
      
         requestCount.await(10000);
@@ -357,13 +339,13 @@
         this.client.shutdown();
         this.server.shutdown();
 
-        for (int c = 0; c < responseData.length; c++) {
-            List receivedPackets = responseData[c];
-            List expectedPackets = testData;
+        for (int c = 0; c < responseData.size(); c++) {
+            ByteSequence receivedPackets = responseData.get(c);
+            ByteSequence expectedPackets = requestData;
             assertEquals(expectedPackets.size(), receivedPackets.size());
-            for (int p = 0; p < testData.size(); p++) {
-                byte[] expected = (byte[]) testData.get(p);
-                byte[] received = (byte[]) receivedPackets.get(p);
+            for (int p = 0; p < requestData.size(); p++) {
+                byte[] expected = requestData.getBytes(p);
+                byte[] received = receivedPackets.getBytes(p);
                 
                 assertEquals(expected.length, received.length);
                 for (int i = 0; i < expected.length; i++) {
@@ -378,27 +360,18 @@
      * This test case executes a series of simple (non-pipelined) POST requests 
      * with chunk coded content content over multiple connections. 
      */
-    @SuppressWarnings("unchecked")
     public void testSimpleBasicHttpEntityEnclosingRequestsChunked() throws Exception {
         
         final int connNo = 3;
         final int reqNo = 20;
         final RequestCount requestCount = new RequestCount(connNo * reqNo); 
         
-        Random rnd = new Random();
+        final ByteSequence requestData = new ByteSequence();
+        requestData.rnd(reqNo);
         
-        // Prepare some random data
-        final List testData = new ArrayList(reqNo);
-        for (int i = 0; i < reqNo; i++) {
-            int size = rnd.nextInt(20000);
-            byte[] data = new byte[size];
-            rnd.nextBytes(data);
-            testData.add(data);
-        }
-        
-        List[] responseData = new List[connNo];
-        for (int i = 0; i < responseData.length; i++) {
-            responseData[i] = new ArrayList();
+        List<ByteSequence> responseData = new ArrayList<ByteSequence>(connNo);
+        for (int i = 0; i < connNo; i++) {
+            responseData.add(new ByteSequence());
         }
         
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
@@ -425,7 +398,7 @@
         HttpRequestExecutionHandler requestExecutionHandler = new HttpRequestExecutionHandler()
{
 
             public void initalizeContext(final HttpContext context, final Object attachment)
{
-                context.setAttribute("LIST", (List) attachment);
+                context.setAttribute("LIST", (ByteSequence) attachment);
                 context.setAttribute("REQ-COUNT", new Integer(0));
                 context.setAttribute("RES-COUNT", new Integer(0));
             }
@@ -438,8 +411,8 @@
                 BasicHttpEntityEnclosingRequest post = null;
                 if (i < reqNo) {
                     post = new BasicHttpEntityEnclosingRequest("POST", "/?" + i);
-                    byte[] data = (byte[]) testData.get(i);
-                    ByteArrayEntity outgoing = new ByteArrayEntity(data);
+                    byte[] bytes = requestData.getBytes(i);
+                    ByteArrayEntity outgoing = new ByteArrayEntity(bytes);
                     outgoing.setChunked(true);
                     post.setEntity(outgoing);
                     
@@ -452,7 +425,7 @@
                 NHttpConnection conn = (NHttpConnection) context.getAttribute(
                         ExecutionContext.HTTP_CONNECTION);
                 
-                List list = (List) context.getAttribute("LIST");
+                ByteSequence list = (ByteSequence) context.getAttribute("LIST");
                 int i = ((Integer) context.getAttribute("RES-COUNT")).intValue();
                 i++;
                 context.setAttribute("RES-COUNT", new Integer(i));
@@ -460,7 +433,7 @@
                 try {
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
-                    list.add(data);
+                    list.addBytes(data);
                     requestCount.decrement();
                 } catch (IOException ex) {
                     requestCount.abort();
@@ -492,10 +465,10 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
         
-        for (int i = 0; i < responseData.length; i++) {
+        for (int i = 0; i < responseData.size(); i++) {
             this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()), 
-                    responseData[i]);
+                    responseData.get(i));
         }
      
         requestCount.await(10000);
@@ -504,13 +477,13 @@
         this.client.shutdown();
         this.server.shutdown();
 
-        for (int c = 0; c < responseData.length; c++) {
-            List receivedPackets = responseData[c];
-            List expectedPackets = testData;
+        for (int c = 0; c < responseData.size(); c++) {
+            ByteSequence receivedPackets = responseData.get(c);
+            ByteSequence expectedPackets = requestData;
             assertEquals(expectedPackets.size(), receivedPackets.size());
-            for (int p = 0; p < testData.size(); p++) {
-                byte[] expected = (byte[]) testData.get(p);
-                byte[] received = (byte[]) receivedPackets.get(p);
+            for (int p = 0; p < requestData.size(); p++) {
+                byte[] expected = requestData.getBytes(p);
+                byte[] received = receivedPackets.getBytes(p);
                 
                 assertEquals(expected.length, received.length);
                 for (int i = 0; i < expected.length; i++) {
@@ -525,27 +498,18 @@
      * This test case executes a series of simple (non-pipelined) HTTP/1.0 
      * POST requests over multiple persistent connections. 
      */
-    @SuppressWarnings("unchecked")
     public void testSimpleBasicHttpEntityEnclosingRequestsHTTP10() throws Exception {
         
         final int connNo = 3;
         final int reqNo = 20;
         final RequestCount requestCount = new RequestCount(connNo * reqNo); 
         
-        Random rnd = new Random();
+        final ByteSequence requestData = new ByteSequence();
+        requestData.rnd(reqNo);
         
-        // Prepare some random data
-        final List testData = new ArrayList(reqNo);
-        for (int i = 0; i < reqNo; i++) {
-            int size = rnd.nextInt(5000);
-            byte[] data = new byte[size];
-            rnd.nextBytes(data);
-            testData.add(data);
-        }
-        
-        List[] responseData = new List[connNo];
-        for (int i = 0; i < responseData.length; i++) {
-            responseData[i] = new ArrayList();
+        List<ByteSequence> responseData = new ArrayList<ByteSequence>(connNo);
+        for (int i = 0; i < connNo; i++) {
+            responseData.add(new ByteSequence());
         }
         
         HttpRequestHandler requestHandler = new HttpRequestHandler() {
@@ -578,7 +542,7 @@
         HttpRequestExecutionHandler requestExecutionHandler = new HttpRequestExecutionHandler()
{
 
             public void initalizeContext(final HttpContext context, final Object attachment)
{
-                context.setAttribute("LIST", (List) attachment);
+                context.setAttribute("LIST", (ByteSequence) attachment);
                 context.setAttribute("REQ-COUNT", new Integer(0));
                 context.setAttribute("RES-COUNT", new Integer(0));
             }
@@ -591,8 +555,8 @@
                 BasicHttpEntityEnclosingRequest post = null;
                 if (i < reqNo) {
                     post = new BasicHttpEntityEnclosingRequest("POST", "/?" + i);
-                    byte[] data = (byte[]) testData.get(i);
-                    ByteArrayEntity outgoing = new ByteArrayEntity(data);
+                    byte[] bytes = requestData.getBytes(i);
+                    ByteArrayEntity outgoing = new ByteArrayEntity(bytes);
                     post.setEntity(outgoing);
                     
                     context.setAttribute("REQ-COUNT", new Integer(i + 1));
@@ -604,7 +568,7 @@
                 NHttpConnection conn = (NHttpConnection) context.getAttribute(
                         ExecutionContext.HTTP_CONNECTION);
 
-                List list = (List) context.getAttribute("LIST");
+                ByteSequence list = (ByteSequence) context.getAttribute("LIST");
                 int i = ((Integer) context.getAttribute("RES-COUNT")).intValue();
                 i++;
                 context.setAttribute("RES-COUNT", new Integer(i));
@@ -612,7 +576,7 @@
                 try {
                     HttpEntity entity = response.getEntity();
                     byte[] data = EntityUtils.toByteArray(entity);
-                    list.add(data);
+                    list.addBytes(data);
                     requestCount.decrement();
                 } catch (IOException ex) {
                     requestCount.abort();
@@ -644,10 +608,10 @@
         endpoint.waitFor();
         InetSocketAddress serverAddress = (InetSocketAddress) endpoint.getAddress();
         
-        for (int i = 0; i < responseData.length; i++) {
+        for (int i = 0; i < responseData.size(); i++) {
             this.client.openConnection(
                     new InetSocketAddress("localhost", serverAddress.getPort()), 
-                    responseData[i]);
+                    responseData.get(i));
         }
      
         requestCount.await(10000);
@@ -656,13 +620,13 @@
         this.client.shutdown();
         this.server.shutdown();
 
-        for (int c = 0; c < responseData.length; c++) {
-            List receivedPackets = responseData[c];
-            List expectedPackets = testData;
+        for (int c = 0; c < responseData.size(); c++) {
+            ByteSequence receivedPackets = responseData.get(c);
+            ByteSequence expectedPackets = requestData;
             assertEquals(expectedPackets.size(), receivedPackets.size());
-            for (int p = 0; p < testData.size(); p++) {
-                byte[] expected = (byte[]) testData.get(p);
-                byte[] received = (byte[]) receivedPackets.get(p);
+            for (int p = 0; p < requestData.size(); p++) {
+                byte[] expected = requestData.getBytes(p);
+                byte[] received = receivedPackets.getBytes(p);
                 
                 assertEquals(expected.length, received.length);
                 for (int i = 0; i < expected.length; i++) {



Mime
View raw message