Search in sources :

Example 11 with Progress

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());
}
Also used : OffsetRange(org.apache.beam.sdk.io.range.OffsetRange) Progress(org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress) Test(org.junit.Test)

Example 12 with Progress

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);
}
Also used : Progress(org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress) Test(org.junit.Test)

Example 13 with Progress

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);
}
Also used : OffsetRange(org.apache.beam.sdk.io.range.OffsetRange) Progress(org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress) Test(org.junit.Test)

Example 14 with Progress

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);
}
Also used : Progress(org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress) Test(org.junit.Test)

Aggregations

Progress (org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress)14 Test (org.junit.Test)13 OffsetRange (org.apache.beam.sdk.io.range.OffsetRange)5 HasProgress (org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.HasProgress)1 VisibleForTesting (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.annotations.VisibleForTesting)1