Search in sources :

Example 11 with OffsetRange

use of org.apache.beam.sdk.io.range.OffsetRange in project beam by apache.

the class OffsetRangeTrackerTest method testCheckpointUnstarted.

@Test
public void testCheckpointUnstarted() throws Exception {
    OffsetRangeTracker tracker = new OffsetRangeTracker(new OffsetRange(100, 200));
    SplitResult res = tracker.trySplit(0);
    assertEquals(new OffsetRange(100, 100), res.getPrimary());
    assertEquals(new OffsetRange(100, 200), res.getResidual());
    tracker.checkDone();
}
Also used : OffsetRange(org.apache.beam.sdk.io.range.OffsetRange) Test(org.junit.Test)

Example 12 with OffsetRange

use of org.apache.beam.sdk.io.range.OffsetRange in project beam by apache.

the class OffsetRangeTrackerTest method testNonMonotonicClaim.

@Test
public void testNonMonotonicClaim() throws Exception {
    expected.expectMessage("Trying to claim offset 103 while last attempted was 110");
    OffsetRangeTracker tracker = new OffsetRangeTracker(new OffsetRange(100, 200));
    assertTrue(tracker.tryClaim(105L));
    assertTrue(tracker.tryClaim(110L));
    tracker.tryClaim(103L);
}
Also used : OffsetRange(org.apache.beam.sdk.io.range.OffsetRange) Test(org.junit.Test)

Example 13 with OffsetRange

use of org.apache.beam.sdk.io.range.OffsetRange in project beam by apache.

the class OffsetRangeTrackerTest method testBacklogUnstarted.

@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);
}
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 OffsetRange

use of org.apache.beam.sdk.io.range.OffsetRange in project beam by apache.

the class GrowableOffsetRangeTrackerTest method testSplitWithMaxEstimateRangeEnd.

@Test
public void testSplitWithMaxEstimateRangeEnd() throws Exception {
    SimpleEstimator simpleEstimator = new SimpleEstimator();
    GrowableOffsetRangeTracker tracker = new GrowableOffsetRangeTracker(0L, simpleEstimator);
    assertTrue(tracker.tryClaim(1L));
    simpleEstimator.setEstimateRangeEnd(Long.MAX_VALUE);
    SplitResult res = tracker.trySplit(0.5);
    long expectedEnd = 1L + (Long.MAX_VALUE - 1L) / 2;
    assertEquals(new OffsetRange(0L, expectedEnd), res.getPrimary());
    assertEquals(new OffsetRange(expectedEnd, Long.MAX_VALUE), res.getResidual());
}
Also used : OffsetRange(org.apache.beam.sdk.io.range.OffsetRange) Test(org.junit.Test)

Example 15 with OffsetRange

use of org.apache.beam.sdk.io.range.OffsetRange in project beam by apache.

the class GrowableOffsetRangeTrackerTest method testCheckpointBeforeStart.

@Test
public void testCheckpointBeforeStart() throws Exception {
    SimpleEstimator simpleEstimator = new SimpleEstimator();
    GrowableOffsetRangeTracker tracker = new GrowableOffsetRangeTracker(0L, simpleEstimator);
    simpleEstimator.setEstimateRangeEnd(10);
    SplitResult res = tracker.trySplit(0);
    tracker.checkDone();
    assertEquals(new OffsetRange(0, 0), res.getPrimary());
    assertEquals(new OffsetRange(0, 0), tracker.currentRestriction());
    assertEquals(new OffsetRange(0, Long.MAX_VALUE), res.getResidual());
}
Also used : OffsetRange(org.apache.beam.sdk.io.range.OffsetRange) Test(org.junit.Test)

Aggregations

OffsetRange (org.apache.beam.sdk.io.range.OffsetRange)63 Test (org.junit.Test)53 Instant (org.joda.time.Instant)8 ArrayList (java.util.ArrayList)5 OffsetRangeTracker (org.apache.beam.sdk.transforms.splittabledofn.OffsetRangeTracker)5 Progress (org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker.Progress)5 ProcessContinuation (org.apache.beam.sdk.transforms.DoFn.ProcessContinuation)4 PartitionMetadata (org.apache.beam.sdk.io.gcp.spanner.changestreams.model.PartitionMetadata)3 DoFn (org.apache.beam.sdk.transforms.DoFn)3 BigDecimal (java.math.BigDecimal)2 RestrictionTracker (org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker)2 Offset (com.google.cloud.pubsublite.Offset)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Scope (io.opencensus.common.Scope)1 AttributeValue (io.opencensus.trace.AttributeValue)1 Tracer (io.opencensus.trace.Tracer)1 Tracing (io.opencensus.trace.Tracing)1 Serializable (java.io.Serializable)1 Map (java.util.Map)1 Optional (java.util.Optional)1