use of org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress in project beam by apache.
the class GrowableOffsetRangeTrackerTest method testLargeRange.
@Test
public void testLargeRange() throws Exception {
SimpleEstimator simpleEstimator = new SimpleEstimator();
GrowableOffsetRangeTracker tracker = new GrowableOffsetRangeTracker(Long.MIN_VALUE, simpleEstimator);
simpleEstimator.setEstimateRangeEnd(Long.MAX_VALUE);
Progress progress = tracker.getProgress();
assertEquals(0, progress.getWorkCompleted(), 0.001);
assertEquals(BigDecimal.valueOf(Long.MAX_VALUE).subtract(BigDecimal.valueOf(Long.MIN_VALUE), MathContext.DECIMAL128).doubleValue(), progress.getWorkRemaining(), 0.001);
simpleEstimator.setEstimateRangeEnd(Long.MIN_VALUE);
SplitResult res = tracker.trySplit(0);
assertEquals(new OffsetRange(Long.MIN_VALUE, Long.MIN_VALUE), res.getPrimary());
assertEquals(new OffsetRange(Long.MIN_VALUE, Long.MAX_VALUE), res.getResidual());
}
use of org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress in project beam by apache.
the class GrowableOffsetRangeTrackerTest method testProgressAfterFinished.
@Test
public void testProgressAfterFinished() throws Exception {
SimpleEstimator simpleEstimator = new SimpleEstimator();
GrowableOffsetRangeTracker tracker = new GrowableOffsetRangeTracker(10L, simpleEstimator);
assertFalse(tracker.tryClaim(Long.MAX_VALUE));
tracker.checkDone();
simpleEstimator.setEstimateRangeEnd(0L);
Progress currentProgress = tracker.getProgress();
assertEquals(Long.MAX_VALUE - 10L, currentProgress.getWorkCompleted(), 0);
assertEquals(0, currentProgress.getWorkRemaining(), 0.001);
}
use of org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress in project beam by apache.
the class OffsetRangeTrackerTest method testBacklogPartiallyCompleted.
@Test
public void testBacklogPartiallyCompleted() {
OffsetRangeTracker tracker = new OffsetRangeTracker(new OffsetRange(0, 200));
tracker.tryClaim(150L);
Progress progress = tracker.getProgress();
assertEquals(150, progress.getWorkCompleted(), 0.001);
assertEquals(50, progress.getWorkRemaining(), 0.001);
tracker = new OffsetRangeTracker(new OffsetRange(100, 200));
tracker.tryClaim(150L);
progress = tracker.getProgress();
assertEquals(50, progress.getWorkCompleted(), 0.001);
assertEquals(50, progress.getWorkRemaining(), 0.001);
}
use of org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress in project beam by apache.
the class ByteKeyRangeTrackerTest method testBacklogPartiallyCompleted.
@Test
public void testBacklogPartiallyCompleted() {
ByteKeyRangeTracker tracker = ByteKeyRangeTracker.of(ByteKeyRange.ALL_KEYS);
tracker.tryClaim(ByteKey.of(0xa0));
Progress progress = tracker.getProgress();
assertEquals(0.625, progress.getWorkCompleted(), 0.001);
assertEquals(0.375, progress.getWorkRemaining(), 0.001);
tracker = ByteKeyRangeTracker.of(ByteKeyRange.of(ByteKey.of(0x40), ByteKey.of(0xc0)));
tracker.tryClaim(ByteKey.of(0xa0));
progress = tracker.getProgress();
assertEquals(0.75, progress.getWorkCompleted(), 0.001);
assertEquals(0.25, progress.getWorkRemaining(), 0.001);
}
Aggregations