jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1159588 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/datastore/ test/java/org/apache/jackrabbit/mk/ test/java/org/apache/jackrabbit/mk/datastore/ test/java/org/apache/jackrabbit/mk/util/
Date Fri, 19 Aug 2011 10:45:45 GMT
Author: thomasm
Date: Fri Aug 19 10:45:44 2011
New Revision: 1159588

URL: http://svn.apache.org/viewvc?rev=1159588&view=rev
Log:
Move and improve data store tests.

Added:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/DataStoreTest.java
      - copied, changed from r1156601, jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DataStoreTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/DbStoreTest.java
      - copied, changed from r1156601, jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DbStoreTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/FileStoreTest.java
      - copied, changed from r1156601, jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/FileStoreTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/MemoryStoreTest.java
Removed:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DataStoreTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DbStoreTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/FileStoreTest.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/datastore/Store.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/IOUtilsTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/StringUtilsTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/datastore/Store.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/datastore/Store.java?rev=1159588&r1=1159587&r2=1159588&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/datastore/Store.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/datastore/Store.java
Fri Aug 19 10:45:44 2011
@@ -183,7 +183,7 @@ public abstract class Store {
                     }
                 }
             } else {
-                throw new IOException("Datastore id type " + type + " for blob " + blobId);
+                throw new IOException("Unknown datastore id type " + type + " for blob "
+ blobId);
             }
         }
     }

Copied: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/DataStoreTest.java
(from r1156601, 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/datastore/DataStoreTest.java?p2=jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/DataStoreTest.java&p1=jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DataStoreTest.java&r1=1156601&r2=1159588&rev=1159588&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/datastore/DataStoreTest.java
Fri Aug 19 10:45:44 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk;
+package org.apache.jackrabbit.mk.datastore;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -22,11 +22,12 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Random;
 import junit.framework.TestCase;
+import org.apache.jackrabbit.mk.MicroKernelFactory;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.util.MicroKernelInputStream;
 
 /**
- * Test the data store
+ * Test the data store using the MicroKernel API.
  */
 public class DataStoreTest extends TestCase {
 

Copied: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/DbStoreTest.java
(from r1156601, jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DbStoreTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/DbStoreTest.java?p2=jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/DbStoreTest.java&p1=jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DbStoreTest.java&r1=1156601&r2=1159588&rev=1159588&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/DbStoreTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/DbStoreTest.java
Fri Aug 19 10:45:44 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk;
+package org.apache.jackrabbit.mk.datastore;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -31,6 +31,7 @@ import org.apache.jackrabbit.mk.datastor
 import org.apache.jackrabbit.mk.datastore.StoreInputStream;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
+import org.apache.jackrabbit.mk.util.IOUtilsTest;
 import org.h2.jdbcx.JdbcConnectionPool;
 
 /**
@@ -58,6 +59,36 @@ public class DbStoreTest extends TestCas
         }
     }
 
+    public void testCombinedIdentifier() throws Exception {
+        String id = store.writeBlob(new ByteArrayInputStream(new byte[2]));
+        assertEquals(2, store.getBlobLength(id));
+        String combinedId = id + id;
+        assertEquals(4, store.getBlobLength(combinedId));
+        doTestRead(new byte[4], 4, combinedId);
+    }
+
+    public void testEmptyIdentifier() throws Exception {
+        byte[] data = new byte[1];
+        assertEquals(-1, store.readBlob("", 0, data, 0, 1));
+        assertEquals(0, store.getBlobLength(""));
+    }
+
+    public void testIllegalIdentifier() throws Exception {
+        byte[] data = new byte[1];
+        try {
+            store.readBlob("ff", 0, data, 0, 1);
+            fail();
+        } catch (IOException e) {
+            // expected
+        }
+        try {
+            store.getBlobLength("ff");
+            fail();
+        } catch (IOException e) {
+            // expected
+        }
+    }
+
     public void testSmall() throws Exception {
         doTest(10, 1000);
     }
@@ -91,30 +122,25 @@ public class DbStoreTest extends TestCas
         }
     }
 
-    private void assertByteArrayEquals(byte[] expected, int expectedLen, byte[] got) {
-        assertEquals(expectedLen, got.length);
-        for (int j = 0; j < expectedLen; j++) {
-            if (expected[j] != got[j]) {
-                assertEquals("j:" + j, expected[j], got[j]);
-            }
-        }
-    }
-
     private void doTestRead(byte[] expectedData, int expectedLen, String id) throws Exception
{
         byte[] got = readFully(id);
-        assertByteArrayEquals(expectedData, expectedLen, got);
+        assertEquals(expectedLen, got.length);
+        IOUtilsTest.assertEquals(expectedData, got);
     }
 
     public byte[] readFully(String id) throws Exception {
         int len = (int) store.getBlobLength(id);
-        byte[] buff = new byte[len];
-        int off = 0, remaining = len;
-        while (remaining > 0) {
-            int l = store.readBlob(id, off, buff, off, remaining);
-            off += l;
-            remaining -= l;
+        byte[] data;
+        if (len < 100) {
+            data = new byte[len];
+            for (int i = 0; i < len; i++) {
+                store.readBlob(id, i, data, i, 1);
+            }
+        } else {
+            data = StoreInputStream.readFully(store, id);
         }
-        return buff;
+        assertEquals(len, data.length);
+        return data;
     }
 
     public static void main(String... args) throws Exception {

Copied: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/FileStoreTest.java
(from r1156601, jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/FileStoreTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/FileStoreTest.java?p2=jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/FileStoreTest.java&p1=jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/FileStoreTest.java&r1=1156601&r2=1159588&rev=1159588&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/FileStoreTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/FileStoreTest.java
Fri Aug 19 10:45:44 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.mk;
+package org.apache.jackrabbit.mk.datastore;
 
 import org.apache.jackrabbit.mk.datastore.FileStore;
 
@@ -34,4 +34,5 @@ public class FileStoreTest extends DbSto
     public void tearDown() throws Exception {
         // nothing to do
     }
+
 }

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/MemoryStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/MemoryStoreTest.java?rev=1159588&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/MemoryStoreTest.java
(added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/datastore/MemoryStoreTest.java
Fri Aug 19 10:45:44 2011
@@ -0,0 +1,33 @@
+/*
+ * 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.datastore;
+
+/**
+ * Tests the MemoryStore implementation.
+ */
+public class MemoryStoreTest extends DbStoreTest {
+
+    public void setUp() throws Exception {
+        MemoryStore store = new MemoryStore();
+        this.store = store;
+    }
+
+    public void tearDown() throws Exception {
+        // nothing to do
+    }
+
+}

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/IOUtilsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/IOUtilsTest.java?rev=1159588&r1=1159587&r2=1159588&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/IOUtilsTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/IOUtilsTest.java
Fri Aug 19 10:45:44 2011
@@ -53,7 +53,7 @@ public class IOUtilsTest extends TestCas
         assertEquals(0, readCount.get());
 
         assertEquals(1000, IOUtils.readFully(in, test, 0, 1000));
-        StringUtilsTest.assertEquals(data, test);
+        IOUtilsTest.assertEquals(data, test);
         test = new byte[1001];
         in.reset();
         in.mark(10000);
@@ -211,4 +211,11 @@ public class IOUtilsTest extends TestCas
         assertEquals(-1, in.read());
     }
 
+    public static void assertEquals(byte[] expected, byte[] got) {
+        assertEquals(expected.length, got.length);
+        for (int i = 0; i < got.length; i++) {
+            assertEquals(expected[i], got[i]);
+        }
+    }
+
 }

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/StringUtilsTest.java?rev=1159588&r1=1159587&r2=1159588&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/StringUtilsTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/StringUtilsTest.java
Fri Aug 19 10:45:44 2011
@@ -27,10 +27,10 @@ public class StringUtilsTest extends Tes
         assertEquals("0123", StringUtils.convertBytesToHex(new byte[] { (byte) 0x01, (byte)
0x23 }));
         assertEquals("89bd", StringUtils.convertBytesToHex(new byte[] { (byte) 0x89, (byte)
0xbd }));
         assertEquals("face", StringUtils.convertBytesToHex(new byte[] { (byte) 0xfa, (byte)
0xce }));
-        assertEquals(new byte[] { (byte) 0xfa, (byte) 0xce }, StringUtils.convertHexToBytes("face"));
-        assertEquals(new byte[] { (byte) 0xfa, (byte) 0xce }, StringUtils.convertHexToBytes("fAcE"));
-        assertEquals(new byte[] { (byte) 0xfa, (byte) 0xce }, StringUtils.convertHexToBytes("FaCe"));
-        assertEquals(new byte[] { (byte) 0x09, (byte) 0xaf }, StringUtils.convertHexToBytes("09af"));
+        IOUtilsTest.assertEquals(new byte[] { (byte) 0xfa, (byte) 0xce }, StringUtils.convertHexToBytes("face"));
+        IOUtilsTest.assertEquals(new byte[] { (byte) 0xfa, (byte) 0xce }, StringUtils.convertHexToBytes("fAcE"));
+        IOUtilsTest.assertEquals(new byte[] { (byte) 0xfa, (byte) 0xce }, StringUtils.convertHexToBytes("FaCe"));
+        IOUtilsTest.assertEquals(new byte[] { (byte) 0x09, (byte) 0xaf }, StringUtils.convertHexToBytes("09af"));
         for (String s : new String[]{"120", "1/", "9:", "fast", "a`", "ag", "0@", "aG"})
{
             try {
                 StringUtils.convertHexToBytes(s);
@@ -41,11 +41,4 @@ public class StringUtilsTest extends Tes
         }
     }
 
-    public static void assertEquals(byte[] expected, byte[] got) {
-        assertEquals(expected.length, got.length);
-        for (int i = 0; i < got.length; i++) {
-            assertEquals(expected[i], got[i]);
-        }
-    }
-
 }



Mime
View raw message