jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1002960 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/persistence/util/ main/java/org/apache/jackrabbit/core/value/ test/java/org/apache/jackrabbit/core/persistence/util/
Date Thu, 30 Sep 2010 08:27:58 GMT
Author: jukka
Date: Thu Sep 30 08:27:58 2010
New Revision: 1002960

URL: http://svn.apache.org/viewvc?rev=1002960&view=rev
Log:
JCR-2762: Optimize bundle serialization

Include serialized bundle byte patterns in the test case.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/NodePropBundle.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/NodePropBundle.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/NodePropBundle.java?rev=1002960&r1=1002959&r2=1002960&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/NodePropBundle.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/NodePropBundle.java
Thu Sep 30 08:27:58 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.persistence.util;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -511,6 +512,16 @@ public class NodePropBundle {
         public NodeId getId() {
             return id;
         }
+
+        public boolean equals(Object object) {
+            if (object instanceof ChildNodeEntry) {
+                ChildNodeEntry that = (ChildNodeEntry) object;
+                return name.equals(that.name) && id.equals(that.id);
+            } else {
+                return false;
+            }
+        }
+
     }
 
     //------------------------------------------------------< PropertyEntry >---
@@ -699,6 +710,18 @@ public class NodePropBundle {
             }
         }
 
+        public boolean equals(Object object) {
+            if (object instanceof PropertyEntry) {
+                PropertyEntry that = (PropertyEntry) object;
+                return id.equals(that.id)
+                    && type == that.type
+                    && multiValued == that.multiValued
+                    && Arrays.equals(values, that.values);
+            } else {
+                return false;
+            }
+        }
+
     }
 
 }

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=1002960&r1=1002959&r2=1002960&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
Thu Sep 30 08:27:58 2010
@@ -49,7 +49,6 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.value.AbstractQValueFactory;
 import org.apache.jackrabbit.spi.commons.value.QValueValue;
 import org.apache.jackrabbit.util.ISO8601;
-import org.apache.commons.io.IOUtils;
 
 /**
  * <code>InternalValue</code> represents the internal format of a property value.
@@ -706,4 +705,13 @@ public class InternalValue extends Abstr
         }
     }
 
+    public boolean equals(Object object) {
+        if (object instanceof InternalValue) {
+            InternalValue that = (InternalValue) object;
+            return type == that.type && val.equals(that.val);
+        } else {
+            return false;
+        }
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java?rev=1002960&r1=1002959&r2=1002960&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/BundleBindingTest.java
Thu Sep 30 08:27:58 2010
@@ -18,9 +18,17 @@ package org.apache.jackrabbit.core.persi
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+import java.util.Calendar;
 import java.util.Collections;
+import java.util.HashSet;
+
+import javax.jcr.PropertyType;
 
 import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.core.id.PropertyId;
+import org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry;
+import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 
@@ -37,11 +45,69 @@ public class BundleBindingTest extends T
 
     public void testEmptyBundle() throws Exception {
         NodePropBundle bundle = new NodePropBundle(new NodeId());
-        bundle.setParentId(new NodeId());
+        bundle.setParentId(new NodeId(1, 2));
         bundle.setNodeTypeName(NameConstants.NT_UNSTRUCTURED);
         bundle.setMixinTypeNames(Collections.<Name>emptySet());
         bundle.setSharedSet(Collections.<NodeId>emptySet());
+
         assertBundleRoundtrip(bundle);
+
+        assertBundleSerialization(bundle, new byte[] {
+                2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
+                0, 0, 0, 0, 0, 2, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1,
+                0, 0, 0, 0, 0 });
+    }
+
+    public void testComplexBundle() throws Exception {
+        NodeId id = new NodeId(1, 2);
+        NodePropBundle bundle = new NodePropBundle(id);
+        bundle.setParentId(new NodeId(3, 4));
+        bundle.setNodeTypeName(NameConstants.NT_UNSTRUCTURED);
+        bundle.setMixinTypeNames(Collections.singleton(
+                NameConstants.MIX_CREATED));
+        bundle.setReferenceable(true);
+        bundle.setSharedSet(new HashSet<NodeId>(Arrays.asList(
+                new NodeId(5, 6), new NodeId(7, 8), new NodeId(9, 10))));
+
+        PropertyEntry created = new PropertyEntry(
+                new PropertyId(id, NameConstants.JCR_CREATED));
+        created.setType(PropertyType.DATE);
+        created.setMultiValued(false);
+        Calendar date = Calendar.getInstance();
+        date.setTimeInMillis(1234567890);
+        created.setValues(new InternalValue[] { InternalValue.create(date) });
+        bundle.addProperty(created);
+
+        PropertyEntry createdby = new PropertyEntry(
+                new PropertyId(id, NameConstants.JCR_CREATEDBY));
+        createdby.setType(PropertyType.STRING);
+        createdby.setMultiValued(false);
+        createdby.setValues(new InternalValue[] {
+                InternalValue.create("test") });
+        bundle.addProperty(createdby);
+
+        bundle.addChildNodeEntry(
+                NameConstants.JCR_SYSTEM, new NodeId(11, 12));
+        bundle.addChildNodeEntry(
+                NameConstants.JCR_VERSIONSTORAGE, new NodeId(13, 14));
+
+        assertBundleRoundtrip(bundle);
+
+        assertBundleSerialization(bundle, new byte[] {
+                2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0,
+                0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, -1, -1, -1, -1,
+                0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
+                0, 0, 4, 116, 101, 115, 116, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0,
+                5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 29, 49, 57, 55, 48, 45, 48,
+                49, 45, 49, 53, 84, 48, 55, 58, 53, 54, 58, 48, 55, 46, 56,
+                57, 48, 43, 48, 49, 58, 48, 48, -1, -1, -1, -1, 1, 1, 0, 0,
+                0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 2, 0, 6,
+                115, 121, 115, 116, 101, 109, 1, 0, 0, 0, 0, 0, 0, 0, 13, 0,
+                0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 2, 0, 14, 118, 101, 114, 115,
+                105, 111, 110, 83, 116, 111, 114, 97, 103, 101, 0, 0, 0, 1,
+                0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 8, 1, 0, 0, 0,
+                0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 10, 1, 0, 0, 0, 0, 0, 0,
+                0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0 });
     }
 
     private void assertBundleRoundtrip(NodePropBundle bundle)
@@ -55,4 +121,13 @@ public class BundleBindingTest extends T
         assertEquals(bundle, binding.readBundle(
                 new ByteArrayInputStream(bytes), bundle.getId()));
     }
+
+    private void assertBundleSerialization(NodePropBundle bundle, byte[] data)
+            throws Exception {
+        assertTrue(binding.checkBundle(new ByteArrayInputStream(data)));
+
+        assertEquals(bundle, binding.readBundle(
+                new ByteArrayInputStream(data), bundle.getId()));
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/TestAll.java?rev=1002960&r1=1002959&r2=1002960&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/persistence/util/TestAll.java
Thu Sep 30 08:27:58 2010
@@ -26,6 +26,7 @@ public class TestAll extends TestCase {
         TestSuite suite = new TestSuite("Persistence utility tests");
 
         suite.addTestSuite(HashMapIndexTest.class);
+        suite.addTestSuite(BundleBindingTest.class);
 
         return suite;
     }



Mime
View raw message