/** * @param p pipeline. * @return source. */ private static PCollection<Long> getSource(final Pipeline p) { return p.apply(GenerateSequence .from(1) .withRate(2, Duration.standardSeconds(1)) .withTimestampFn(num -> new Instant(num * 500))); // 0.5 second between subsequent elements } /**
.from(1) .withRate(2, Duration.standardSeconds(1)) .withTimestampFn(num -> new Instant(num * 500))) // 0.5 second between subsequent elements .apply(MapElements.via(new SimpleFunction<Long, KV<String, Long>>() { @Override
@Test public void testUnboundedDisplayData() { Duration maxReadTime = Duration.standardHours(5); SerializableFunction<Long, Instant> timestampFn = input -> Instant.now(); PTransform<?, ?> input = GenerateSequence.from(0).to(1234).withMaxReadTime(maxReadTime).withTimestampFn(timestampFn); DisplayData displayData = DisplayData.from(input); assertThat(displayData, hasDisplayItem("maxReadTime", maxReadTime)); assertThat(displayData, hasDisplayItem("timestampFn", timestampFn.getClass())); }
@Test @Category(NeedsRunner.class) public void testUnboundedInputTimestamps() { long numElements = 1000; PCollection<Long> input = p.apply(GenerateSequence.from(0).to(numElements).withTimestampFn(new ValueAsTimestampFn())); addCountingAsserts(input, 0, numElements); PCollection<Long> diffs = input .apply("TimestampDiff", ParDo.of(new ElementValueDiff())) .apply("DistinctTimestamps", Distinct.create()); // This assert also confirms that diffs only has one unique value. PAssert.thatSingleton(diffs).isEqualTo(0L); p.run(); }
GenerateSequence.from(0) .to(100) .withTimestampFn( new SerializableFunction<Long, Instant>() { @Override