/** @deprecated Use {@link TestPipeline} with the {@code DirectRunner}. */ @Deprecated public List<TimestampedValue<OutputT>> peekOutputElementsInWindow(BoundedWindow window) { return peekOutputElementsInWindow(mainOutputTag, window); }
List<TimestampedValue<OutputT>> peekOutputElementsInWindow(BoundedWindow window) { return tester.peekOutputElementsInWindow(window); }
@Test public void peekValuesInWindow() throws Exception { try (DoFnTester<Long, String> tester = DoFnTester.of(new CounterDoFn())) { tester.startBundle(); tester.processElement(1L); tester.processElement(2L); tester.finishBundle(); assertThat( tester.peekOutputElementsInWindow(GlobalWindow.INSTANCE), containsInAnyOrder( TimestampedValue.of("1", new Instant(1000L)), TimestampedValue.of("2", new Instant(2000L)))); assertThat( tester.peekOutputElementsInWindow(new IntervalWindow(new Instant(0L), new Instant(10L))), Matchers.emptyIterable()); } }
@Test public void testSupportsWindowParameter() throws Exception { Instant now = Instant.now(); try (DoFnTester<Integer, KV<Integer, BoundedWindow>> tester = DoFnTester.of(new DoFnWithWindowParameter())) { BoundedWindow firstWindow = new IntervalWindow(now, now.plus(Duration.standardMinutes(1))); tester.processWindowedElement(1, now, firstWindow); tester.processWindowedElement(2, now, firstWindow); BoundedWindow secondWindow = new IntervalWindow(now, now.plus(Duration.standardMinutes(4))); tester.processWindowedElement(3, now, secondWindow); tester.finishBundle(); assertThat( tester.peekOutputElementsInWindow(firstWindow), containsInAnyOrder( TimestampedValue.of(KV.of(1, firstWindow), now), TimestampedValue.of(KV.of(2, firstWindow), now))); assertThat( tester.peekOutputElementsInWindow(secondWindow), containsInAnyOrder(TimestampedValue.of(KV.of(3, secondWindow), now))); } }