use of org.joda.time.Instant in project beam by apache.
the class GatherAllPanesTest method singlePaneSingleReifiedPane.
@Test
@Category(NeedsRunner.class)
public void singlePaneSingleReifiedPane() {
PCollection<Iterable<ValueInSingleWindow<Iterable<Long>>>> accumulatedPanes = p.apply(GenerateSequence.from(0).to(20000)).apply(WithTimestamps.of(new SerializableFunction<Long, Instant>() {
@Override
public Instant apply(Long input) {
return new Instant(input * 10);
}
})).apply(Window.<Long>into(FixedWindows.of(Duration.standardMinutes(1))).triggering(AfterWatermark.pastEndOfWindow()).withAllowedLateness(Duration.ZERO).discardingFiredPanes()).apply(WithKeys.<Void, Long>of((Void) null).withKeyType(new TypeDescriptor<Void>() {
})).apply(GroupByKey.<Void, Long>create()).apply(Values.<Iterable<Long>>create()).apply(GatherAllPanes.<Iterable<Long>>globally());
PAssert.that(accumulatedPanes).satisfies(new SerializableFunction<Iterable<Iterable<ValueInSingleWindow<Iterable<Long>>>>, Void>() {
@Override
public Void apply(Iterable<Iterable<ValueInSingleWindow<Iterable<Long>>>> input) {
for (Iterable<ValueInSingleWindow<Iterable<Long>>> windowedInput : input) {
if (Iterables.size(windowedInput) > 1) {
fail("Expected all windows to have exactly one pane, got " + windowedInput);
return null;
}
}
return null;
}
});
p.run();
}
use of org.joda.time.Instant in project beam by apache.
the class CreateTest method testCreateTimestampedDefaultOutputCoderUsingCoder.
@Test
public void testCreateTimestampedDefaultOutputCoderUsingCoder() throws Exception {
Coder<Record> coder = new RecordCoder();
PBegin pBegin = PBegin.in(p);
Create.TimestampedValues<Record> values = Create.timestamped(TimestampedValue.of(new Record(), new Instant(0)), TimestampedValue.<Record>of(new Record2(), new Instant(0))).withCoder(coder);
Coder<Record> defaultCoder = values.getDefaultOutputCoder(pBegin);
assertThat(defaultCoder, equalTo(coder));
}
use of org.joda.time.Instant in project beam by apache.
the class CreateTest method testCreateTimestampedDefaultOutputCoderUsingTypeDescriptor.
@Test
public void testCreateTimestampedDefaultOutputCoderUsingTypeDescriptor() throws Exception {
Coder<Record> coder = new RecordCoder();
p.getCoderRegistry().registerCoderForClass(Record.class, coder);
PBegin pBegin = PBegin.in(p);
Create.TimestampedValues<Record> values = Create.timestamped(TimestampedValue.of(new Record(), new Instant(0)), TimestampedValue.<Record>of(new Record2(), new Instant(0))).withType(new TypeDescriptor<Record>() {
});
Coder<Record> defaultCoder = values.getDefaultOutputCoder(pBegin);
assertThat(defaultCoder, equalTo(coder));
}
use of org.joda.time.Instant in project beam by apache.
the class DistinctTest method testTriggeredDistinct.
@Test
@Category({ ValidatesRunner.class, UsesTestStream.class })
public void testTriggeredDistinct() {
Instant base = new Instant(0);
TestStream<String> values = TestStream.create(StringUtf8Coder.of()).advanceWatermarkTo(base).addElements(TimestampedValue.of("k1", base), TimestampedValue.of("k2", base.plus(Duration.standardSeconds(10))), TimestampedValue.of("k3", base.plus(Duration.standardSeconds(20)))).advanceProcessingTime(Duration.standardMinutes(1)).addElements(TimestampedValue.of("k1", base.plus(Duration.standardSeconds(30))), TimestampedValue.of("k2", base.plus(Duration.standardSeconds(40))), TimestampedValue.of("k3", base.plus(Duration.standardSeconds(50)))).advanceWatermarkToInfinity();
PCollection<String> distinctValues = triggeredDistinctPipeline.apply(values).apply(Window.<String>into(FixedWindows.of(Duration.standardMinutes(1))).triggering(Repeatedly.forever(AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.standardSeconds(30)))).withAllowedLateness(Duration.ZERO).accumulatingFiredPanes()).apply(Distinct.<String>create());
PAssert.that(distinctValues).containsInAnyOrder("k1", "k2", "k3");
triggeredDistinctPipeline.run();
}
use of org.joda.time.Instant in project beam by apache.
the class TestStreamTest method testFirstElementLate.
@Test
@Category({ NeedsRunner.class, UsesTestStream.class })
public void testFirstElementLate() {
Instant lateElementTimestamp = new Instant(-1_000_000);
TestStream<String> stream = TestStream.create(StringUtf8Coder.of()).advanceWatermarkTo(new Instant(0)).addElements(TimestampedValue.of("late", lateElementTimestamp)).addElements(TimestampedValue.of("onTime", new Instant(100))).advanceWatermarkToInfinity();
FixedWindows windowFn = FixedWindows.of(Duration.millis(1000L));
Duration allowedLateness = Duration.millis(5000L);
PCollection<String> values = p.apply(stream).apply(Window.<String>into(windowFn).triggering(DefaultTrigger.of()).discardingFiredPanes().withAllowedLateness(allowedLateness)).apply(WithKeys.<Integer, String>of(1)).apply(GroupByKey.<Integer, String>create()).apply(Values.<Iterable<String>>create()).apply(Flatten.<String>iterables());
PAssert.that(values).inWindow(windowFn.assignWindow(lateElementTimestamp)).empty();
PAssert.that(values).inWindow(windowFn.assignWindow(new Instant(100))).containsInAnyOrder("onTime");
p.run();
}
Aggregations