jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1151403 - /jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DataStoreTest.java
Date Wed, 27 Jul 2011 09:47:25 GMT
Author: thomasm
Date: Wed Jul 27 09:47:24 2011
New Revision: 1151403

URL: http://svn.apache.org/viewvc?rev=1151403&view=rev
Log:
Improved data store test.

Modified:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DataStoreTest.java

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DataStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DataStoreTest.java?rev=1151403&r1=1151402&r2=1151403&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DataStoreTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DataStoreTest.java
Wed Jul 27 09:47:24 2011
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.mk;
 
 import java.io.ByteArrayInputStream;
+import java.util.Random;
 import junit.framework.TestCase;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.util.MicroKernelInputStream;
@@ -26,8 +27,8 @@ import org.apache.jackrabbit.mk.util.Mic
  */
 public class DataStoreTest extends TestCase {
 
-    // private static final String URL = "fs:{homeDir};clean";
-    private static final String URL = "mem:";
+    private static final String URL = "fs:{homeDir};clean";
+    // private static final String URL = "mem:";
 
     private MicroKernel mk;
 
@@ -39,17 +40,34 @@ public class DataStoreTest extends TestC
         mk.dispose();
     }
 
-    public void test() {
-        int len = 100;
-        String[] s = new String[len];
-        for (int i = 0; i < len; i++) {
-            s[i] = mk.write(new ByteArrayInputStream(new byte[i]));
-            s[i] = mk.write(new ByteArrayInputStream(new byte[i]));
+    public void testSmall() {
+        doTest(100, 1000);
+    }
+
+    public void testLarge() {
+        doTest(100000, 10);
+    }
+
+    private void doTest(int maxLength, int count) {
+        String[] s = new String[count];
+        Random r = new Random(0);
+        for (int i = 0; i < count;) {
+            byte[] data = new byte[r.nextInt(maxLength)];
+            r.nextBytes(data);
+            s[i++] = mk.write(new ByteArrayInputStream(data));
+            s[i++] = mk.write(new ByteArrayInputStream(data));
         }
-        for (int i = 0; i < len; i++) {
-            assertEquals(i, mk.getLength(s[i]));
-            byte[] b = MicroKernelInputStream.readFully(mk, s[i]);
-            assertEquals(i, b.length);
+        r.setSeed(0);
+        for (int i = 0; i < count;) {
+            int expectedLen = r.nextInt(maxLength);
+            byte[] expectedData = new byte[expectedLen];
+            r.nextBytes(expectedData);
+            assertEquals(expectedLen, mk.getLength(s[i++]));
+            byte[] b = MicroKernelInputStream.readFully(mk, s[i++]);
+            assertEquals(expectedLen, b.length);
+            for (int j = 0; j < expectedData.length; j++) {
+                assertEquals(expectedData[j], b[j]);
+            }
         }
     }
 



Mime
View raw message