Author: chetanm
Date: Thu Aug 10 08:41:38 2017
New Revision: 1804641

URL: http://svn.apache.org/viewvc?rev=1804641&view=rev
Log:
OAK-6524 - Provide an extension point to customize the NodeStore builders

Added:
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentBuilderCustomizer.java
   (with props)
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/FileStoreBuilderCustomizer.java
   (with props)
    
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureTest.java
      - copied, changed from r1804638, 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureTest.java
Modified:
    jackrabbit/oak/trunk/oak-run/pom.xml
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java
    
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureProvider.java
    
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureTest.java

Modified: jackrabbit/oak/trunk/oak-run/pom.xml
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/pom.xml?rev=1804641&r1=1804640&r2=1804641&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-run/pom.xml Thu Aug 10 08:41:38 2017
@@ -371,6 +371,12 @@
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>1.10.19</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <profiles>

Added: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentBuilderCustomizer.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentBuilderCustomizer.java?rev=1804641&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentBuilderCustomizer.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentBuilderCustomizer.java
 Thu Aug 10 08:41:38 2017
@@ -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.oak.run.cli;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+
+/**
+ * Extension point which needs to be registered with the Whiteboard
+ * attached to Options
+ */
+public interface DocumentBuilderCustomizer {
+
+    void customize(DocumentMK.Builder builder) throws IOException;
+}

Propchange: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentBuilderCustomizer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java?rev=1804641&r1=1804640&r2=1804641&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureProvider.java
 Thu Aug 10 08:41:38 2017
@@ -19,7 +19,7 @@
 
 package org.apache.jackrabbit.oak.run.cli;
 
-import java.net.UnknownHostException;
+import java.io.IOException;
 
 import javax.sql.DataSource;
 
@@ -46,10 +46,15 @@ class DocumentFixtureProvider {
                                          BlobStore blobStore,
                                          Whiteboard wb,
                                          Closer closer,
-                                         boolean readOnly) throws 
UnknownHostException {
+                                         boolean readOnly) throws IOException {
         DocumentMK.Builder builder = new DocumentMK.Builder();
         StatisticsProvider statisticsProvider = checkNotNull(getService(wb, 
StatisticsProvider.class));
 
+        DocumentBuilderCustomizer customizer = getService(wb, 
DocumentBuilderCustomizer.class);
+        if (customizer != null) {
+            customizer.customize(builder);
+        }
+
         if (blobStore != null) {
             builder.setBlobStore(blobStore);
         }

Added: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/FileStoreBuilderCustomizer.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/FileStoreBuilderCustomizer.java?rev=1804641&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/FileStoreBuilderCustomizer.java
 (added)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/FileStoreBuilderCustomizer.java
 Thu Aug 10 08:41:38 2017
@@ -0,0 +1,29 @@
+/*
+ * 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.run.cli;
+
+import java.io.IOException;
+
+import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
+
+public interface FileStoreBuilderCustomizer {
+
+    void customize(FileStoreBuilder builder) throws IOException;
+}

Propchange: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/FileStoreBuilderCustomizer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureProvider.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureProvider.java?rev=1804641&r1=1804640&r2=1804641&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureProvider.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureProvider.java
 Thu Aug 10 08:41:38 2017
@@ -46,6 +46,11 @@ class SegmentTarFixtureProvider {
         String path = options.getOptionBean(CommonOptions.class).getStoreArg();
         FileStoreBuilder builder = fileStoreBuilder(new 
File(path)).withMaxFileSize(256);
 
+        FileStoreBuilderCustomizer customizer = getService(wb, 
FileStoreBuilderCustomizer.class);
+        if (customizer != null) {
+            customizer.customize(builder);
+        }
+
         if (blobStore != null) {
             builder.withBlobStore(blobStore);
         }

Copied: 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureTest.java
 (from r1804638, 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureTest.java)
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureTest.java?p2=jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureTest.java&p1=jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureTest.java&r1=1804638&r2=1804641&rev=1804641&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/DocumentFixtureTest.java
 Thu Aug 10 08:41:38 2017
@@ -16,31 +16,38 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.jackrabbit.oak.run.cli;
 
-import static 
org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
+package org.apache.jackrabbit.oak.run.cli;
 
-import java.io.File;
 import java.io.IOException;
 
 import joptsimple.OptionParser;
-import org.apache.jackrabbit.oak.segment.file.FileStore;
-import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
+import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
+import org.apache.jackrabbit.oak.plugins.document.MongoUtils;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
-import org.junit.Rule;
+import org.junit.Assume;
+import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
 
-public class SegmentTarFixtureTest {
-    @Rule
-    public TemporaryFolder folder = new TemporaryFolder(new File("target"));
+import static java.util.Collections.emptyMap;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class DocumentFixtureTest {
+
+    @BeforeClass
+    public static void checkMongoDbAvailable() {
+        Assume.assumeTrue(MongoUtils.isAvailable());
+    }
 
     @Test
-    public void testReadWrite() throws Exception {
-        try (NodeStoreFixture fixture = 
NodeStoreFixtureProvider.create(createSegmentOptions(folder.getRoot()), false)) 
{
+    public void documentNodeStore() throws Exception{
+        try (NodeStoreFixture fixture = 
NodeStoreFixtureProvider.create(createMongoOptions(), false)) {
             NodeStore store = fixture.getStore();
             NodeBuilder builder = store.getRoot().builder();
             builder.setChildNode("foo");
@@ -48,30 +55,22 @@ public class SegmentTarFixtureTest {
         }
     }
 
-    @Test(expected = UnsupportedOperationException.class)
-    public void testReadOnly()
-            throws Exception {
-        File directory = folder.getRoot();
-        createStoreAt(directory);
-
+    @Test
+    public void customizer() throws Exception{
+        Options o = createMongoOptions();
+        DocumentBuilderCustomizer customizer = 
mock(DocumentBuilderCustomizer.class);
+        o.getWhiteboard().register(DocumentBuilderCustomizer.class, 
customizer, emptyMap());
+        try (NodeStoreFixture fixture = NodeStoreFixtureProvider.create(o, 
false)) {
 
-        try (NodeStoreFixture fixture = 
NodeStoreFixtureProvider.create(createSegmentOptions(folder.getRoot()), true)) {
-            NodeStore s = fixture.getStore();
-            NodeBuilder builder = s.getRoot().builder();
-            builder.setChildNode("foo");
-            s.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
         }
-    }
 
-    private static void createStoreAt(File path) throws 
InvalidFileStoreVersionException, IOException {
-        FileStore store = fileStoreBuilder(path).build();
-        store.close();
+        verify(customizer, times(1)).customize(any(DocumentMK.Builder.class));
     }
 
-    private Options createSegmentOptions(File storePath) throws IOException {
+    private Options createMongoOptions() throws IOException {
         OptionParser parser = new OptionParser();
         Options opts = new Options().withDisableSystemExit();
-        opts.parseAndConfigure(parser, new String[] 
{storePath.getAbsolutePath()});
+        opts.parseAndConfigure(parser, new String[] {MongoUtils.URL});
         return opts;
     }
 }

Modified: 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureTest.java?rev=1804641&r1=1804640&r2=1804641&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/SegmentTarFixtureTest.java
 Thu Aug 10 08:41:38 2017
@@ -18,13 +18,20 @@
  */
 package org.apache.jackrabbit.oak.run.cli;
 
+import static java.util.Collections.emptyMap;
 import static 
org.apache.jackrabbit.oak.segment.file.FileStoreBuilder.fileStoreBuilder;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Collections;
 
 import joptsimple.OptionParser;
 import org.apache.jackrabbit.oak.segment.file.FileStore;
+import org.apache.jackrabbit.oak.segment.file.FileStoreBuilder;
 import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
@@ -63,6 +70,18 @@ public class SegmentTarFixtureTest {
         }
     }
 
+    @Test
+    public void customizerCalled() throws Exception{
+        Options o = createSegmentOptions(folder.getRoot());
+        FileStoreBuilderCustomizer customizer = 
mock(FileStoreBuilderCustomizer.class);
+        o.getWhiteboard().register(FileStoreBuilderCustomizer.class, 
customizer, emptyMap());
+        try (NodeStoreFixture fixture = NodeStoreFixtureProvider.create(o, 
false)) {
+
+        }
+
+        verify(customizer, times(1)).customize(any(FileStoreBuilder.class));
+    }
+
     private static void createStoreAt(File path) throws 
InvalidFileStoreVersionException, IOException {
         FileStore store = fileStoreBuilder(path).build();
         store.close();


Reply via email to