Author: mreutegg
Date: Tue Aug  8 12:43:22 2017
New Revision: 1804410

URL: http://svn.apache.org/viewvc?rev=1804410&view=rev
Log:
OAK-6530: Expose last RGC result via Supplier

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.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=1804410&r1=1804409&r2=1804410&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 Aug  8 12:43:22 2017
@@ -53,6 +53,7 @@ import javax.sql.DataSource;
 import com.google.common.base.Strings;
 import com.google.common.base.Supplier;
 import com.google.common.io.Closer;
+import com.google.common.util.concurrent.UncheckedExecutionException;
 import com.mongodb.MongoClientURI;
 
 import org.apache.commons.io.FilenameUtils;
@@ -1071,11 +1072,12 @@ public class DocumentNodeStoreService {
         };
     }
 
-    static final class RevisionGCJob implements Runnable {
+    static final class RevisionGCJob implements Runnable, Supplier<String> {
 
         private final DocumentNodeStore nodeStore;
         private final long versionGcMaxAgeInSecs;
         private final Logger log;
+        private volatile Object lastResult = "";
 
         RevisionGCJob(DocumentNodeStore ns,
                       long versionGcMaxAgeInSecs,
@@ -1089,10 +1091,26 @@ public class DocumentNodeStoreService {
         public void run() {
             VersionGarbageCollector gc = 
nodeStore.getVersionGarbageCollector();
             try {
-                gc.gc(versionGcMaxAgeInSecs, TimeUnit.SECONDS);
-            } catch (IOException e) {
+                lastResult = gc.gc(versionGcMaxAgeInSecs, 
TimeUnit.SECONDS).toString();
+            } catch (Exception e) {
+                lastResult = e;
                 log.warn("Error occurred while executing the Version Garbage 
Collector", e);
             }
         }
+
+        /**
+         * Returns the result of the last revision GC run. This method throws
+         * an {@link UncheckedExecutionException} if the last run failed with 
an
+         * exception.
+         *
+         * @return result of the last revision GC run.
+         */
+        @Override
+        public String get() throws UncheckedExecutionException {
+            if (lastResult instanceof Exception) {
+                throw new UncheckedExecutionException((Exception) lastResult);
+            }
+            return String.valueOf(lastResult);
+        }
     }
 }

Modified: 
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=1804410&r1=1804409&r2=1804410&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreServiceTest.java
 Tue Aug  8 12:43:22 2017
@@ -20,6 +20,7 @@ import java.io.File;
 import java.lang.reflect.Field;
 import java.util.Map;
 
+import com.google.common.base.Supplier;
 import com.google.common.collect.Maps;
 import com.mongodb.DB;
 
@@ -172,6 +173,22 @@ public class DocumentNodeStoreServiceTes
         assertTrue(jobScheduled);
     }
 
+    @Test
+    public void continuousRGCJobAsSupplier() throws Exception {
+        Map<String, Object> config = newConfig(repoHome);
+        config.put(DocumentNodeStoreService.PROP_VER_GC_CONTINUOUS, true);
+        MockOsgi.activate(service, context.bundleContext(), config);
+        Runnable rgcJob = null;
+        for (Runnable r : context.getServices(Runnable.class, null)) {
+            if 
(r.getClass().equals(DocumentNodeStoreService.RevisionGCJob.class)) {
+                rgcJob = r;
+            }
+        }
+        assertNotNull(rgcJob);
+        assertTrue(rgcJob instanceof Supplier);
+        assertNotNull(((Supplier) rgcJob).get());
+    }
+
     private static MongoDocumentStore getMongoDocumentStore(DocumentNodeStore 
s) {
         try {
             Field f = s.getClass().getDeclaredField("nonLeaseCheckingStore");


Reply via email to