incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1544434 - in /sling/trunk/bundles/servlets/get/src: main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java
Date Fri, 22 Nov 2013 08:33:59 GMT
Author: bdelacretaz
Date: Fri Nov 22 08:33:58 2013
New Revision: 1544434

URL: http://svn.apache.org/r1544434
Log:
SLING-3255 - add some more StreamRendererServlet test cases

Modified:
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
    sling/trunk/bundles/servlets/get/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java?rev=1544434&r1=1544433&r2=1544434&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
(original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServlet.java
Fri Nov 22 08:33:58 2013
@@ -73,7 +73,7 @@ public class StreamRendererServlet exten
      */
     private static ArrayList<Range> FULL = new ArrayList<Range>(0);
 
-    private static final int IO_BUFFER_SIZE = 2048;
+    static final int IO_BUFFER_SIZE = 2048;
 
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());

Modified: sling/trunk/bundles/servlets/get/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java?rev=1544434&r1=1544433&r2=1544434&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java
(original)
+++ sling/trunk/bundles/servlets/get/src/test/java/org/apache/sling/servlets/get/impl/helpers/StreamRendererServletTest.java
Fri Nov 22 08:33:58 2013
@@ -18,28 +18,38 @@
  */
 package org.apache.sling.servlets.get.impl.helpers;
 
+import static org.junit.Assert.assertEquals;
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.util.Random;
 
-import org.apache.sling.servlets.get.impl.helpers.StreamRendererServlet;
+import org.junit.Test;
 
-import junit.framework.TestCase;
-
-public class StreamRendererServletTest extends TestCase {
+public class StreamRendererServletTest {
 
+    @Test
     public void testCopyRange() {
-        assertCopyRange(1234);
-        assertCopyRange(4321);
+        runTests(1234);
+        runTests(4321);
+    }
+
+    private void runTests(int randomSeed) {
+        final Random random = new Random(randomSeed);
+        assertCopyRange(random, StreamRendererServlet.IO_BUFFER_SIZE * 2 + 42);
+        assertCopyRange(random, StreamRendererServlet.IO_BUFFER_SIZE * 3);
+        assertCopyRange(random, StreamRendererServlet.IO_BUFFER_SIZE);
+        assertCopyRange(random, StreamRendererServlet.IO_BUFFER_SIZE - 1);
+        assertCopyRange(random, random.nextInt(StreamRendererServlet.IO_BUFFER_SIZE));
+        assertCopyRange(random, 42);
+        assertCopyRange(random, 1);
     }
 
-    private void assertCopyRange(long seed) {
-        Random random = new Random(seed);
+    private void assertCopyRange(Random random, int bufferSize) {
 
         // generate some random test data
-        byte[] expected = new byte[random.nextInt(10000)]; // >> IO_BUFFER_SIZE
+        final byte[] expected = new byte[bufferSize];
         random.nextBytes(expected);
 
         // Check some simple cases ...
@@ -48,16 +58,11 @@ public class StreamRendererServletTest e
         assertCopyRange(expected, 0, expected.length);
 
         // ... and a few randomly selected ones
-        int n = random.nextInt(100);
+        final int n = random.nextInt(100);
         for (int i = 0; i < n; i++) {
-            int a = random.nextInt(expected.length);
-            int b = random.nextInt(expected.length);
-            if (a > b) {
-                int x = a;
-                a = b;
-                b = x;
-            }
-            assertCopyRange(expected, a, b);
+            final int a = random.nextInt(expected.length);
+            final int b = random.nextInt(expected.length);
+            assertCopyRange(expected, Math.min(a, b), Math.max(a, b));
         }
     }
 



Mime
View raw message