Author: chetanm
Date: Wed Mar 26 07:58:05 2014
New Revision: 1581720
URL: http://svn.apache.org/r1581720
Log:
OAK-1604 - Support for signed references in Blob (WIP)
Port the org.apache.jackrabbit.core.value.ReferenceBinaryTest to Oak. The test
is run with two fixture for SegmentStore and DocumentNodeStore backed by
FileDataStore
Added:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferenceBinaryIT.java
(with props)
Modified:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NodeStoreFixture.java
Modified:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NodeStoreFixture.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NodeStoreFixture.java?rev=1581720&r1=1581719&r2=1581720&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NodeStoreFixture.java
(original)
+++
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NodeStoreFixture.java
Wed Mar 26 07:58:05 2014
@@ -33,6 +33,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStore;
import org.apache.jackrabbit.oak.plugins.segment.SegmentStore;
import org.apache.jackrabbit.oak.plugins.segment.memory.MemoryStore;
+import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
/**
@@ -184,27 +185,33 @@ public abstract class NodeStoreFixture {
private final String uri;
private final boolean inMemory;
+ private final BlobStore blobStore;
- public DocumentFixture(String uri, boolean inMemory) {
+ public DocumentFixture(String uri, boolean inMemory, BlobStore
blobStore) {
this.uri = uri;
this.inMemory = inMemory;
+ this.blobStore = blobStore;
}
public DocumentFixture(String uri) {
- this(uri, true);
+ this(uri, true, null);
}
public DocumentFixture() {
- this(DEFAULT_URI, false);
+ this(DEFAULT_URI, false, null);
}
- private static NodeStore createNodeStore(String uri) {
+ private static NodeStore createNodeStore(String uri, BlobStore
blobStore) {
MongoConnection connection;
try {
connection = new MongoConnection(uri);
DB mongoDB = connection.getDB();
- return new DocumentMK.Builder()
- .setMongoDB(mongoDB).getNodeStore();
+ DocumentMK.Builder builder = new DocumentMK.Builder();
+ if(blobStore != null){
+ builder.setBlobStore(blobStore);
+ }
+ builder.setMongoDB(mongoDB);
+ return builder.getNodeStore();
} catch (Exception e) {
return null;
}
@@ -215,19 +222,19 @@ public abstract class NodeStoreFixture {
if (inMemory) {
return new DocumentMK.Builder().getNodeStore();
} else {
- return createNodeStore(uri + '-' + System.nanoTime());
+ return createNodeStore(uri + '-' + System.nanoTime(),
blobStore);
}
}
@Override
public NodeStore createNodeStore(int clusterNodeId) {
- return createNodeStore(uri);
+ return createNodeStore(uri, blobStore);
}
@Override
public boolean isAvailable() {
// FIXME is there a better way to check whether MongoDB is
available?
- NodeStore nodeStore = createNodeStore(uri);
+ NodeStore nodeStore = createNodeStore(uri, blobStore);
if (nodeStore == null) {
return false;
} else {
Added:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferenceBinaryIT.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferenceBinaryIT.java?rev=1581720&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferenceBinaryIT.java
(added)
+++
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferenceBinaryIT.java
Wed Mar 26 07:58:05 2014
@@ -0,0 +1,169 @@
+/*
+ * 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.jcr;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Random;
+
+import javax.jcr.Binary;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import com.google.common.collect.Lists;
+import com.google.common.io.BaseEncoding;
+import org.apache.jackrabbit.api.JackrabbitRepository;
+import org.apache.jackrabbit.api.ReferenceBinary;
+import org.apache.jackrabbit.commons.jackrabbit.SimpleReferenceBinary;
+import org.apache.jackrabbit.core.data.RandomInputStream;
+import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore;
+import org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStore;
+import org.apache.jackrabbit.oak.plugins.segment.SegmentStore;
+import org.apache.jackrabbit.oak.plugins.segment.file.FileStore;
+import org.apache.jackrabbit.oak.spi.blob.BlobStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.jackrabbit.oak.jcr.NodeStoreFixture.DocumentFixture;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(Parameterized.class)
+public class ReferenceBinaryIT {
+
+ //Taken from org.apache.jackrabbit.oak.plugins.segment.Segment
+ //As SegmentStore inlines binary content with size less then MEDIUM_LIMIT
+ static final int SMALL_LIMIT = 1 << 7;
+ static final int MEDIUM_LIMIT = (1 << (16 - 2)) + SMALL_LIMIT;
+
+ private static final int STREAM_LENGTH = MEDIUM_LIMIT + 1000;
+
+ private final NodeStoreFixture fixture;
+
+ private NodeStore nodeStore;
+ private Repository repository;
+
+ public ReferenceBinaryIT(NodeStoreFixture fixture) {
+ this.fixture = fixture;
+ }
+
+ @Before
+ public void setup() throws RepositoryException {
+ nodeStore = fixture.createNodeStore();
+ repository = new Jcr(nodeStore).createRepository();
+ }
+
+ /**
+ * Taken from org.apache.jackrabbit.core.value.ReferenceBinaryTest
+ * @throws Exception
+ */
+ @Test
+ public void testReferenceBinaryExchangeWithSharedRepository() throws
Exception {
+ Session firstSession = createAdminSession();
+
+ // create a binary
+ Binary b = firstSession.getValueFactory().createBinary(new
RandomInputStream(1, STREAM_LENGTH));
+
+ ReferenceBinary referenceBinary = null;
+ if (b instanceof ReferenceBinary) {
+ referenceBinary = (ReferenceBinary) b;
+ }
+
+ assertNotNull(referenceBinary);
+
+ assertNotNull(referenceBinary.getReference());
+
+ // in the current test the message is exchanged via repository which
is shared as well
+ // put the reference message value in a property on a node
+ String newNode = "sample_" + System.nanoTime();
+ firstSession.getRootNode().addNode(newNode).setProperty("reference",
referenceBinary.getReference());
+
+ // save the first session
+ firstSession.save();
+
+ // get a second session over the same repository / ds
+ Session secondSession = repository.login(new
SimpleCredentials("admin", "admin".toCharArray()));
+
+ // read the binary referenced by the referencing binary
+ String reference =
secondSession.getRootNode().getNode(newNode).getProperty("reference").getString();
+
+ ReferenceBinary ref = new SimpleReferenceBinary(reference);
+
+ assertEquals(b,
secondSession.getValueFactory().createValue(ref).getBinary());
+
+ safeLogout(firstSession);
+ safeLogout(secondSession);
+
+ }
+
+ @After
+ public void tearDown() {
+ if (repository instanceof JackrabbitRepository) {
+ ((JackrabbitRepository) repository).shutdown();
+ }
+ fixture.dispose(nodeStore);
+ }
+
+ @Parameterized.Parameters
+ public static Collection<Object[]> fixtures() throws IOException {
+ File file = new File(new File("target"), "tar." + System.nanoTime());
+ SegmentStore segmentStore = new FileStore(createBlobStore(), file,
266, true);
+
+ List<Object[]> fixtures = Lists.newArrayList();
+ NodeStoreFixture.SegmentFixture segmentFixture = new
NodeStoreFixture.SegmentFixture(segmentStore);
+ if (segmentFixture.isAvailable()) {
+ fixtures.add(new Object[] {segmentFixture});
+ }
+ DocumentFixture documentFixture = new
DocumentFixture(DocumentFixture.DEFAULT_URI, false, createBlobStore());
+ if (documentFixture.isAvailable()) {
+ fixtures.add(new Object[]{documentFixture});
+ }
+ return fixtures;
+ }
+
+ private static BlobStore createBlobStore(){
+ File file = new File(new File("target"), "datastore." +
System.nanoTime());
+ OakFileDataStore fds = new OakFileDataStore();
+ byte[] key = new byte[256];
+ new Random().nextBytes(key);
+ fds.setSigningKey(BaseEncoding.base64().encode(key));
+ fds.setMinRecordLength(4092);
+ fds.init(file.getAbsolutePath());
+ return new DataStoreBlobStore(fds);
+ }
+
+ private Session createAdminSession() throws RepositoryException {
+ return repository.login(new SimpleCredentials("admin",
"admin".toCharArray()));
+ }
+
+ private static void safeLogout(Session session) {
+ try {
+ session.logout();
+ } catch (Exception ignore) {}
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferenceBinaryIT.java
------------------------------------------------------------------------------
svn:eol-style = native