OffsetRangeTracker implements RangeTracker<Long> { @Override public boolean tryReturnRecordAt(boolean isAtSplitPoint, Long recordStart) { return tryReturnRecordAt(isAtSplitPoint, recordStart.longValue()); } OffsetRangeTracker(long startOffset, long stopOffset); private  OffsetRangeTracker(); synchronized boolean isStarted(); synchronized boolean isDone(); @Override synchronized Long getStartPosition(); @Override synchronized Long getStopPosition(); @Override boolean tryReturnRecordAt(boolean isAtSplitPoint, Long recordStart); synchronized boolean tryReturnRecordAt(boolean isAtSplitPoint, long recordStart); @Override boolean trySplitAtPosition(Long splitOffset); synchronized boolean trySplitAtPosition(long splitOffset); synchronized long getPositionForFractionConsumed(double fraction); @Override synchronized double getFractionConsumed(); synchronized long getSplitPointsProcessed(); synchronized boolean markDone(); @Override synchronized String toString(); static final long OFFSET_INFINITY; }
@Test public void testTryReturnRecordSimpleSparse() throws Exception { OffsetRangeTracker tracker = new OffsetRangeTracker(100, 200); assertTrue(tracker.tryReturnRecordAt(true, 110)); assertTrue(tracker.tryReturnRecordAt(true, 140)); assertTrue(tracker.tryReturnRecordAt(true, 183)); assertFalse(tracker.tryReturnRecordAt(true, 210)); }
@Test public void testTryReturnRecordSimpleDense() throws Exception { OffsetRangeTracker tracker = new OffsetRangeTracker(3, 6); assertTrue(tracker.tryReturnRecordAt(true, 3)); assertTrue(tracker.tryReturnRecordAt(true, 4)); assertTrue(tracker.tryReturnRecordAt(true, 5)); assertFalse(tracker.tryReturnRecordAt(true, 6)); }
@Test public void testTryReturnRecordContinuesUntilSplitPoint() throws Exception { OffsetRangeTracker tracker = new OffsetRangeTracker(9, 18); assertTrue(tracker.tryReturnRecordAt(true, 10)); assertTrue(tracker.tryReturnRecordAt(false, 12)); assertTrue(tracker.tryReturnRecordAt(false, 14)); assertTrue(tracker.tryReturnRecordAt(true, 16)); assertTrue(tracker.tryReturnRecordAt(false, 18)); assertTrue(tracker.tryReturnRecordAt(false, 20)); assertFalse(tracker.tryReturnRecordAt(true, 22)); }
@Test public void testTryReturnFirstRecordNotSplitPoint() throws Exception { OffsetRangeTracker tracker = new OffsetRangeTracker(100, 200); expected.expect(IllegalStateException.class); tracker.tryReturnRecordAt(false, 120); }
@Test public void testTryReturnRecordNonMonotonic() throws Exception { OffsetRangeTracker tracker = new OffsetRangeTracker(100, 200); tracker.tryReturnRecordAt(true, 120); expected.expect(IllegalStateException.class); tracker.tryReturnRecordAt(true, 110); }