You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2017/01/17 12:27:18 UTC
svn commit: r1779179 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java
test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java
Author: mreutegg
Date: Tue Jan 17 12:27:17 2017
New Revision: 1779179
URL: http://svn.apache.org/viewvc?rev=1779179&view=rev
Log:
OAK-5462: Expensive NodeDocument.split() with multi-valued binary property
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java?rev=1779179&r1=1779178&r2=1779179&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyState.java Tue Jan 17 12:27:17 2017
@@ -94,7 +94,14 @@ final class DocumentPropertyState implem
@Override
public long size(int index) {
- return parsed().size(index);
+ long size;
+ PropertyState parsed = parsed();
+ if (parsed.getType() == Type.BINARIES) {
+ size = parsed.getValue(Type.BINARY, index).length();
+ } else {
+ size = parsed.size(index);
+ }
+ return size;
}
@Override
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java?rev=1779179&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java Tue Jan 17 12:27:17 2017
@@ -0,0 +1,84 @@
+/*
+ * 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.oak.plugins.document;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.jackrabbit.oak.api.Blob;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.spi.blob.BlobStore;
+import org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Sets.newHashSet;
+import static org.junit.Assert.assertEquals;
+
+public class DocumentPropertyStateTest {
+
+ private static final int BLOB_SIZE = 16 * 1024;
+
+ @Rule
+ public DocumentMKBuilderProvider builderProvider = new DocumentMKBuilderProvider();
+
+ private Set<String> reads = newHashSet();
+
+ private BlobStore bs = new MemoryBlobStore() {
+ @Override
+ public InputStream getInputStream(String blobId)
+ throws IOException {
+ reads.add(blobId);
+ return super.getInputStream(blobId);
+ }
+ };
+
+ private DocumentNodeStore ns;
+
+ @Before
+ public void before() throws Exception {
+ ns = builderProvider.newBuilder().setBlobStore(bs).getNodeStore();
+ }
+
+ // OAK-5462
+ @Test
+ public void multiValuedBinarySize() throws Exception {
+ NodeBuilder builder = ns.getRoot().builder();
+ List<Blob> blobs = newArrayList();
+ for (int i = 0; i < 3; i++) {
+ blobs.add(builder.createBlob(new RandomStream(BLOB_SIZE, i)));
+ }
+ builder.child("test").setProperty("p", blobs, Type.BINARIES);
+ TestUtils.merge(ns, builder);
+
+ PropertyState p = ns.getRoot().getChildNode("test").getProperty("p");
+ assertEquals(Type.BINARIES, p.getType());
+ assertEquals(3, p.count());
+
+ reads.clear();
+ assertEquals(BLOB_SIZE, p.size(0));
+ // must not read the blob via stream
+ assertEquals(0, reads.size());
+ }
+
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentPropertyStateTest.java
------------------------------------------------------------------------------
svn:eol-style = native