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 2016/10/18 14:44:59 UTC
svn commit: r1765449 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
Author: mreutegg
Date: Tue Oct 18 14:44:58 2016
New Revision: 1765449
URL: http://svn.apache.org/viewvc?rev=1765449&view=rev
Log:
OAK-2460: Resolve the base directory path of persistent cache against repository home
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1765449&r1=1765448&r2=1765449&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java Tue Oct 18 14:44:58 2016
@@ -44,8 +44,10 @@ import java.util.concurrent.TimeUnit;
import javax.sql.DataSource;
+import com.google.common.base.Strings;
import com.mongodb.MongoClientURI;
+import org.apache.commons.io.FilenameUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.ConfigurationPolicy;
@@ -421,8 +423,8 @@ public class DocumentNodeStoreService {
int childrenCachePercentage = toInteger(prop(PROP_CHILDREN_CACHE_PERCENTAGE), DEFAULT_CHILDREN_CACHE_PERCENTAGE);
int diffCachePercentage = toInteger(prop(PROP_DIFF_CACHE_PERCENTAGE), DEFAULT_DIFF_CACHE_PERCENTAGE);
int blobCacheSize = toInteger(prop(PROP_BLOB_CACHE_SIZE), DEFAULT_BLOB_CACHE_SIZE);
- String persistentCache = PropertiesUtil.toString(prop(PROP_PERSISTENT_CACHE), DEFAULT_PERSISTENT_CACHE);
- String journalCache = PropertiesUtil.toString(prop(PROP_JOURNAL_CACHE), DEFAULT_JOURNAL_CACHE);
+ String persistentCache = getPath(PROP_PERSISTENT_CACHE, DEFAULT_PERSISTENT_CACHE);
+ String journalCache = getPath(PROP_JOURNAL_CACHE, DEFAULT_JOURNAL_CACHE);
int cacheSegmentCount = toInteger(prop(PROP_CACHE_SEGMENT_COUNT), DEFAULT_CACHE_SEGMENT_COUNT);
int cacheStackMoveDistance = toInteger(prop(PROP_CACHE_STACK_MOVE_DISTANCE), DEFAULT_CACHE_STACK_MOVE_DISTANCE);
boolean prefetchExternalChanges = toBoolean(prop(PROP_PREFETCH_EXTERNAL_CHANGES), false);
@@ -461,10 +463,10 @@ public class DocumentNodeStoreService {
}).
setPrefetchExternalChanges(prefetchExternalChanges);
- if (persistentCache != null && persistentCache.length() > 0) {
+ if (!Strings.isNullOrEmpty(persistentCache)) {
mkBuilder.setPersistentCache(persistentCache);
}
- if (journalCache != null && journalCache.length() > 0) {
+ if (!Strings.isNullOrEmpty(journalCache)) {
mkBuilder.setJournalCache(journalCache);
}
@@ -861,14 +863,27 @@ public class DocumentNodeStoreService {
true/*runOnSingleClusterNode*/, true /*use dedicated pool*/));
}
- private Object prop(String propName) {
+ private String prop(String propName) {
return prop(propName, PREFIX + propName);
}
- private Object prop(String propName, String fwkPropName) {
+ private String prop(String propName, String fwkPropName) {
return lookupFrameworkThenConfiguration(context, propName, fwkPropName);
}
+ private String getPath(String propName, String defaultValue) {
+ String path = PropertiesUtil.toString(prop(propName), defaultValue);
+ if (Strings.isNullOrEmpty(path)) {
+ return path;
+ }
+ // resolve as relative to repository.home if available
+ String repoHome = prop(PROP_HOME);
+ if (!Strings.isNullOrEmpty(repoHome)) {
+ path = FilenameUtils.concat(repoHome, path);
+ }
+ return path;
+ }
+
private static String[] getMetadata(DocumentStore ds) {
Map<String, String> meta = new HashMap<String, String>(ds.getMetadata());
meta.put("nodeStoreType", "document");
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java?rev=1765449&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java Tue Oct 18 14:44:58 2016
@@ -0,0 +1,93 @@
+/*
+ * 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.File;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+public class DocumentNodeStoreServiceTest {
+
+ @Rule
+ public final OsgiContext context = new OsgiContext();
+
+ @Rule
+ public final TemporaryFolder target = new TemporaryFolder(new File("target"));
+
+ private final DocumentNodeStoreService service = new DocumentNodeStoreService();
+
+ private String repoHome;
+
+ @Before
+ public void setUp() throws Exception {
+ assumeTrue(MongoUtils.isAvailable());
+ context.registerService(StatisticsProvider.class, StatisticsProvider.NOOP);
+ repoHome = target.newFolder().getAbsolutePath();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ MockOsgi.deactivate(service);
+ MongoUtils.dropCollections(MongoUtils.DB);
+ }
+
+ @Test
+ public void persistentCache() {
+ String persistentCache = FilenameUtils.concat(repoHome, "cache");
+ assertPersistentCachePath(persistentCache, persistentCache, "");
+ }
+
+ @Test
+ public void persistentCacheWithRepositoryHome() {
+ assertPersistentCachePath(FilenameUtils.concat(repoHome, "cache"),
+ "cache", repoHome);
+ }
+
+ private void assertPersistentCachePath(String expectedPath,
+ String persistentCache,
+ String repoHome) {
+ MockOsgi.injectServices(service, context.bundleContext());
+
+ assertFalse(new File(expectedPath).exists());
+
+ Map<String, Object> config = Maps.newHashMap();
+ config.put("repository.home", repoHome);
+ config.put("persistentCache", persistentCache);
+ config.put("db", MongoUtils.DB);
+ MockOsgi.activate(service, context.bundleContext(), config);
+
+ assertNotNull(context.getService(NodeStore.class));
+ assertTrue(new File(expectedPath).exists());
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native