jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1583594 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java
Date Tue, 01 Apr 2014 10:14:04 GMT
Author: chetanm
Date: Tue Apr  1 10:14:04 2014
New Revision: 1583594

URL: http://svn.apache.org/r1583594
Log:
OAK-1655 - DataStoreBlobStore does not take into maxLastModifiedTime when fetching all chunks

Fixed it by filtering the DataRecord base don there modifiedTime

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java?rev=1583594&r1=1583593&r2=1583594&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStore.java
Tue Apr  1 10:14:04 2014
@@ -32,6 +32,7 @@ import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
 
 import com.google.common.base.Function;
+import com.google.common.base.Predicate;
 import com.google.common.collect.Iterators;
 import com.google.common.io.ByteStreams;
 import com.google.common.io.Closeables;
@@ -47,6 +48,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Iterators.filter;
+import static com.google.common.collect.Iterators.transform;
 
 /**
  * BlobStore wrapper for DataStore. Wraps Jackrabbit 2 DataStore and expose them as BlobStores
@@ -258,12 +261,23 @@ public class DataStoreBlobStore implemen
     }
 
     @Override
-    public Iterator<String> getAllChunkIds(long maxLastModifiedTime) throws Exception
{
-        //TODO Ignores the maxLastModifiedTime currently.
-        return Iterators.transform(delegate.getAllIdentifiers(), new Function<DataIdentifier,
String>() {
-            @Nullable
+    public Iterator<String> getAllChunkIds(final long maxLastModifiedTime) throws Exception
{
+        return transform(filter(delegate.getAllIdentifiers(), new Predicate<DataIdentifier>()
{
             @Override
-            public String apply(@Nullable DataIdentifier input) {
+            public boolean apply(DataIdentifier input) {
+                try {
+                    DataRecord dr = delegate.getRecord(input);
+                    if(dr != null && dr.getLastModified() < maxLastModifiedTime){
+                        return true;
+                    }
+                } catch (DataStoreException e) {
+                    log.warn("Error occurred while fetching DataRecord for identifier {}",input,
e);
+                }
+                return false;
+            }
+        }),new Function<DataIdentifier, String>() {
+            @Override
+            public String apply(DataIdentifier input) {
                 return input.toString();
             }
         });

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java?rev=1583594&r1=1583593&r2=1583594&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/DataStoreBlobStoreTest.java
Tue Apr  1 10:14:04 2014
@@ -22,8 +22,13 @@ package org.apache.jackrabbit.oak.plugin
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Random;
+import java.util.Set;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Sets;
 import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.core.data.DataIdentifier;
 import org.apache.jackrabbit.core.data.DataRecord;
@@ -122,6 +127,26 @@ public class DataStoreBlobStoreTest {
         assertNull(ds.getReference(inMemBlobId));
     }
 
+    @Test
+    public void testGetAllChunks() throws Exception{
+        DataIdentifier d10 = new DataIdentifier("d-10");
+        DataIdentifier d20 = new DataIdentifier("d-20");
+        DataIdentifier d30 = new DataIdentifier("d-30");
+        List<DataIdentifier> dis = ImmutableList.of(d10, d20, d30);
+
+        DataStore mockedDS = mock(DataStore.class);
+        when(mockedDS.getAllIdentifiers()).thenReturn(dis.iterator());
+        when(mockedDS.getRecord(new DataIdentifier("d-10"))).thenReturn(new TimeDataRecord(d10));
+        when(mockedDS.getRecord(new DataIdentifier("d-20"))).thenReturn(new TimeDataRecord(d20));
+        when(mockedDS.getRecord(new DataIdentifier("d-30"))).thenReturn(new TimeDataRecord(d30));
+        DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS);
+
+        Iterator<String> chunks = ds.getAllChunkIds(25);
+        Set<String> expected = Sets.newHashSet("d-10","d-20");
+        assertEquals(expected, Sets.newHashSet(chunks));
+
+    }
+
     private static class ByteArrayDataRecord implements DataRecord {
         private final byte[] data;
         private final DataIdentifier identifier;
@@ -158,4 +183,37 @@ public class DataStoreBlobStoreTest {
             return 0;
         }
     }
+
+    private static class TimeDataRecord implements DataRecord {
+        private final DataIdentifier id;
+
+        private TimeDataRecord(DataIdentifier id) {
+            this.id = id;
+        }
+
+        @Override
+        public DataIdentifier getIdentifier() {
+            return id;
+        }
+
+        @Override
+        public String getReference() {
+            return id.toString();
+        }
+
+        @Override
+        public long getLength() throws DataStoreException {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public InputStream getStream() throws DataStoreException {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public long getLastModified() {
+            return Long.valueOf(id.toString().substring(id.toString().indexOf('-')+1));
+        }
+    }
 }



Mime
View raw message