use of org.joda.time.Instant in project beam by apache.
the class ReduceFnRunnerTest method setGarbageCollectionHoldOnLateElements.
/**
* Late elements should still have a garbage collection hold set so that they
* can make a late pane rather than be dropped due to lateness.
*/
@Test
public void setGarbageCollectionHoldOnLateElements() throws Exception {
ReduceFnTester<Integer, Iterable<Integer>, IntervalWindow> tester = ReduceFnTester.nonCombining(WindowingStrategy.of(FixedWindows.of(Duration.millis(10))).withTrigger(AfterWatermark.pastEndOfWindow().withLateFirings(AfterPane.elementCountAtLeast(2))).withMode(AccumulationMode.DISCARDING_FIRED_PANES).withAllowedLateness(Duration.millis(100)).withClosingBehavior(ClosingBehavior.FIRE_IF_NON_EMPTY));
tester.advanceInputWatermark(new Instant(0));
tester.advanceOutputWatermark(new Instant(0));
tester.injectElements(TimestampedValue.of(1, new Instant(1)));
// Fire ON_TIME pane @ 9 with 1
tester.advanceInputWatermark(new Instant(109));
tester.advanceOutputWatermark(new Instant(109));
tester.injectElements(TimestampedValue.of(2, new Instant(2)));
// We should have set a garbage collection hold for the final pane.
Instant hold = tester.getWatermarkHold();
assertEquals(new Instant(109), hold);
tester.advanceInputWatermark(new Instant(110));
tester.advanceOutputWatermark(new Instant(110));
// Fire final LATE pane @ 9 with 2
List<WindowedValue<Iterable<Integer>>> output = tester.extractOutput();
assertEquals(2, output.size());
}
use of org.joda.time.Instant in project beam by apache.
the class SideInputHandlerTest method testMultipleSideInputs.
@Test
public void testMultipleSideInputs() {
SideInputHandler sideInputHandler = new SideInputHandler(ImmutableList.<PCollectionView<?>>of(view1, view2), 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(WINDOW_MSECS_1));
// add value for view1 in the first window
sideInputHandler.addSideInputValue(view1, valuesInWindow(ImmutableList.of("Hello"), new Instant(0), firstWindow));
Assert.assertThat(sideInputHandler.get(view1, firstWindow), contains("Hello"));
// view2 should not have any data
assertFalse(sideInputHandler.isReady(view2, firstWindow));
// also add some data for view2
sideInputHandler.addSideInputValue(view2, valuesInWindow(ImmutableList.of("Salut"), new Instant(0), firstWindow));
assertTrue(sideInputHandler.isReady(view2, firstWindow));
Assert.assertThat(sideInputHandler.get(view2, firstWindow), contains("Salut"));
// view1 should not be affected by that
Assert.assertThat(sideInputHandler.get(view1, firstWindow), contains("Hello"));
}
use of org.joda.time.Instant in project beam by apache.
the class SideInputHandlerTest method testMultipleWindows.
@Test
public void testMultipleWindows() {
SideInputHandler sideInputHandler = new SideInputHandler(ImmutableList.<PCollectionView<?>>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(WINDOW_MSECS_1));
IntervalWindow secondWindow = new IntervalWindow(new Instant(1000), new Instant(1000 + WINDOW_MSECS_2));
// add a first value for view1 in the first window
sideInputHandler.addSideInputValue(view1, valuesInWindow(ImmutableList.of("Hello"), new Instant(0), firstWindow));
Assert.assertThat(sideInputHandler.get(view1, firstWindow), contains("Hello"));
// add something for second window of view1
sideInputHandler.addSideInputValue(view1, valuesInWindow(ImmutableList.of("Arrivederci"), new Instant(0), secondWindow));
Assert.assertThat(sideInputHandler.get(view1, secondWindow), contains("Arrivederci"));
// contents for first window should be unaffected
Assert.assertThat(sideInputHandler.get(view1, firstWindow), contains("Hello"));
}
use of org.joda.time.Instant in project beam by apache.
the class SideInputHandlerTest method testIsReady.
@Test
public void testIsReady() {
SideInputHandler sideInputHandler = new SideInputHandler(ImmutableList.<PCollectionView<?>>of(view1, view2), InMemoryStateInternals.<Void>forKey(null));
IntervalWindow firstWindow = new IntervalWindow(new Instant(0), new Instant(WINDOW_MSECS_1));
IntervalWindow secondWindow = new IntervalWindow(new Instant(0), new Instant(WINDOW_MSECS_2));
// side input should not yet be ready
assertFalse(sideInputHandler.isReady(view1, firstWindow));
// add a value for view1
sideInputHandler.addSideInputValue(view1, valuesInWindow(ImmutableList.of("Hello"), new Instant(0), firstWindow));
// now side input should be ready
assertTrue(sideInputHandler.isReady(view1, firstWindow));
// second window input should still not be ready
assertFalse(sideInputHandler.isReady(view1, secondWindow));
}
use of org.joda.time.Instant in project beam by apache.
the class SimpleDoFnRunnerTest method testSkew.
/**
* Demonstrates that attempting to output an element before the timestamp of the current element
* plus the value of {@link DoFn#getAllowedTimestampSkew()} throws, but between that value and
* the current timestamp succeeds.
*/
@Test
public void testSkew() {
SkewingDoFn fn = new SkewingDoFn(Duration.standardMinutes(10L));
DoFnRunner<Duration, Duration> runner = new SimpleDoFnRunner<>(null, fn, NullSideInputReader.empty(), new ListOutputManager(), new TupleTag<Duration>(), Collections.<TupleTag<?>>emptyList(), mockStepContext, WindowingStrategy.of(new GlobalWindows()));
runner.startBundle();
// Outputting between "now" and "now - allowed skew" succeeds.
runner.processElement(WindowedValue.timestampedValueInGlobalWindow(Duration.standardMinutes(5L), new Instant(0)));
thrown.expect(UserCodeException.class);
thrown.expectCause(isA(IllegalArgumentException.class));
thrown.expectMessage("must be no earlier");
thrown.expectMessage(String.format("timestamp of the current input (%s)", new Instant(0).toString()));
thrown.expectMessage(String.format("the allowed skew (%s)", PeriodFormat.getDefault().print(Duration.standardMinutes(10L).toPeriod())));
// Outputting before "now - allowed skew" fails.
runner.processElement(WindowedValue.timestampedValueInGlobalWindow(Duration.standardHours(1L), new Instant(0)));
}
Aggregations