use of org.joda.time.Instant 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.<PCollectionView<?>>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, Matchers.<WindowedValue<Integer>>emptyIterable());
}
use of org.joda.time.Instant in project beam by apache.
the class SplittableParDoProcessFnTest method testUpdatesWatermark.
@Test
public void testUpdatesWatermark() throws Exception {
DoFn<Instant, String> fn = new WatermarkUpdateFn();
Instant base = Instant.now();
ProcessFnTester<Instant, String, OffsetRange, OffsetRangeTracker> tester = new ProcessFnTester<>(base, fn, InstantCoder.of(), SerializableCoder.of(OffsetRange.class), 3, MAX_BUNDLE_DURATION);
tester.startElement(base, new OffsetRange(0, 8));
assertThat(tester.takeOutputElements(), hasItems("0", "1", "2"));
assertEquals(base.plus(Duration.standardSeconds(2)), tester.getWatermarkHold());
assertTrue(tester.advanceProcessingTimeBy(Duration.standardSeconds(1)));
assertThat(tester.takeOutputElements(), hasItems("3", "4", "5"));
assertEquals(base.plus(Duration.standardSeconds(5)), tester.getWatermarkHold());
assertTrue(tester.advanceProcessingTimeBy(Duration.standardSeconds(1)));
assertThat(tester.takeOutputElements(), hasItems("6", "7"));
assertEquals(null, tester.getWatermarkHold());
}
use of org.joda.time.Instant in project beam by apache.
the class SplittableParDoProcessFnTest method testCheckpointsAfterDuration.
@Test
public void testCheckpointsAfterDuration() throws Exception {
// Don't bound number of outputs.
int max = Integer.MAX_VALUE;
// But bound bundle duration - the bundle should terminate.
Duration maxBundleDuration = Duration.standardSeconds(1);
// Create an fn that attempts to 2x output more than checkpointing allows.
DoFn<Integer, String> fn = new CounterFn();
Instant base = Instant.now();
int baseIndex = 42;
ProcessFnTester<Integer, String, OffsetRange, OffsetRangeTracker> tester = new ProcessFnTester<>(base, fn, BigEndianIntegerCoder.of(), SerializableCoder.of(OffsetRange.class), max, maxBundleDuration);
List<String> elements;
tester.startElement(baseIndex, new OffsetRange(0, Long.MAX_VALUE));
// Bundle should terminate, and should do at least some processing.
elements = tester.takeOutputElements();
assertFalse(elements.isEmpty());
// Bundle should have run for at least the requested duration.
assertThat(Instant.now().getMillis() - base.getMillis(), greaterThanOrEqualTo(maxBundleDuration.getMillis()));
}
use of org.joda.time.Instant in project beam by apache.
the class TimerInternalsTest method testCompareTo.
@Test
public void testCompareTo() {
Instant firstTimestamp = new Instant(100);
Instant secondTimestamp = new Instant(200);
IntervalWindow firstWindow = new IntervalWindow(new Instant(0), firstTimestamp);
IntervalWindow secondWindow = new IntervalWindow(firstTimestamp, secondTimestamp);
Coder<IntervalWindow> windowCoder = IntervalWindow.getCoder();
StateNamespace firstWindowNs = StateNamespaces.window(windowCoder, firstWindow);
StateNamespace secondWindowNs = StateNamespaces.window(windowCoder, secondWindow);
TimerData firstEventTime = TimerData.of(firstWindowNs, firstTimestamp, TimeDomain.EVENT_TIME);
TimerData secondEventTime = TimerData.of(firstWindowNs, secondTimestamp, TimeDomain.EVENT_TIME);
TimerData thirdEventTime = TimerData.of(secondWindowNs, secondTimestamp, TimeDomain.EVENT_TIME);
TimerData firstProcTime = TimerData.of(firstWindowNs, firstTimestamp, TimeDomain.PROCESSING_TIME);
TimerData secondProcTime = TimerData.of(firstWindowNs, secondTimestamp, TimeDomain.PROCESSING_TIME);
TimerData thirdProcTime = TimerData.of(secondWindowNs, secondTimestamp, TimeDomain.PROCESSING_TIME);
assertThat(firstEventTime, comparesEqualTo(TimerData.of(firstWindowNs, firstTimestamp, TimeDomain.EVENT_TIME)));
assertThat(firstEventTime, lessThan(secondEventTime));
assertThat(secondEventTime, lessThan(thirdEventTime));
assertThat(firstEventTime, lessThan(thirdEventTime));
assertThat(secondProcTime, comparesEqualTo(TimerData.of(firstWindowNs, secondTimestamp, TimeDomain.PROCESSING_TIME)));
assertThat(firstProcTime, lessThan(secondProcTime));
assertThat(secondProcTime, lessThan(thirdProcTime));
assertThat(firstProcTime, lessThan(thirdProcTime));
assertThat(firstEventTime, not(comparesEqualTo(firstProcTime)));
assertThat(firstProcTime, not(comparesEqualTo(TimerData.of(firstWindowNs, firstTimestamp, TimeDomain.SYNCHRONIZED_PROCESSING_TIME))));
}
use of org.joda.time.Instant in project beam by apache.
the class TimerInternalsTest method testTimerDataCoder.
@Test
public void testTimerDataCoder() throws Exception {
CoderProperties.coderDecodeEncodeEqual(TimerDataCoder.of(GlobalWindow.Coder.INSTANCE), TimerData.of("arbitrary-id", StateNamespaces.global(), new Instant(0), TimeDomain.EVENT_TIME));
Coder<IntervalWindow> windowCoder = IntervalWindow.getCoder();
CoderProperties.coderDecodeEncodeEqual(TimerDataCoder.of(windowCoder), TimerData.of("another-id", StateNamespaces.window(windowCoder, new IntervalWindow(new Instant(0), new Instant(100))), new Instant(99), TimeDomain.PROCESSING_TIME));
}
Aggregations