Search in sources :

Example 1 with ExtractFlowInfo

use of org.apache.beam.examples.cookbook.TriggerExample.ExtractFlowInfo 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();
}
Also used : TotalFlow(org.apache.beam.examples.cookbook.TriggerExample.TotalFlow) TableRow(com.google.api.services.bigquery.model.TableRow) KV(org.apache.beam.sdk.values.KV) ExtractFlowInfo(org.apache.beam.examples.cookbook.TriggerExample.ExtractFlowInfo) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 2 with ExtractFlowInfo

use of org.apache.beam.examples.cookbook.TriggerExample.ExtractFlowInfo in project beam by apache.

the class TriggerExampleTest method testExtractTotalFlow.

@Test
public void testExtractTotalFlow() throws Exception {
    DoFnTester<String, KV<String, Integer>> extractFlowInfow = DoFnTester.of(new ExtractFlowInfo());
    List<KV<String, Integer>> results = extractFlowInfow.processBundle(INPUT);
    Assert.assertEquals(results.size(), 1);
    Assert.assertEquals(results.get(0).getKey(), "94");
    Assert.assertEquals(results.get(0).getValue(), new Integer(29));
    List<KV<String, Integer>> output = extractFlowInfow.processBundle("");
    Assert.assertEquals(output.size(), 0);
}
Also used : KV(org.apache.beam.sdk.values.KV) ExtractFlowInfo(org.apache.beam.examples.cookbook.TriggerExample.ExtractFlowInfo) Test(org.junit.Test)

Aggregations

ExtractFlowInfo (org.apache.beam.examples.cookbook.TriggerExample.ExtractFlowInfo)2 KV (org.apache.beam.sdk.values.KV)2 Test (org.junit.Test)2 TableRow (com.google.api.services.bigquery.model.TableRow)1 TotalFlow (org.apache.beam.examples.cookbook.TriggerExample.TotalFlow)1 Category (org.junit.experimental.categories.Category)1