jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r981945 - /jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/TestInputStream.java
Date Tue, 03 Aug 2010 16:02:29 GMT
Author: jukka
Date: Tue Aug  3 16:02:29 2010
New Revision: 981945

URL: http://svn.apache.org/viewvc?rev=981945&view=rev
Log:
JCR-2695: Jackrabbit performance test suite

In fact it's better to keep the test streams non-deterministic to prevent excessive data store
optimizations.

Modified:
    jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/TestInputStream.java

Modified: jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/TestInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/TestInputStream.java?rev=981945&r1=981944&r2=981945&view=diff
==============================================================================
--- jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/TestInputStream.java
(original)
+++ jackrabbit/commons/jcr-benchmark/trunk/src/main/java/org/apache/jackrabbit/benchmark/TestInputStream.java
Tue Aug  3 16:02:29 2010
@@ -14,19 +14,25 @@ class TestInputStream extends InputStrea
 
     private int i;
 
-    private final byte[] data = new byte[16 * 1024];
+    /**
+     * Source of the random stream of bytes. No fixed seed is used to
+     * prevent a solution like the Jackrabbit data store from using just
+     * a single storage location for multiple streams.
+     */
+    private final Random random = new Random();
 
     public TestInputStream(int length) {
         n = length;
         i = 0;
-
-        new Random(1234567890).nextBytes(data);
     }
 
     @Override
     public int read() {
         if (i < n) {
-            return data[i++ % data.length];
+            i++;
+            byte[] b = new byte[1];
+            random.nextBytes(b);
+            return b[0];
         } else {
             return -1;
         }
@@ -35,11 +41,11 @@ class TestInputStream extends InputStrea
     @Override
     public int read(byte[] b, int off, int len) {
         if (i < n) {
-            int dataOff = i % data.length;
-            int dataLen = Math.min(len, data.length - dataOff);
-            System.arraycopy(data, dataOff, b, off, dataLen);
-            i += dataLen;
-            return dataLen;
+            byte[] data = new byte[Math.min(len, n - i)];
+            random.nextBytes(data);
+            System.arraycopy(data, 0, b, off, data.length);
+            i += data.length;
+            return data.length;
         } else {
             return -1;
         }



Mime
View raw message