jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1337139 - in /jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test: MicroKernelIT.java util/ util/TestInputStream.java
Date Fri, 11 May 2012 13:11:11 GMT
Author: stefan
Date: Fri May 11 13:11:10 2012
New Revision: 1337139

URL: http://svn.apache.org/viewvc?rev=1337139&view=rev
Log:
OAK-12: Implement a test suite for the MicroKernel

Added:
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/util/
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/util/TestInputStream.java
Modified:
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java?rev=1337139&r1=1337138&r2=1337139&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
Fri May 11 13:11:10 2012
@@ -17,12 +17,17 @@
 package org.apache.jackrabbit.mk.test;
 
 import org.apache.jackrabbit.mk.api.MicroKernelException;
+import org.apache.jackrabbit.mk.test.util.TestInputStream;
+import org.apache.jackrabbit.mk.util.MicroKernelInputStream;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -36,6 +41,10 @@ import static org.junit.Assert.assertNul
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+/**
+ * Integration tests for verifying that a {@code MicroKernel} implementation
+ * obeys the contract of the {@code MicroKernel} API.
+ */
 @RunWith(Parameterized.class)
 public class MicroKernelIT extends AbstractMicroKernelIT {
 
@@ -695,4 +704,45 @@ public class MicroKernelIT extends Abstr
         // make sure /branch/foo does now exist in head
         assertTrue(mk.nodeExists("/branch/foo", null));
     }
+
+    @Test
+    public void testBlobs() {
+        // size of test data
+        final int BLOB_SIZE = 32 * 1024 * 1024;
+
+        // write data
+        TestInputStream in = new TestInputStream(BLOB_SIZE);
+        String id = mk.write(in);
+        assertNotNull(id);
+        assertTrue(in.isClosed());
+
+        // write identical data
+        in = new TestInputStream(BLOB_SIZE);
+        String id1 = mk.write(in);
+        assertNotNull(id1);
+        assertTrue(in.isClosed());
+        // both id's must be identical since they refer to identical data
+        assertEquals(id, id1);
+
+        // verify length
+        assertEquals(mk.getLength(id), BLOB_SIZE);
+
+        // verify data
+        InputStream in1 = new TestInputStream(BLOB_SIZE);
+        InputStream in2 = new BufferedInputStream(new MicroKernelInputStream(mk, id));
+        try {
+            while (true) {
+                int x = in1.read();
+                int y = in2.read();
+                if (x == -1 || y == -1) {
+                    if (x == y) {
+                        break;
+                    }
+                }
+                assertEquals("data does not match", x, y);
+            }
+        } catch (IOException e) {
+            fail(e.getMessage());
+        }
+    }
 }

Added: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/util/TestInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/util/TestInputStream.java?rev=1337139&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/util/TestInputStream.java
(added)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/util/TestInputStream.java
Fri May 11 13:11:10 2012
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.test.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Random;
+
+/**
+ * An {@code InputStream} based on pseudo-random data useful for testing.
+ * <p/>
+ * Instances created with identical parameter values do produce identical byte
+ * sequences.
+ */
+public class TestInputStream extends InputStream {
+
+    private final Random random;
+    private final long length;
+
+    private long pos;
+    private boolean closed;
+
+    public TestInputStream(long length) {
+        this(0, length);
+    }
+
+    public TestInputStream(long seed, long length) {
+        super();
+        random = new Random(seed);
+        if (length < 0) {
+            throw new IllegalArgumentException("length cannot be negative");
+        }
+        this.length = length;
+        pos = 0;
+        closed = false;
+    }
+
+    public boolean isClosed() {
+        return closed;
+    }
+
+    @Override
+    public long skip(long n) throws IOException {
+        if (n <= 0) {
+            return 0;
+        }
+
+        long skipped;
+        for (skipped = 0; skipped < n; skipped++) {
+            if (read() == -1) {
+                break;
+            }
+        }
+        return skipped;
+    }
+
+    @Override
+    public int available() throws IOException {
+        return (int) Math.min(Integer.MAX_VALUE, length - pos);
+    }
+
+    @Override
+    public void close() throws IOException {
+        super.close();
+        closed = true;
+    }
+
+    @Override
+    public int read() throws IOException {
+        if (pos >= length) {
+            return -1;
+        }
+        pos++;
+        return random.nextInt() & 0xff;
+    }
+}



Mime
View raw message