use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class SplittableParDoProcessFnTest method testTrivialProcessFnPropagatesOutputWindowAndTimestamp.
@Test
public void testTrivialProcessFnPropagatesOutputWindowAndTimestamp() throws Exception {
// Tests that ProcessFn correctly propagates the window and timestamp of the element
// inside the KeyedWorkItem.
// The underlying DoFn is actually monolithic, so this doesn't test splitting.
DoFn<Integer, String> fn = new ToStringFn();
Instant base = Instant.now();
IntervalWindow w = new IntervalWindow(base.minus(Duration.standardMinutes(1)), base.plus(Duration.standardMinutes(1)));
ProcessFnTester<Integer, String, SomeRestriction, Void, Void> tester = new ProcessFnTester<>(base, fn, BigEndianIntegerCoder.of(), SerializableCoder.of(SomeRestriction.class), VoidCoder.of(), MAX_OUTPUTS_PER_BUNDLE, MAX_BUNDLE_DURATION);
tester.startElement(WindowedValue.of(KV.of(42, new SomeRestriction()), base, Collections.singletonList(w), PaneInfo.ON_TIME_AND_ONLY_FIRING));
assertEquals(Arrays.asList(TimestampedValue.of("42a", base), TimestampedValue.of("42b", base), TimestampedValue.of("42c", base)), tester.peekOutputElementsInWindow(w));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class TimerInternalsTest method testTimerDataCoder.
@Test
public void testTimerDataCoder() throws Exception {
CoderProperties.coderDecodeEncodeEqual(TimerDataCoderV2.of(GlobalWindow.Coder.INSTANCE), TimerData.of("arbitrary-id", StateNamespaces.global(), new Instant(0), new Instant(0), TimeDomain.EVENT_TIME));
Coder<IntervalWindow> windowCoder = IntervalWindow.getCoder();
CoderProperties.coderDecodeEncodeEqual(TimerDataCoderV2.of(windowCoder), TimerData.of("another-id", StateNamespaces.window(windowCoder, new IntervalWindow(new Instant(0), new Instant(100))), new Instant(99), new Instant(99), TimeDomain.PROCESSING_TIME));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class TimerInternalsTest method testCompareByNamespace.
@Test
public void testCompareByNamespace() {
Instant timestamp = new Instant(100);
IntervalWindow firstWindow = new IntervalWindow(new Instant(0), timestamp);
IntervalWindow secondWindow = new IntervalWindow(timestamp, new Instant(200));
Coder<IntervalWindow> windowCoder = IntervalWindow.getCoder();
StateNamespace firstWindowNs = StateNamespaces.window(windowCoder, firstWindow);
StateNamespace secondWindowNs = StateNamespaces.window(windowCoder, secondWindow);
TimerData secondEventTime = TimerData.of(firstWindowNs, timestamp, timestamp, TimeDomain.EVENT_TIME);
TimerData thirdEventTime = TimerData.of(secondWindowNs, timestamp, timestamp, TimeDomain.EVENT_TIME);
assertThat(secondEventTime, lessThan(thirdEventTime));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class WindowMatchersTest method testIsWindowedValueExact.
@Test
public void testIsWindowedValueExact() {
long timestamp = 100;
long windowStart = 0;
long windowEnd = 200;
assertThat(WindowedValue.of("hello", new Instant(timestamp), new IntervalWindow(new Instant(windowStart), new Instant(windowEnd)), PaneInfo.NO_FIRING), WindowMatchers.isWindowedValue("hello", new Instant(timestamp), ImmutableList.of(new IntervalWindow(new Instant(windowStart), new Instant(windowEnd))), PaneInfo.NO_FIRING));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class AfterFirstStateMachineTest method testOnlyT1ShouldFireFixedWindows.
@Test
public void testOnlyT1ShouldFireFixedWindows() throws Exception {
tester = TriggerStateMachineTester.forTrigger(AfterFirstStateMachine.of(mockTrigger1, mockTrigger2), FixedWindows.of(Duration.millis(10)));
tester.injectElements(1);
IntervalWindow window = new IntervalWindow(new Instant(1), new Instant(11));
when(mockTrigger1.shouldFire(anyTriggerContext())).thenReturn(true);
when(mockTrigger2.shouldFire(anyTriggerContext())).thenReturn(false);
// should fire
assertTrue(tester.shouldFire(window));
tester.fireIfShouldFire(window);
assertTrue(tester.isMarkedFinished(window));
}
Aggregations