OffsetRangeTracker extends RestrictionTracker<OffsetRange, Long> implements HasProgress { @Override public Progress getProgress() { if (lastAttemptedOffset == null) { return Progress.from( 0, BigDecimal.valueOf(range.getTo()) .subtract(BigDecimal.valueOf(range.getFrom()), MathContext.DECIMAL128) .doubleValue()); } BigDecimal workRemaining = BigDecimal.valueOf(range.getTo()) .subtract(BigDecimal.valueOf(lastAttemptedOffset), MathContext.DECIMAL128) .max(BigDecimal.ZERO); BigDecimal totalWork = BigDecimal.valueOf(range.getTo()) .subtract(BigDecimal.valueOf(range.getFrom()), MathContext.DECIMAL128); return Progress.from( totalWork.subtract(workRemaining, MathContext.DECIMAL128).doubleValue(), workRemaining.doubleValue()); } OffsetRangeTracker(OffsetRange range); @Override OffsetRange currentRestriction(); @Override SplitResult<OffsetRange> trySplit(double fractionOfRemainder); @Override boolean tryClaim(Long i); @Override void checkDone(); @Override IsBounded isBounded(); @Override String toString(); @Override Progress getProgress();  }
@Test public void testBacklogUnstarted() { OffsetRangeTracker tracker = new OffsetRangeTracker(new OffsetRange(0, 200)); Progress progress = tracker.getProgress(); assertEquals(0, progress.getWorkCompleted(), 0.001); assertEquals(200, progress.getWorkRemaining(), 0.001); tracker = new OffsetRangeTracker(new OffsetRange(100, 200)); progress = tracker.getProgress(); assertEquals(0, progress.getWorkCompleted(), 0.001); assertEquals(100, progress.getWorkRemaining(), 0.001); }