Author: reschke
Date: Thu Jul  4 07:50:58 2019
New Revision: 1862537

URL: http://svn.apache.org/viewvc?rev=1862537&view=rev
Log:
OAK-8448: VersionGC may get stuck at 60s scope - add failing test case

Modified:
    
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCTest.java

Modified: 
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCTest.java?rev=1862537&r1=1862536&r2=1862537&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCTest.java
 Thu Jul  4 07:50:58 2019
@@ -44,6 +44,7 @@ import org.jetbrains.annotations.NotNull
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -259,6 +260,58 @@ public class VersionGCTest {
         assertTrue(nduration == duration / 2);
     }
 
+    // OAK-8448: test that after shrinking the scope to the minimum and after
+    // successful runs, scope will be expanded again
+    @Ignore("OAK-8448")
+    @Test
+    public void expandIntervalAgain() throws Exception {
+
+        VersionGCOptions options = gc.getOptions();
+        VersionGCRecommendations rec;
+        VersionGCStats stats;
+        VersionGCSupport localgcsupport;
+        GCMonitor testmonitor = new TestGCMonitor();
+
+        int days = 365;
+        long secondsPerDay = TimeUnit.DAYS.toMillis(1);
+        long oldestDeleted = ns.getClock().getTime() - 
TimeUnit.DAYS.toMillis(days);
+        // one per second
+        long deletedCount = TimeUnit.DAYS.toSeconds(days);
+
+        localgcsupport = fakeVersionGCSupport(ns.getDocumentStore(), 
oldestDeleted, deletedCount);
+
+        // loop until the recommended interval is at 60s (precisionMS)
+        do {
+            rec = new VersionGCRecommendations(secondsPerDay, 
ns.getCheckpoints(), ns.getClock(), localgcsupport, options,
+                    testmonitor);
+            stats = new VersionGCStats();
+            stats.limitExceeded = true;
+            rec.evaluate(stats);
+            assertTrue(stats.needRepeat);
+        } while (rec.suggestedIntervalMs > options.precisionMs);
+
+        // loop with successful runs (1 node/sec interval deleted) and observe 
the interval
+        int iterations = 0;
+        int maxiterations = 1000;
+        do {
+            iterations += 1;
+            oldestDeleted = rec.scope.fromMs + rec.scope.getDurationMs();
+            int deleted = (int) (rec.scope.getDurationMs() / 
TimeUnit.SECONDS.toMillis(1));
+            deletedCount -= deleted;
+            localgcsupport = fakeVersionGCSupport(ns.getDocumentStore(), 
oldestDeleted, deletedCount);
+            rec = new VersionGCRecommendations(secondsPerDay, 
ns.getCheckpoints(), ns.getClock(), localgcsupport, options,
+                    testmonitor);
+            stats = new VersionGCStats();
+            stats.limitExceeded = false;
+            stats.deletedDocGCCount = deleted;
+            stats.deletedLeafDocGCCount = 0;
+            rec.evaluate(stats);
+        } while (stats.needRepeat && iterations < maxiterations);
+
+        assertTrue("VersionGC should have finished after " + maxiterations + " 
iterations, but did not. Last scope was: "
+                + rec.scope + ".", !stats.needRepeat);
+    }
+
     // OAK-7378
     @Test
     public void recommendedInterval() throws Exception {


Reply via email to