use of org.apache.beam.sdk.transforms.windowing.FixedWindows 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()));
}
use of org.apache.beam.sdk.transforms.windowing.FixedWindows 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)));
}
use of org.apache.beam.sdk.transforms.windowing.FixedWindows in project beam by apache.
the class TestStreamTest method testFirstElementLate.
@Test
@Category({ NeedsRunner.class, UsesTestStream.class })
public void testFirstElementLate() {
Instant lateElementTimestamp = new Instant(-1_000_000);
TestStream<String> stream = TestStream.create(StringUtf8Coder.of()).advanceWatermarkTo(new Instant(0)).addElements(TimestampedValue.of("late", lateElementTimestamp)).addElements(TimestampedValue.of("onTime", new Instant(100))).advanceWatermarkToInfinity();
FixedWindows windowFn = FixedWindows.of(Duration.millis(1000L));
Duration allowedLateness = Duration.millis(5000L);
PCollection<String> values = p.apply(stream).apply(Window.<String>into(windowFn).triggering(DefaultTrigger.of()).discardingFiredPanes().withAllowedLateness(allowedLateness)).apply(WithKeys.<Integer, String>of(1)).apply(GroupByKey.<Integer, String>create()).apply(Values.<Iterable<String>>create()).apply(Flatten.<String>iterables());
PAssert.that(values).inWindow(windowFn.assignWindow(lateElementTimestamp)).empty();
PAssert.that(values).inWindow(windowFn.assignWindow(new Instant(100))).containsInAnyOrder("onTime");
p.run();
}
use of org.apache.beam.sdk.transforms.windowing.FixedWindows in project beam by apache.
the class CreateStreamTest method testFirstElementLate.
@Test
public void testFirstElementLate() throws IOException {
Instant lateElementTimestamp = new Instant(-1_000_000);
CreateStream<String> source = CreateStream.of(StringUtf8Coder.of(), batchDuration()).emptyBatch().advanceWatermarkForNextBatch(new Instant(0)).nextBatch(TimestampedValue.of("late", lateElementTimestamp), TimestampedValue.of("onTime", new Instant(100))).advanceNextBatchWatermarkToInfinity();
FixedWindows windowFn = FixedWindows.of(Duration.millis(1000L));
Duration allowedLateness = Duration.millis(5000L);
PCollection<String> values = p.apply(source).apply(Window.<String>into(windowFn).triggering(DefaultTrigger.of()).discardingFiredPanes().withAllowedLateness(allowedLateness)).apply(WithKeys.<Integer, String>of(1)).apply(GroupByKey.<Integer, String>create()).apply(Values.<Iterable<String>>create()).apply(Flatten.<String>iterables());
PAssert.that(values).inWindow(windowFn.assignWindow(lateElementTimestamp)).empty();
PAssert.that(values).inWindow(windowFn.assignWindow(new Instant(100))).containsInAnyOrder("onTime");
p.run();
}
use of org.apache.beam.sdk.transforms.windowing.FixedWindows in project beam by apache.
the class CreateStreamTest method testElementsAtAlmostPositiveInfinity.
@Test
public void testElementsAtAlmostPositiveInfinity() throws IOException {
Instant endOfGlobalWindow = GlobalWindow.INSTANCE.maxTimestamp();
CreateStream<String> source = CreateStream.of(StringUtf8Coder.of(), batchDuration()).nextBatch(TimestampedValue.of("foo", endOfGlobalWindow), TimestampedValue.of("bar", endOfGlobalWindow)).advanceNextBatchWatermarkToInfinity();
FixedWindows windows = FixedWindows.of(Duration.standardHours(6));
PCollection<String> windowedValues = p.apply(source).apply(Window.<String>into(windows)).apply(WithKeys.<Integer, String>of(1)).apply(GroupByKey.<Integer, String>create()).apply(Values.<Iterable<String>>create()).apply(Flatten.<String>iterables());
PAssert.that(windowedValues).inWindow(windows.assignWindow(GlobalWindow.INSTANCE.maxTimestamp())).containsInAnyOrder("foo", "bar");
p.run();
}
Aggregations