jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r574543 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/data/ main/java/org/apache/jackrabbit/core/persistence/bundle/util/ main/java/org/apache/jackrabbit/core/value/ test/java/org/apache/jackrabbit/core/data/
Date Tue, 11 Sep 2007 10:27:43 GMT
Author: thomasm
Date: Tue Sep 11 03:27:41 2007
New Revision: 574543

URL: http://svn.apache.org/viewvc?rev=574543&view=rev
Log:
#15482 new configuration parameter, bugfixes, and improved test coverage

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ExportImportTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/RandomInputStream.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java?rev=574543&r1=574542&r2=574543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
Tue Sep 11 03:27:41 2007
@@ -100,4 +100,12 @@
      */
     void init(String homeDir);
 
+    /**
+     * Get the minimum size of an object that should be stored in this data store.
+     * Depending on the overhead and configuration, each store may return a different value.
+     * 
+     * @return the minimum size
+     */
+    int getMinRecordLength();
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java?rev=574543&r1=574542&r2=574543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
Tue Sep 11 03:27:41 2007
@@ -35,6 +35,7 @@
  * <ul>
  * <li>&lt;param name="className" value="org.apache.jackrabbit.core.data.FileDataStore"/>
  * <li>&lt;param name="{@link #setPath(String) path}" value="/data/datastore"/>
+ * <li>&lt;param name="{@link #setMinRecordLength(int) minRecordLength}" value="1024"/>
  * </ul>
  * 
  * <p>
@@ -53,6 +54,11 @@
      * The digest algorithm used to uniquely identify records.
      */
     private static final String DIGEST = "SHA-1";
+    
+    /**
+     * The default value for the minimum object size.
+     */
+    private static final int DEFAULT_MIN_RECORD_LENGTH = 100;
 
     /**
      * Name of the directory used for temporary files.
@@ -77,6 +83,11 @@
      * of content within this directory is controlled by this class.
      */
     private String path;
+    
+    /**
+     * The minimum size of an object that should be stored in this data store.
+     */
+    private int minRecordLength = DEFAULT_MIN_RECORD_LENGTH;
 
     /**
      * Creates a uninitialized data store.
@@ -296,6 +307,22 @@
      */
     public void setPath(String directoryName) {
         this.path = directoryName;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getMinRecordLength() {
+        return minRecordLength;
+    }
+
+    /**
+     * Set the minimum object length.
+     * 
+     * @param minRecordLength the length
+     */
+    public void setMinRecordLength(int minRecordLength) {
+        this.minRecordLength = minRecordLength;
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java?rev=574543&r1=574542&r2=574543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
Tue Sep 11 03:27:41 2007
@@ -40,6 +40,7 @@
 import java.util.Set;
 
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 
 /**
  * This Class implements efficient serialization methods for item states.
@@ -560,6 +561,14 @@
                 case PropertyType.BINARY:
                     if (InternalValue.USE_DATA_STORE && dataStore != null) {
                         out.writeInt(-2);
+                        try {
+                            val.store(dataStore);
+                        } catch (RepositoryException e) {
+                            String msg = "Error while storing blob. id="
+                                + state.getId() + " idx=" + i + " size=" + val.getBLOBFileValue().getLength();
+                            log.error(msg, e);
+                            throw new IOException(msg);                            
+                        }
                         out.writeUTF(val.toString());
                         break;
                     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java?rev=574543&r1=574542&r2=574543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
Tue Sep 11 03:27:41 2007
@@ -46,6 +46,7 @@
 import java.util.Set;
 
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 
 /**
  * This Class implements relatively efficient serialization methods for item
@@ -385,6 +386,14 @@
                 case PropertyType.BINARY:
                     try {
                         if (InternalValue.USE_DATA_STORE && dataStore != null) {
+                            try {
+                                val.store(dataStore);
+                            } catch (RepositoryException e) {
+                                String msg = "Error while storing blob. id="
+                                    + state.getId() + " idx=" + i + " size=" + val.getBLOBFileValue().getLength();
+                                log.error(msg, e);
+                                throw new IOException(msg);                            
+                            }
                             out.writeInt(-2);
                             out.writeUTF(val.toString());
                             break;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java?rev=574543&r1=574542&r2=574543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInMemory.java
Tue Sep 11 03:27:41 2007
@@ -24,8 +24,6 @@
 import java.io.InputStream;
 import java.util.Arrays;
 
-import javax.jcr.RepositoryException;
-
 /**
  * Represents binary data which is backed by a byte[] (in memory).
  */
@@ -143,7 +141,7 @@
     /**
      * {@inheritDoc}
      */
-    public InputStream getStream() throws IllegalStateException, RepositoryException {
+    public InputStream getStream() {
         return new ByteArrayInputStream(data);
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java?rev=574543&r1=574542&r2=574543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInResource.java
Tue Sep 11 03:27:41 2007
@@ -110,7 +110,7 @@
     /**
      * {@inheritDoc}
      */
-    public InputStream getStream() throws IllegalStateException, RepositoryException {
+    public InputStream getStream() throws RepositoryException {
         try {
             return fsResource.getInputStream();
         } catch (FileSystemException fse) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=574543&r1=574542&r2=574543&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
Tue Sep 11 03:27:41 2007
@@ -83,11 +83,11 @@
     public static final boolean USE_DATA_STORE = Boolean.valueOf(System.getProperty("org.jackrabbit.useDataStore",
"false")).booleanValue();
 
     /**
-     * Byte arrays smaller or equal this size are always kept in memory
+     * Temporary binary values smaller or equal this size are kept in memory
      */
-    private static final int MIN_BLOB_FILE_SIZE = Integer.parseInt(System.getProperty("org.jackrabbit.minBlobFileSize",
"100"));
+    private static final int MIN_BLOB_FILE_SIZE = 1024;
 
-    private final Object val;
+    private Object val;
     private final int type;
 
     //------------------------------------------------------< factory methods >
@@ -282,9 +282,7 @@
      * @throws IOException
      */
     public static InternalValue create(File value) throws IOException {
-        if (USE_DATA_STORE) {
-            return new InternalValue(BLOBInTempFile.getInstance(value, false));
-        }                
+        assert !USE_DATA_STORE;
         return new InternalValue(new BLOBValue(value));
     }
     
@@ -599,9 +597,16 @@
     }
     
     private static BLOBFileValue getBLOBFileValue(DataStore store, InputStream in) throws
IOException {
-        byte[] buffer = new byte[MIN_BLOB_FILE_SIZE];
-        int pos = 0, len = MIN_BLOB_FILE_SIZE;
-        while (pos < MIN_BLOB_FILE_SIZE) {
+        int maxMemorySize;
+        if (store != null) {
+            maxMemorySize = store.getMinRecordLength() - 1;
+        } else {
+            maxMemorySize = MIN_BLOB_FILE_SIZE;
+        }
+        maxMemorySize = Math.max(0, maxMemorySize);
+        byte[] buffer = new byte[maxMemorySize];
+        int pos = 0, len = maxMemorySize;
+        while (pos < maxMemorySize) {
             int l = in.read(buffer, pos, len);
             if (l < 0) {
                 break;
@@ -609,7 +614,7 @@
             pos += l;
             len -= l;
         }
-        if (pos < MIN_BLOB_FILE_SIZE) {
+        if (pos < maxMemorySize) {
             // shrink the buffer
             byte[] data = new byte[pos];
             System.arraycopy(buffer, 0, data, 0, pos);
@@ -633,6 +638,24 @@
         } else {
             throw new IllegalArgumentException("illegal binary id: " + id);
         }
+    }
+
+    public void store(DataStore dataStore) throws RepositoryException, IOException {
+        assert USE_DATA_STORE;
+        assert dataStore != null;
+        assert type == PropertyType.BINARY;
+        BLOBFileValue v = (BLOBFileValue) val;
+        if (v instanceof BLOBInDataStore) {
+            // already in the data store, OK
+            return;
+        } else if (v instanceof BLOBInMemory) {
+            if (v.getLength() < dataStore.getMinRecordLength()) {
+                // in memory and does not make sense to store, OK
+                return;
+            }
+        }
+        // store the temp file to the data store, or (theoretically) load it in memory
+        val = getBLOBFileValue(dataStore, v.getStream());
     }
 
 }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ExportImportTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ExportImportTest.java?rev=574543&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ExportImportTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ExportImportTest.java
Tue Sep 11 03:27:41 2007
@@ -0,0 +1,110 @@
+/*
+ * 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.core.data;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Random;
+
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+public class ExportImportTest extends AbstractJCRTest {
+
+    /**
+     * Test a node type with a binary default value
+     * @throws RepositoryException 
+     */
+    public void testExportImportBinary() throws RepositoryException {
+        doTestExportImportBinary(0);
+        doTestExportImportBinary(10);
+        doTestExportImportBinary(10000);
+        doTestExportImportBinary(100000);
+    }
+
+    private void doTestExportImportBinary(int len) throws RepositoryException {
+        try {
+            Session session = helper.getReadWriteSession();
+            Node root = session.getRootNode();
+            clean(root);
+            Node test = root.addNode("testBinary");
+            session.save();
+            byte[] data = new byte[len];
+            Random random = new Random(1);
+            random.nextBytes(data);
+            test.setProperty("data", new ByteArrayInputStream(data));
+            test.save();
+            session.save();
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            session.exportSystemView("/testBinary", out, false, false);
+            byte[] output = out.toByteArray();
+            Node test2 = root.addNode("testBinary2");
+            Node test3 = root.addNode("testBinary3");
+            session.save();
+            session.importXML("/testBinary2", new ByteArrayInputStream(output), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+            session.save();
+            session.getWorkspace().importXML("/testBinary3", new ByteArrayInputStream(output),
ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+            test2 = root.getNode("testBinary2");
+            test2 = test2.getNode("testBinary");
+            test3 = root.getNode("testBinary3");
+            test3 = test3.getNode("testBinary");
+            byte[] data2 = readFromStream(test2.getProperty("data").getStream());
+            byte[] data3 = readFromStream(test3.getProperty("data").getStream());
+            assertEquals(data.length, data2.length);
+            assertEquals(data.length, data3.length);
+            for (int i = 0; i < len; i++) {
+                assertEquals(data[i], data2[i]);
+                assertEquals(data[i], data3[i]);
+            }
+            clean(root);
+        } catch (Exception e) {
+            e.printStackTrace();
+            assertFalse(e.getMessage(), true);
+        }
+    }
+    
+    private byte[] readFromStream(InputStream in) throws IOException {
+        ByteArrayOutputStream out2 = new ByteArrayOutputStream();
+        while (true) {
+            int x = in.read();
+            if (x < 0) {
+                break;
+            }
+            out2.write(x);
+        }
+        return out2.toByteArray();
+    }
+    
+    private void clean(Node root) throws RepositoryException {
+        while (root.hasNode("testBinary")) {
+            root.getNode("testBinary").remove();
+        }
+        while (root.hasNode("testBinary2")) {
+            root.getNode("testBinary2").remove();
+        }
+        while (root.hasNode("testBinary3")) {
+            root.getNode("testBinary3").remove();
+        }
+        root.getSession().save();
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/ExportImportTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java?rev=574543&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java
Tue Sep 11 03:27:41 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.core.data;
+
+import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.List;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+
+public class NodeTypeTest extends AbstractJCRTest {
+    
+    /**
+     * Test a node type with a binary default value
+     * @throws RepositoryException 
+     */
+    public void testNodeTypesWithBinaryDefaultValue() throws RepositoryException {
+        Session session = helper.getReadWriteSession();
+        NamespaceRegistry reg = session.getWorkspace().getNamespaceRegistry();
+        reg.registerNamespace("ns", "http://namespace.com/ns");
+        
+        doTestNodeTypesWithBinaryDefaultValue(0);
+        doTestNodeTypesWithBinaryDefaultValue(10);
+        doTestNodeTypesWithBinaryDefaultValue(10000);
+    }
+    
+    public void doTestNodeTypesWithBinaryDefaultValue(int len) {
+        try {
+            Session session = helper.getReadWriteSession();
+            Workspace ws = session.getWorkspace();
+            String d = new String(new char[len]).replace('\0', 'a');
+            Reader reader = new StringReader(
+                    "<ns = 'http://namespace.com/ns'>\n"
+                    + "[ns:foo"+len+"] \n" 
+                    + "- ns:bar(binary) = '" + d + "' m a");
+            CompactNodeTypeDefReader cndReader = new CompactNodeTypeDefReader(
+                    reader, "test");
+            List ntdList = cndReader.getNodeTypeDefs();
+            NodeTypeManagerImpl ntmgr = (NodeTypeManagerImpl) ws.getNodeTypeManager();
+            NodeTypeRegistry ntreg = ntmgr.getNodeTypeRegistry();
+            if (!ntreg.isRegistered(new QName("http://namespace.com/ns", "foo" + len))) {
+                ntreg.registerNodeTypes(ntdList);
+            }
+            Node root = session.getRootNode();
+            Node f = root.addNode("testfoo" + len, "ns:foo" + len);
+            InputStream in = f.getProperty("ns:bar").getValue().getStream();
+            StringBuffer buff = new StringBuffer();
+            while (true) {
+                int x = in.read();
+                if (x < 0) {
+                    break;
+                }
+                buff.append((char) x);
+            }
+            String d2 = buff.toString();
+            assertEquals(d, d2);
+        } catch (Exception e) {
+            e.printStackTrace();
+            assertFalse(e.getMessage(), true);
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/NodeTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/RandomInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/RandomInputStream.java?rev=574543&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/RandomInputStream.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/RandomInputStream.java
Tue Sep 11 03:27:41 2007
@@ -0,0 +1,121 @@
+/*
+ * 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.core.data;
+
+import java.io.InputStream;
+
+public class RandomInputStream extends InputStream {
+
+    private static final long MUL = 0x5DEECE66DL;
+    private static final long ADD = 0xBL;
+    private static final long MASK = (1L << 48) - 1;
+    private static final int MAX_READ_BLOCK = 15;
+
+    private final long initialSeed;
+    private final long len;
+    private long markedState;
+    private long pos;
+    private long markedPos;
+    private long state;
+
+    public String toString() {
+        return "new RandomInputStream(" + initialSeed + ", " + len + ")";
+    }
+
+    public RandomInputStream(long seed, long len) {
+        this.initialSeed = seed;
+        this.len = len;
+        setSeed(seed);
+        reset();
+    }
+
+    public long skip(long n) {
+        n = getReadBlock(n);
+        if (n == 0) {
+            return -1;
+        }
+        pos += n;
+        return n;
+    }
+
+    private int getReadBlock(long n) {
+        if (n > (len - pos)) {
+            n = (len - pos);
+        }
+        if (n > MAX_READ_BLOCK) {
+            n = MAX_READ_BLOCK;
+        } else if (n < 0) {
+            n = 0;
+        }
+        return (int) n;
+    }
+
+    public int read(byte[] b, int off, int len) {
+        if (pos >= this.len) {
+            return -1;
+        }
+        len = getReadBlock(len);
+        if (len == 0) {
+            return -1;
+        }
+        for (int i = 0; i < len; i++) {
+            b[off + i] = (byte) (next() & 255);
+        }
+        pos += len;
+        return len;
+    }
+
+    public int read(byte[] b) {
+        return read(b, 0, b.length);
+    }
+
+    public void close() {
+        pos = len;
+    }
+
+    private void setSeed(long seed) {
+        markedState = (seed ^ MUL) & MASK;
+    }
+
+    private int next() {
+        state = (state * MUL + ADD) & MASK;
+        return (int) (state >>> (48 - 32));
+    }
+
+    public void reset() {
+        pos = markedPos;
+        state = markedState;
+    }
+
+    public int read() {
+        if (pos >= len) {
+            return -1;
+        }
+        pos++;
+        return next() & 255;
+    }
+
+    public boolean markSupported() {
+        return true;
+    }
+
+    public void mark(int readlimit) {
+        markedPos = pos;
+        markedState = state;
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/RandomInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java?rev=574543&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
Tue Sep 11 03:27:41 2007
@@ -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.core.data;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all testcases for the data module.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a test suite that executes all tests inside this package.
+     *
+     * @return a test suite that executes all tests inside this package
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Data tests");
+        suite.addTestSuite(NodeTypeTest.class);
+        suite.addTestSuite(ExportImportTest.class);
+        return suite;
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message