Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/AbstractDataStoreService.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/AbstractDataStoreService.java (revision 1726939) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/AbstractDataStoreService.java (working copy) @@ -111,7 +111,7 @@ dataStore.close(); } - protected abstract DataStore createDataStore(ComponentContext context, Map config); + protected abstract DataStore createDataStore(ComponentContext context, Map config) throws RepositoryException; protected StatisticsProvider getStatisticsProvider(){ return statisticsProvider; Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/FileDataStoreService.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/FileDataStoreService.java (revision 1726939) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/FileDataStoreService.java (working copy) @@ -20,23 +20,57 @@ package org.apache.jackrabbit.oak.plugins.blob.datastore; import java.util.Map; +import java.util.Properties; +import aQute.bnd.maven.support.Repo; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.jackrabbit.core.data.CachingFDS; import org.apache.jackrabbit.core.data.DataStore; +import org.apache.jackrabbit.oak.commons.PropertiesUtil; import org.osgi.service.component.ComponentContext; +import javax.jcr.RepositoryException; + @Component(policy = ConfigurationPolicy.REQUIRE, name = FileDataStoreService.NAME) -public class FileDataStoreService extends AbstractDataStoreService{ +public class FileDataStoreService extends AbstractDataStoreService { public static final String NAME = "org.apache.jackrabbit.oak.plugins.blob.datastore.FileDataStore"; + public static final String DS_CACHE_PATH = "dsCachePath"; + public static final String DS_CACHE_SIZE = "dsCacheSize"; + public static final String FS_BACKEND_PATH = "fsBackendPath"; + public static final String PATH = "path"; + @Override - protected DataStore createDataStore(ComponentContext context, Map config) { - return new OakFileDataStore(); + protected DataStore createDataStore(ComponentContext context, Map config) throws RepositoryException { + + long dsCacheSize = PropertiesUtil.toLong(config.get(DS_CACHE_SIZE), 0L); + if (dsCacheSize > 0) { + String fsBackendPath = PropertiesUtil.toString(config.get(PATH), ""); + if ("".equals(fsBackendPath)) { + throw new RepositoryException("Cannot create FileDataStoreService with caching. [{path}] property not configured."); + } + CachingFDS dataStore = new CachingFDS(); + config.remove(PATH); + config.remove(DS_CACHE_SIZE); + config.put(FS_BACKEND_PATH, fsBackendPath); + config.put("cacheSize", dsCacheSize); + String cachePath = PropertiesUtil.toString(config.get(DS_CACHE_PATH), ""); + if (!"".equals(cachePath)) { + config.remove(DS_CACHE_PATH); + config.put(PATH, cachePath); + } + Properties properties = new Properties(); + properties.putAll(config); + dataStore.setProperties(properties); + return dataStore; + } else { + return new OakFileDataStore(); + } } @Override protected String[] getDescription() { - return new String[] {"type=filesystem"}; + return new String[]{"type=filesystem"}; } } Index: oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreServiceTest.java =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreServiceTest.java (revision 1726939) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreServiceTest.java (working copy) @@ -19,10 +19,16 @@ package org.apache.jackrabbit.oak.plugins.blob.datastore; +import java.lang.reflect.Field; +import java.util.HashMap; import java.util.Map; +import java.util.Properties; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import org.apache.jackrabbit.core.data.*; import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean; +import org.apache.jackrabbit.oak.commons.PropertiesUtil; import org.apache.jackrabbit.oak.spi.blob.stats.BlobStoreStatsMBean; import org.apache.jackrabbit.oak.stats.StatisticsProvider; import org.apache.sling.testing.mock.osgi.MockOsgi; @@ -31,7 +37,9 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class DataStoreServiceTest { @Rule @@ -54,4 +62,53 @@ assertNotNull(context.getService(CacheStatsMBean.class)); } + @Test + public void configCachingFDS() throws Exception { + String nasPath= folder.getRoot().getAbsolutePath() + "/NASPath"; + String cachePath = folder.getRoot().getAbsolutePath() + "/cachePath"; + long cacheSize = 100l; + Map config = new HashMap(); + config.put("repository.home", folder.getRoot().getAbsolutePath()); + config.put(FileDataStoreService.DS_CACHE_SIZE, cacheSize); + config.put(FileDataStoreService.PATH, nasPath); + config.put(FileDataStoreService.DS_CACHE_PATH, cachePath); + FileDataStoreService fdsSvc = new FileDataStoreService(); + + DataStore ds = fdsSvc.createDataStore(context.componentContext(), config); + PropertiesUtil.populate(ds, config, false); + ds.init(folder.getRoot().getAbsolutePath()); + assertTrue("not instance of CachingFDS", ds instanceof CachingFDS); + CachingFDS cds = (CachingFDS) ds; + assertEquals( "cachesize not equal", cacheSize, cds.getCacheSize()); + assertEquals( "cachepath not equal", cachePath, cds.getPath()); + Backend backend = cds.getBackend(); + Properties props = (Properties) getField(backend, "properties"); + assertEquals( "path not equal", nasPath, props.getProperty(FSBackend.FS_BACKEND_PATH)); + + + } + + @Test + public void configFileDataStore() throws Exception { + String nasPath= folder.getRoot().getAbsolutePath() + "/NASPath"; + String cachePath = folder.getRoot().getAbsolutePath() + "/cachePath"; + Map config = new HashMap(); + config.put("repository.home", folder.getRoot().getAbsolutePath()); + config.put(FileDataStoreService.PATH, nasPath); + config.put(FileDataStoreService.DS_CACHE_PATH, cachePath); + FileDataStoreService fdsSvc = new FileDataStoreService(); + + DataStore ds = fdsSvc.createDataStore(context.componentContext(), config); + PropertiesUtil.populate(ds, config, false); + ds.init(folder.getRoot().getAbsolutePath()); + assertTrue("not instance of FileDataStore", ds instanceof FileDataStore); + FileDataStore fds = (FileDataStore) ds; + assertEquals( "path not equal", nasPath, fds.getPath()); + } + + private static Object getField( Object obj, String fieldName) throws Exception { + Field f = obj.getClass().getDeclaredField(fieldName); //NoSuchFieldException + f.setAccessible(true); + return f.get(obj); + } } Index: oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/FileDataStoreServiceTest.java =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/FileDataStoreServiceTest.java (revision 0) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/FileDataStoreServiceTest.java (working copy) @@ -0,0 +1,7 @@ +package org.apache.jackrabbit.oak.plugins.blob.datastore; + +/** + * Created by shgupta on 27/01/16. + */ +public class FileDataStoreServiceTest { +}