use of org.apache.beam.sdk.transforms.windowing.FixedWindows in project beam by apache.
the class ParDoTest method testWindowingInStartAndFinishBundle.
@Test
@Category(ValidatesRunner.class)
public void testWindowingInStartAndFinishBundle() {
final FixedWindows windowFn = FixedWindows.of(Duration.millis(1));
PCollection<String> output = pipeline.apply(Create.timestamped(TimestampedValue.of("elem", new Instant(1)))).apply(Window.<String>into(windowFn)).apply(ParDo.of(new DoFn<String, String>() {
@ProcessElement
public void processElement(ProcessContext c) {
c.output(c.element());
System.out.println("Process: " + c.element() + ":" + c.timestamp().getMillis());
}
@FinishBundle
public void finishBundle(FinishBundleContext c) {
Instant ts = new Instant(3);
c.output("finish", ts, windowFn.assignWindow(ts));
System.out.println("Finish: 3");
}
})).apply(ParDo.of(new PrintingDoFn()));
PAssert.that(output).satisfies(new Checker());
pipeline.run();
}
Aggregations