Search in sources :

Example 36 with IntervalWindow

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));
}
Also used : Instant(org.joda.time.Instant) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow) Test(org.junit.Test)

Example 37 with IntervalWindow

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));
}
Also used : Instant(org.joda.time.Instant) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow) Test(org.junit.Test)

Example 38 with IntervalWindow

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));
}
Also used : Instant(org.joda.time.Instant) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow) Test(org.junit.Test)

Example 39 with IntervalWindow

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));
}
Also used : Instant(org.joda.time.Instant) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow) Test(org.junit.Test)

Example 40 with IntervalWindow

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));
}
Also used : Instant(org.joda.time.Instant) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow) Test(org.junit.Test)

Aggregations

IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)238 Test (org.junit.Test)214 Instant (org.joda.time.Instant)213 WindowedValue (org.apache.beam.sdk.util.WindowedValue)67 BoundedWindow (org.apache.beam.sdk.transforms.windowing.BoundedWindow)56 KV (org.apache.beam.sdk.values.KV)56 Duration (org.joda.time.Duration)33 Matchers.emptyIterable (org.hamcrest.Matchers.emptyIterable)32 WindowMatchers.isSingleWindowedValue (org.apache.beam.runners.core.WindowMatchers.isSingleWindowedValue)20 WindowMatchers.isWindowedValue (org.apache.beam.runners.core.WindowMatchers.isWindowedValue)20 ArrayList (java.util.ArrayList)16 TupleTag (org.apache.beam.sdk.values.TupleTag)16 HashMap (java.util.HashMap)14 PCollectionView (org.apache.beam.sdk.values.PCollectionView)14 Category (org.junit.experimental.categories.Category)13 MetricsContainerImpl (org.apache.beam.runners.core.metrics.MetricsContainerImpl)12 FixedWindows (org.apache.beam.sdk.transforms.windowing.FixedWindows)12 ByteBuffer (java.nio.ByteBuffer)11 Map (java.util.Map)11 StringUtf8Coder (org.apache.beam.sdk.coders.StringUtf8Coder)11