jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1583602 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStore.java test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStoreTest.java
Date Tue, 01 Apr 2014 10:43:34 GMT
Author: chetanm
Date: Tue Apr  1 10:43:34 2014
New Revision: 1583602

URL: http://svn.apache.org/r1583602
Log:
OAK-1656 - Provide lazy iterator for FileDataStore.getAllIdentifiers

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStoreTest.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStore.java?rev=1583602&r1=1583601&r2=1583602&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStore.java
Tue Apr  1 10:43:34 2014
@@ -19,8 +19,15 @@
 
 package org.apache.jackrabbit.oak.plugins.blob.datastore;
 
+import java.io.File;
+import java.util.Iterator;
+
 import com.google.common.base.Charsets;
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
 import com.google.common.io.BaseEncoding;
+import com.google.common.io.Files;
+import org.apache.jackrabbit.core.data.DataIdentifier;
 import org.apache.jackrabbit.core.data.DataStoreException;
 import org.apache.jackrabbit.core.data.FileDataStore;
 
@@ -32,6 +39,23 @@ public class OakFileDataStore extends Fi
     private byte[] referenceKey;
 
     @Override
+    public Iterator<DataIdentifier> getAllIdentifiers() {
+        return Files.fileTreeTraverser().postOrderTraversal(new File(getPath()))
+                .filter(new Predicate<File>() {
+                    @Override
+                    public boolean apply(File input) {
+                        return input.isFile();
+                    }
+                })
+                .transform(new Function<File, DataIdentifier>() {
+                    @Override
+                    public DataIdentifier apply(File input) {
+                        return new DataIdentifier(input.getName());
+                    }
+                }).iterator();
+    }
+
+    @Override
     protected byte[] getOrCreateReferenceKey() throws DataStoreException {
         if(referenceKey != null){
             return referenceKey;

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStoreTest.java?rev=1583602&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStoreTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStoreTest.java
Tue Apr  1 10:43:34 2014
@@ -0,0 +1,63 @@
+/*
+ * 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.blob.datastore;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.annotation.Nullable;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Sets;
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.core.data.DataIdentifier;
+import org.apache.jackrabbit.core.data.FileDataStore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class OakFileDataStoreTest {
+
+    @Test
+    public void testGetAllIdentifiers() throws Exception {
+        File testDir = new File("./target", "oak-fds-test");
+        FileUtils.touch(new File(testDir, "a"));
+        FileUtils.touch(new File(testDir, "b"));
+        FileUtils.touch(new File(testDir, "adir/c"));
+
+        FileDataStore fds = new OakFileDataStore();
+        fds.setPath(testDir.getAbsolutePath());
+        fds.init(null);
+
+        Iterator<DataIdentifier> dis = fds.getAllIdentifiers();
+        Set<String> fileNames = Sets.newHashSet(Iterators.transform(dis, new Function<DataIdentifier,
String>() {
+            @Override
+            public String apply(@Nullable DataIdentifier input) {
+                return input.toString();
+            }
+        }));
+
+        Set<String> expectedNames = Sets.newHashSet("a","b","c");
+        assertEquals(expectedNames, fileNames);
+        FileUtils.cleanDirectory(testDir);
+    }
+}

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



Mime
View raw message