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 ch...@apache.org on 2016/10/25 06:42:41 UTC

svn commit: r1766475 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/ oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/

Author: chetanm
Date: Tue Oct 25 06:42:41 2016
New Revision: 1766475

URL: http://svn.apache.org/viewvc?rev=1766475&view=rev
Log:
OAK-4862 - Provide a MemoryNodeStoreService

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreService.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreServiceTest.java   (with props)
    jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/MemoryNodeStoreConfigTest.groovy

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreService.java?rev=1766475&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreService.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreService.java Tue Oct 25 06:42:41 2016
@@ -0,0 +1,67 @@
+/*
+ * 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.memory;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.jackrabbit.oak.osgi.ObserverTracker;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+@Component(
+        policy = ConfigurationPolicy.REQUIRE,
+        label = "Apache Jackrabbit Oak Memory NodeStore Service",
+        description = "NodeStore implementation based on MemoryNodeStore. Any changes made with this store would not " +
+                "be persisted and would only be visible while system is running. This implementation can be used for " +
+                "testing purpose or in those setup where only transient storage is required."
+)
+public class MemoryNodeStoreService {
+    private ObserverTracker observerTracker;
+    private ServiceRegistration nodeStoreReg;
+
+    @Activate
+    private void activate(BundleContext context) {
+        MemoryNodeStore nodeStore = new MemoryNodeStore();
+        observerTracker = new ObserverTracker(nodeStore);
+        observerTracker.start(context);
+
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(Constants.SERVICE_DESCRIPTION, "NodeStore implementation based on MemoryNodeStore");
+        nodeStoreReg = context.registerService(NodeStore.class.getName(), nodeStore, props);
+    }
+
+    @Deactivate
+    private void deactivate() {
+        if (observerTracker != null) {
+            observerTracker.stop();
+        }
+
+        if (nodeStoreReg != null) {
+            nodeStoreReg.unregister();
+        }
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreServiceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreServiceTest.java?rev=1766475&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreServiceTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreServiceTest.java Tue Oct 25 06:42:41 2016
@@ -0,0 +1,76 @@
+/*
+ * 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.memory;
+
+import java.util.Collections;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
+import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.commit.Observer;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class MemoryNodeStoreServiceTest {
+    @Rule
+    public final OsgiContext context = new OsgiContext();
+
+    private MemoryNodeStoreService service = new MemoryNodeStoreService();
+
+    @Test
+    public void registration() throws Exception{
+        MockOsgi.activate(service, context.bundleContext(), Collections.<String, Object>emptyMap());
+        assertNotNull(context.getService(NodeStore.class));
+    }
+
+    @Test
+    public void observers() throws Exception{
+        MockOsgi.activate(service, context.bundleContext(), Collections.<String, Object>emptyMap());
+
+        final AtomicBoolean invoked = new AtomicBoolean();
+        Observer o = new Observer() {
+            @Override
+            public void contentChanged(@Nonnull NodeState root, @Nullable CommitInfo info) {
+                invoked.set(true);
+            }
+        };
+        context.registerService(Observer.class, o);
+
+        NodeStore store = context.getService(NodeStore.class);
+        NodeBuilder builder = store.getRoot().builder();
+        builder.child("a");
+        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+
+        assertTrue(invoked.get());
+
+    }
+
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStoreServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/MemoryNodeStoreConfigTest.groovy
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/MemoryNodeStoreConfigTest.groovy?rev=1766475&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/MemoryNodeStoreConfigTest.groovy (added)
+++ jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/MemoryNodeStoreConfigTest.groovy Tue Oct 25 06:42:41 2016
@@ -0,0 +1,44 @@
+/*
+ * 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.osgi
+
+import org.apache.jackrabbit.oak.spi.state.NodeStore
+import org.junit.Before
+import org.junit.Test
+
+import static org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory.REPOSITORY_CONFIG
+
+class MemoryNodeStoreConfigTest extends  AbstractRepositoryFactoryTest{
+
+    @Before
+    void setupRepo(){
+        config[REPOSITORY_CONFIG] = [
+                'org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStoreService' : [:],
+                'org.apache.jackrabbit.oak.jcr.osgi.RepositoryManager' : [:]
+        ]
+    }
+
+    @Test
+    void testMemoryNodeStore(){
+        repository = repositoryFactory.getRepository(config)
+        NodeStore ns = getServiceWithWait(NodeStore.class)
+        assert ns
+    }
+}