List<OutputT> takeOutputElements() { return tester.takeOutputElements(); }
@Test public void processElementWithOutputTimestamp() throws Exception { try (DoFnTester<Long, String> tester = DoFnTester.of(new CounterDoFn())) { tester.processElement(1L); tester.processElement(2L); List<TimestampedValue<String>> peek = tester.peekOutputElementsWithTimestamp(); TimestampedValue<String> one = TimestampedValue.of("1", new Instant(1000L)); TimestampedValue<String> two = TimestampedValue.of("2", new Instant(2000L)); assertThat(peek, hasItems(one, two)); tester.processElement(3L); tester.processElement(4L); TimestampedValue<String> three = TimestampedValue.of("3", new Instant(3000L)); TimestampedValue<String> four = TimestampedValue.of("4", new Instant(4000L)); peek = tester.peekOutputElementsWithTimestamp(); assertThat(peek, hasItems(one, two, three, four)); List<TimestampedValue<String>> take = tester.takeOutputElementsWithTimestamp(); assertThat(take, hasItems(one, two, three, four)); // Following takeOutputElementsWithTimestamp(), neither takeOutputElementsWithTimestamp() // nor peekOutputElementsWithTimestamp() return anything. assertTrue(tester.takeOutputElementsWithTimestamp().isEmpty()); assertTrue(tester.peekOutputElementsWithTimestamp().isEmpty()); // peekOutputElements() and takeOutputElements() also return nothing. assertTrue(tester.peekOutputElements().isEmpty()); assertTrue(tester.takeOutputElements().isEmpty()); } }
/** @deprecated Use {@link TestPipeline} with the {@code DirectRunner}. */ @Deprecated public List<OutputT> processBundle(Iterable<? extends InputT> inputElements) throws Exception { startBundle(); for (InputT inputElement : inputElements) { processElement(inputElement); } finishBundle(); return takeOutputElements(); }
@Test public void processElement() throws Exception { for (DoFnTester.CloningBehavior cloning : DoFnTester.CloningBehavior.values()) { try (DoFnTester<Long, String> tester = DoFnTester.of(new CounterDoFn())) { tester.setCloningBehavior(cloning); tester.processElement(1L); List<String> take = tester.takeOutputElements(); assertThat(take, hasItems("1")); // Following takeOutputElements(), neither takeOutputElements() // nor peekOutputElements() return anything. assertTrue(tester.takeOutputElements().isEmpty()); assertTrue(tester.peekOutputElements().isEmpty()); } } }
@Test public void processTimestampedElement() throws Exception { try (DoFnTester<Long, TimestampedValue<Long>> tester = DoFnTester.of(new ReifyTimestamps())) { TimestampedValue<Long> input = TimestampedValue.of(1L, new Instant(100)); tester.processTimestampedElement(input); assertThat(tester.takeOutputElements(), contains(input)); } }
partitions = tester.takeOutputElements(multiPartitionsTag); } else { partitions = tester.takeOutputElements(singlePartitionTag);
assertThat(peek, hasItems("1", "2", "3", "4")); List<String> take = tester.takeOutputElements(); assertThat(take, hasItems("1", "2", "3", "4")); assertTrue(tester.takeOutputElements().isEmpty()); take = tester.takeOutputElements(); assertThat(take, hasItems("5", "6"));
doFnTester.takeOutputElements(outputForSizeTag), contains( KV.of( doFnTester.takeOutputElements(outputForEntrySetTag), contains( KV.of(