use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class SideInputHandlerTest method testMultipleWindows.
@Test
public void testMultipleWindows() {
long view1WindowSize = 100;
PCollectionView<Iterable<String>> view1 = Pipeline.create().apply(Create.of("1")).apply(Window.into(FixedWindows.of(Duration.millis(view1WindowSize)))).apply(View.asIterable());
SideInputHandler sideInputHandler = new SideInputHandler(ImmutableList.of(view1), InMemoryStateInternals.<Void>forKey(null));
// two windows that we'll later use for adding elements/retrieving side input
IntervalWindow firstWindow = new IntervalWindow(new Instant(0), new Instant(view1WindowSize));
IntervalWindow secondWindow = new IntervalWindow(new Instant(view1WindowSize), new Instant(view1WindowSize * 2));
// add a first value for view1 in the first window
sideInputHandler.addSideInputValue(view1, valuesInWindow(materializeValuesFor(view1.getPipeline().getOptions(), View.asIterable(), "Hello"), new Instant(0), firstWindow));
assertThat(sideInputHandler.get(view1, firstWindow), contains("Hello"));
// add something for second window of view1
sideInputHandler.addSideInputValue(view1, valuesInWindow(materializeValuesFor(view1.getPipeline().getOptions(), View.asIterable(), "Arrivederci"), new Instant(0), secondWindow));
assertThat(sideInputHandler.get(view1, secondWindow), contains("Arrivederci"));
// contents for first window should be unaffected
assertThat(sideInputHandler.get(view1, firstWindow), contains("Hello"));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class SimplePushbackSideInputDoFnRunnerTest method processElementNoSideInputs.
@Test
public void processElementNoSideInputs() {
SimplePushbackSideInputDoFnRunner<Integer, Integer> runner = createRunner(ImmutableList.of());
WindowedValue<Integer> multiWindow = WindowedValue.of(2, new Instant(-2), ImmutableList.of(new IntervalWindow(new Instant(-500L), new Instant(0L)), new IntervalWindow(BoundedWindow.TIMESTAMP_MIN_VALUE, new Instant(250L)), GlobalWindow.INSTANCE), PaneInfo.ON_TIME_AND_ONLY_FIRING);
Iterable<WindowedValue<Integer>> multiWindowPushback = runner.processElementInReadyWindows(multiWindow);
assertThat(multiWindowPushback, emptyIterable());
// Should preserve the compressed representation when there's no side inputs.
assertThat(underlying.inputElems, containsInAnyOrder(multiWindow));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class SimplePushbackSideInputDoFnRunnerTest method processElementSideInputNotReady.
@Test
public void processElementSideInputNotReady() {
when(reader.isReady(Mockito.eq(singletonView), Mockito.any(BoundedWindow.class))).thenReturn(false);
SimplePushbackSideInputDoFnRunner<Integer, Integer> runner = createRunner(ImmutableList.of(singletonView));
WindowedValue<Integer> oneWindow = WindowedValue.of(2, new Instant(-2), new IntervalWindow(new Instant(-500L), new Instant(0L)), PaneInfo.ON_TIME_AND_ONLY_FIRING);
Iterable<WindowedValue<Integer>> oneWindowPushback = runner.processElementInReadyWindows(oneWindow);
assertThat(oneWindowPushback, containsInAnyOrder(oneWindow));
assertThat(underlying.inputElems, emptyIterable());
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class SimplePushbackSideInputDoFnRunnerTest method processElementSideInputNotReadySomeWindows.
@Test
public void processElementSideInputNotReadySomeWindows() {
when(reader.isReady(Mockito.eq(singletonView), Mockito.eq(GlobalWindow.INSTANCE))).thenReturn(false);
when(reader.isReady(Mockito.eq(singletonView), org.mockito.AdditionalMatchers.not(Mockito.eq(GlobalWindow.INSTANCE)))).thenReturn(true);
SimplePushbackSideInputDoFnRunner<Integer, Integer> runner = createRunner(ImmutableList.of(singletonView));
IntervalWindow littleWindow = new IntervalWindow(new Instant(-500L), new Instant(0L));
IntervalWindow bigWindow = new IntervalWindow(BoundedWindow.TIMESTAMP_MIN_VALUE, new Instant(250L));
WindowedValue<Integer> multiWindow = WindowedValue.of(2, new Instant(-2), ImmutableList.of(littleWindow, bigWindow, GlobalWindow.INSTANCE), PaneInfo.NO_FIRING);
Iterable<WindowedValue<Integer>> multiWindowPushback = runner.processElementInReadyWindows(multiWindow);
assertThat(multiWindowPushback, containsInAnyOrder(WindowedValue.timestampedValueInGlobalWindow(2, new Instant(-2L))));
assertThat(underlying.inputElems, containsInAnyOrder(WindowedValue.of(2, new Instant(-2), ImmutableList.of(littleWindow), PaneInfo.NO_FIRING), WindowedValue.of(2, new Instant(-2), ImmutableList.of(bigWindow), PaneInfo.NO_FIRING)));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class SimplePushbackSideInputDoFnRunnerTest method testOnTimerCalled.
/**
* Tests that a call to onTimer gets delegated.
*/
@Test
public void testOnTimerCalled() {
PushbackSideInputDoFnRunner<Integer, Integer> runner = createRunner(ImmutableList.of());
String timerId = "fooTimer";
IntervalWindow window = new IntervalWindow(new Instant(4), new Instant(16));
Instant timestamp = new Instant(72);
// Mocking is not easily compatible with annotation analysis, so we manually record
// the method call.
runner.onTimer(timerId, "", null, window, timestamp, timestamp, TimeDomain.EVENT_TIME);
assertThat(underlying.firedTimers, contains(TimerData.of(timerId, StateNamespaces.window(IntervalWindow.getCoder(), window), timestamp, timestamp, TimeDomain.EVENT_TIME)));
}
Aggregations