jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1146647 - in /jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel: MicrokernelTest.java util/NumberStream.java
Date Thu, 14 Jul 2011 11:03:25 GMT
Author: mduerig
Date: Thu Jul 14 11:03:24 2011
New Revision: 1146647

URL: http://svn.apache.org/viewvc?rev=1146647&view=rev
Log:
spi2microkernel (WIP)
- refactor data store test

Added:
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/NumberStream.java
Modified:
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java?rev=1146647&r1=1146646&r2=1146647&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
Thu Jul 14 11:03:24 2011
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.mk.MicroKer
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
+import org.apache.jackrabbit.spi2microkernel.util.NumberStream;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
@@ -32,9 +33,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.BufferedInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -313,32 +312,22 @@ public class MicrokernelTest {
     }
 
     @Test
-    public void blobTest() {
+    public void blobTest() throws IOException {
         MicroKernel mk = getMicroKernel();
-
-        InputStream is = new InputStream() {
-            int counter;
-
-            @Override
-            public int read() throws IOException {
-                return counter < 12345678
-                    ? counter++ & 255
-                    : -1;
-            }
-        };
-
-        String blobId = mk.write(new BufferedInputStream(is));
+        int blobSize = 12345678;
+        String blobId = mk.write(new NumberStream(blobSize));
 
         int pos = 0;
         int count;
-        byte val = 0;
+        NumberStream expectedNumbers = new NumberStream(blobSize);
         byte[] buf = new byte[65536];
         while ((count = mk.read(blobId, pos, buf, 0, buf.length)) != -1) {
             pos += count;
             for (int c = 0; c < count; c++) {
-                assertEquals(val++, buf[c]);
+                assertEquals((byte) expectedNumbers.read(), buf[c]);
             }
         }
+        assertEquals(-1, expectedNumbers.read());
     }
 
     //------------------------------------------< private >---

Added: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/NumberStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/NumberStream.java?rev=1146647&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/NumberStream.java
(added)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/util/NumberStream.java
Thu Jul 14 11:03:24 2011
@@ -0,0 +1,40 @@
+/*
+ * 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.spi2microkernel.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class NumberStream extends InputStream {
+    private final int limit;
+    private int counter;
+
+    public NumberStream(int limit) {
+        this.limit = limit;
+    }
+
+    @Override
+    public int read() throws IOException {
+        return counter < limit
+            ? counter++ & 0xff
+            : -1;
+    }
+
+}



Mime
View raw message