@Test
@Category(NeedsRunner.class)
public void testReadWatchForNewFiles() throws IOException, InterruptedException {
final Path basePath = tempFolder.getRoot().toPath().resolve("readWatch");
basePath.toFile().mkdir();
p.apply(GenerateSequence.from(0).to(10).withRate(1, Duration.millis(100)))
.apply(
Window.<Long>into(FixedWindows.of(Duration.millis(150)))
.withAllowedLateness(Duration.ZERO)
.triggering(Repeatedly.forever(AfterPane.elementCountAtLeast(1)))
.discardingFiredPanes())
.apply(ToString.elements())
.apply(
TextIO.write()
.to(basePath.resolve("data").toString())
.withNumShards(1)
.withWindowedWrites());
PCollection<String> lines =
p.apply(
TextIO.read()
.from(basePath.resolve("*").toString())
.watchForNewFiles(
Duration.millis(100),
Watch.Growth.afterTimeSinceNewOutput(Duration.standardSeconds(3))));
PAssert.that(lines).containsInAnyOrder("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
p.run();
}
}