Search in sources :

Example 56 with Instant

use of org.joda.time.Instant in project beam by apache.

the class UnboundedReadFromBoundedSourceTest method testReadFromCheckpointBeforeStart.

@Test
public void testReadFromCheckpointBeforeStart() throws Exception {
    thrown.expect(NoSuchElementException.class);
    BoundedSource<Long> countingSource = CountingSource.upTo(100);
    BoundedToUnboundedSourceAdapter<Long> unboundedSource = new BoundedToUnboundedSourceAdapter<>(countingSource);
    PipelineOptions options = PipelineOptionsFactory.create();
    List<TimestampedValue<Long>> elements = ImmutableList.of(TimestampedValue.of(1L, new Instant(1L)));
    Checkpoint<Long> checkpoint = new Checkpoint<>(elements, countingSource);
    unboundedSource.createReader(options, checkpoint).getCurrent();
}
Also used : Checkpoint(org.apache.beam.runners.core.construction.UnboundedReadFromBoundedSource.BoundedToUnboundedSourceAdapter.Checkpoint) TimestampedValue(org.apache.beam.sdk.values.TimestampedValue) BoundedToUnboundedSourceAdapter(org.apache.beam.runners.core.construction.UnboundedReadFromBoundedSource.BoundedToUnboundedSourceAdapter) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) Instant(org.joda.time.Instant) Test(org.junit.Test)

Example 57 with Instant

use of org.joda.time.Instant in project beam by apache.

the class LateDataUtilsTest method garbageCollectionTimeAfterEndOfGlobalWindow.

@Test
public void garbageCollectionTimeAfterEndOfGlobalWindow() {
    FixedWindows windowFn = FixedWindows.of(Duration.standardMinutes(5));
    WindowingStrategy<?, ?> strategy = WindowingStrategy.globalDefault().withWindowFn(windowFn);
    IntervalWindow window = windowFn.assignWindow(new Instant(BoundedWindow.TIMESTAMP_MAX_VALUE));
    assertThat(window.maxTimestamp(), Matchers.<ReadableInstant>greaterThan(GlobalWindow.INSTANCE.maxTimestamp()));
    assertThat(LateDataUtils.garbageCollectionTime(window, strategy), equalTo(GlobalWindow.INSTANCE.maxTimestamp()));
}
Also used : FixedWindows(org.apache.beam.sdk.transforms.windowing.FixedWindows) ReadableInstant(org.joda.time.ReadableInstant) Instant(org.joda.time.Instant) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow) Test(org.junit.Test)

Example 58 with Instant

use of org.joda.time.Instant in project beam by apache.

the class LateDataUtilsTest method beforeEndOfGlobalWindowSame.

@Test
public void beforeEndOfGlobalWindowSame() {
    FixedWindows windowFn = FixedWindows.of(Duration.standardMinutes(5));
    Duration allowedLateness = Duration.standardMinutes(2);
    WindowingStrategy<?, ?> strategy = WindowingStrategy.globalDefault().withWindowFn(windowFn).withAllowedLateness(allowedLateness);
    IntervalWindow window = windowFn.assignWindow(new Instant(10));
    assertThat(LateDataUtils.garbageCollectionTime(window, strategy), equalTo(window.maxTimestamp().plus(allowedLateness)));
}
Also used : FixedWindows(org.apache.beam.sdk.transforms.windowing.FixedWindows) ReadableInstant(org.joda.time.ReadableInstant) Instant(org.joda.time.Instant) Duration(org.joda.time.Duration) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow) Test(org.junit.Test)

Example 59 with Instant

use of org.joda.time.Instant in project beam by apache.

the class PaneInfoTracker method describePane.

private <W> PaneInfo describePane(Object key, Instant windowMaxTimestamp, PaneInfo previousPane, boolean isFinal) {
    boolean isFirst = previousPane == null;
    Timing previousTiming = isFirst ? null : previousPane.getTiming();
    long index = isFirst ? 0 : previousPane.getIndex() + 1;
    long nonSpeculativeIndex = isFirst ? 0 : previousPane.getNonSpeculativeIndex() + 1;
    Instant outputWM = timerInternals.currentOutputWatermarkTime();
    Instant inputWM = timerInternals.currentInputWatermarkTime();
    // True if it is not possible to assign the element representing this pane a timestamp
    // which will make an ON_TIME pane for any following computation.
    // Ie true if the element's latest possible timestamp is before the current output watermark.
    boolean isLateForOutput = outputWM != null && windowMaxTimestamp.isBefore(outputWM);
    // True if all emitted panes (if any) were EARLY panes.
    // Once the ON_TIME pane has fired, all following panes must be considered LATE even
    // if the output watermark is behind the end of the window.
    boolean onlyEarlyPanesSoFar = previousTiming == null || previousTiming == Timing.EARLY;
    // True is the input watermark hasn't passed the window's max timestamp.
    boolean isEarlyForInput = !inputWM.isAfter(windowMaxTimestamp);
    Timing timing;
    if (isLateForOutput || !onlyEarlyPanesSoFar) {
        // The output watermark has already passed the end of this window, or we have already
        // emitted a non-EARLY pane. Irrespective of how this pane was triggered we must
        // consider this pane LATE.
        timing = Timing.LATE;
    } else if (isEarlyForInput) {
        // This is an EARLY firing.
        timing = Timing.EARLY;
        nonSpeculativeIndex = -1;
    } else {
        // This is the unique ON_TIME firing for the window.
        timing = Timing.ON_TIME;
    }
    WindowTracing.debug("describePane: {} pane (prev was {}) for key:{}; windowMaxTimestamp:{}; " + "inputWatermark:{}; outputWatermark:{}; isLateForOutput:{}", timing, previousTiming, key, windowMaxTimestamp, inputWM, outputWM, isLateForOutput);
    if (previousPane != null) {
        // Timing transitions should follow EARLY* ON_TIME? LATE*
        switch(previousTiming) {
            case EARLY:
                checkState(timing == Timing.EARLY || timing == Timing.ON_TIME || timing == Timing.LATE, "EARLY cannot transition to %s", timing);
                break;
            case ON_TIME:
                checkState(timing == Timing.LATE, "ON_TIME cannot transition to %s", timing);
                break;
            case LATE:
                checkState(timing == Timing.LATE, "LATE cannot transtion to %s", timing);
                break;
            case UNKNOWN:
                break;
        }
        checkState(!previousPane.isLast(), "Last pane was not last after all.");
    }
    return PaneInfo.createPane(isFirst, isFinal, timing, index, nonSpeculativeIndex);
}
Also used : Instant(org.joda.time.Instant) Timing(org.apache.beam.sdk.transforms.windowing.PaneInfo.Timing)

Example 60 with Instant

use of org.joda.time.Instant in project beam by apache.

the class InMemoryTimerInternalsTest method testResetById.

@Test
public void testResetById() throws Exception {
    InMemoryTimerInternals underTest = new InMemoryTimerInternals();
    Instant earlyTimestamp = new Instant(13);
    Instant laterTimestamp = new Instant(42);
    underTest.advanceInputWatermark(new Instant(0));
    underTest.setTimer(NS1, ID1, earlyTimestamp, TimeDomain.EVENT_TIME);
    underTest.setTimer(NS1, ID1, laterTimestamp, TimeDomain.EVENT_TIME);
    underTest.advanceInputWatermark(earlyTimestamp.plus(1L));
    assertThat(underTest.removeNextEventTimer(), nullValue());
    underTest.advanceInputWatermark(laterTimestamp.plus(1L));
    assertThat(underTest.removeNextEventTimer(), equalTo(TimerData.of(ID1, NS1, laterTimestamp, TimeDomain.EVENT_TIME)));
}
Also used : Instant(org.joda.time.Instant) Test(org.junit.Test)

Aggregations

Instant (org.joda.time.Instant)411 Test (org.junit.Test)326 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)135 KV (org.apache.beam.sdk.values.KV)64 Category (org.junit.experimental.categories.Category)60 WindowedValue (org.apache.beam.sdk.util.WindowedValue)47 Duration (org.joda.time.Duration)44 ReadableInstant (org.joda.time.ReadableInstant)36 BoundedWindow (org.apache.beam.sdk.transforms.windowing.BoundedWindow)30 WatermarkHoldState (org.apache.beam.sdk.state.WatermarkHoldState)24 TimerData (org.apache.beam.runners.core.TimerInternals.TimerData)22 Matchers.emptyIterable (org.hamcrest.Matchers.emptyIterable)22 HashMap (java.util.HashMap)19 TransformWatermarks (org.apache.beam.runners.direct.WatermarkManager.TransformWatermarks)18 StateNamespaceForTest (org.apache.beam.runners.core.StateNamespaceForTest)17 WindowMatchers.isSingleWindowedValue (org.apache.beam.runners.core.WindowMatchers.isSingleWindowedValue)17 WindowMatchers.isWindowedValue (org.apache.beam.runners.core.WindowMatchers.isWindowedValue)17 TupleTag (org.apache.beam.sdk.values.TupleTag)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)12