Refactor VersionGarbageCollector to extract Recommendations class - extract helper code into inner class, compute more time consts
@@ -233,19 +233,11 @@ public class VersionGCTest {
VersionGCOptions options = gc.getOptions();
final long oneYearAgo = ns.getClock().getTime() - TimeUnit.DAYS.toMillis(365);
final long twelveTimesTheLimit = options.collectLimit * 12;
+ final long secondsPerDay = TimeUnit.DAYS.toMillis(1);
- VersionGCSupport localgcsupport = new VersionGCSupport(ns.getDocumentStore()) {
- @Override
- public long getOldestDeletedOnceTimestamp(Clock clock, long precisionMs) {
- return oneYearAgo;
- }
- @Override
- public long getDeletedOnceCount() {
- return twelveTimesTheLimit;
- }
- };
+ VersionGCSupport localgcsupport = fakeVersionGCSupport(ns.getDocumentStore(), oneYearAgo, twelveTimesTheLimit);
- VersionGCRecommendations rec = new VersionGCRecommendations(86400L, ns.getCheckpoints(), ns.getClock(), localgcsupport,
+ VersionGCRecommendations rec = new VersionGCRecommendations(secondsPerDay, ns.getCheckpoints(), ns.getClock(), localgcsupport,
options, new TestGCMonitor());
// should select a duration of roughly one month
@@ -259,7 +251,7 @@ public class VersionGCTest {
rec.evaluate(stats);
assertTrue(stats.needRepeat);
- rec = new VersionGCRecommendations(86400L, ns.getCheckpoints(), ns.getClock(), localgcsupport, options,
+ rec = new VersionGCRecommendations(secondsPerDay, ns.getCheckpoints(), ns.getClock(), localgcsupport, options,
new TestGCMonitor());
// new duration should be half
@@ -403,4 +395,19 @@ public class VersionGCTest {
return this.statusMessages;
}
}
+
+ private VersionGCSupport fakeVersionGCSupport(final DocumentStore ds, final long oldestDeleted, final long countDeleted) {
+ return new VersionGCSupport(ds) {
+
+ @Override
+ public long getOldestDeletedOnceTimestamp(Clock clock, long precisionMs) {
+ return oldestDeleted;
+ }
+
+ @Override
+ public long getDeletedOnceCount() {
+ return countDeleted;
+ }
+ };
+ }
}
