use of org.junit.experimental.categories.Category in project beam by apache.
the class CombineTest method testGlobalCombineWithDefaultsAndTriggers.
@Test
@Category(ValidatesRunner.class)
public void testGlobalCombineWithDefaultsAndTriggers() {
PCollection<Integer> input = pipeline.apply(Create.of(1, 1));
PCollection<String> output = input.apply(Window.<Integer>into(new GlobalWindows()).triggering(Repeatedly.forever(AfterPane.elementCountAtLeast(1))).accumulatingFiredPanes().withAllowedLateness(new Duration(0))).apply(Sum.integersGlobally()).apply(ParDo.of(new FormatPaneInfo()));
// The actual elements produced are nondeterministic. Could be one, could be two.
// But it should certainly have a final element with the correct final sum.
PAssert.that(output).satisfies(new SerializableFunction<Iterable<String>, Void>() {
@Override
public Void apply(Iterable<String> input) {
assertThat(input, hasItem("2: true"));
return null;
}
});
pipeline.run();
}
use of org.junit.experimental.categories.Category in project beam by apache.
the class TriggerExampleTest method testTotalFlow.
@Test
@Category(ValidatesRunner.class)
public void testTotalFlow() {
PCollection<KV<String, Integer>> flow = pipeline.apply(Create.timestamped(TIME_STAMPED_INPUT)).apply(ParDo.of(new ExtractFlowInfo()));
PCollection<TableRow> totalFlow = flow.apply(Window.<KV<String, Integer>>into(FixedWindows.of(Duration.standardMinutes(1)))).apply(new TotalFlow("default"));
PCollection<String> results = totalFlow.apply(ParDo.of(new FormatResults()));
PAssert.that(results).containsInAnyOrder(canonicalFormat(OUT_ROW_1), canonicalFormat(OUT_ROW_2));
pipeline.run().waitUntilFinish();
}
use of org.junit.experimental.categories.Category in project beam by apache.
the class WindowingTest method testTextIoInput.
@Test
@Category(NeedsRunner.class)
public void testTextIoInput() throws Exception {
File tmpFile = tmpFolder.newFile("file.txt");
String filename = tmpFile.getPath();
try (PrintStream writer = new PrintStream(new FileOutputStream(tmpFile))) {
writer.println("a 1");
writer.println("b 2");
writer.println("b 3");
writer.println("c 11");
writer.println("d 11");
}
PCollection<String> output = p.begin().apply("ReadLines", TextIO.read().from(filename)).apply(ParDo.of(new ExtractWordsWithTimestampsFn())).apply(new WindowedCount(FixedWindows.of(Duration.millis(10))));
PAssert.that(output).containsInAnyOrder(output("a", 1, 1, 0, 10), output("b", 2, 2, 0, 10), output("c", 1, 11, 10, 20), output("d", 1, 11, 10, 20));
p.run();
}
use of org.junit.experimental.categories.Category in project beam by apache.
the class WindowingTest method testMergingWindowing.
@Test
@Category(ValidatesRunner.class)
public void testMergingWindowing() {
PCollection<String> input = p.apply(Create.timestamped(TimestampedValue.of("a", new Instant(1)), TimestampedValue.of("a", new Instant(5)), TimestampedValue.of("a", new Instant(20))));
PCollection<String> output = input.apply(new WindowedCount(Sessions.withGapDuration(new Duration(10))));
PAssert.that(output).containsInAnyOrder(output("a", 2, 1, 1, 15), output("a", 1, 20, 20, 30));
p.run();
}
use of org.junit.experimental.categories.Category in project beam by apache.
the class WindowingTest method testPartitioningWindowing.
@Test
@Category(ValidatesRunner.class)
public void testPartitioningWindowing() {
PCollection<String> input = p.apply(Create.timestamped(TimestampedValue.of("a", new Instant(1)), TimestampedValue.of("b", new Instant(2)), TimestampedValue.of("b", new Instant(3)), TimestampedValue.of("c", new Instant(11)), TimestampedValue.of("d", new Instant(11))));
PCollection<String> output = input.apply(new WindowedCount(FixedWindows.of(new Duration(10))));
PAssert.that(output).containsInAnyOrder(output("a", 1, 1, 0, 10), output("b", 2, 2, 0, 10), output("c", 1, 11, 10, 20), output("d", 1, 11, 10, 20));
p.run();
}
Aggregations