Search in sources :

Example 6 with ApexRunnerResult

use of org.apache.beam.runners.apex.ApexRunnerResult in project beam by apache.

the class ReadUnboundTranslatorTest method test.

@Test
public void test() throws Exception {
    ApexPipelineOptions options = PipelineOptionsFactory.create().as(ApexPipelineOptions.class);
    EmbeddedCollector.RESULTS.clear();
    options.setApplicationName("ReadUnbound");
    options.setRunner(ApexRunner.class);
    Pipeline p = Pipeline.create(options);
    List<String> collection = Lists.newArrayList("1", "2", "3", "4", "5");
    CollectionSource<String> source = new CollectionSource<>(collection, StringUtf8Coder.of());
    p.apply(Read.from(source)).apply(ParDo.of(new EmbeddedCollector()));
    ApexRunnerResult result = (ApexRunnerResult) p.run();
    DAG dag = result.getApexDAG();
    DAG.OperatorMeta om = dag.getOperatorMeta("Read(CollectionSource)");
    Assert.assertNotNull(om);
    Assert.assertEquals(om.getOperator().getClass(), ApexReadUnboundedInputOperator.class);
    long timeout = System.currentTimeMillis() + 30000;
    while (System.currentTimeMillis() < timeout) {
        if (EmbeddedCollector.RESULTS.containsAll(collection)) {
            break;
        }
        LOG.info("Waiting for expected results.");
        Thread.sleep(1000);
    }
    Assert.assertEquals(Sets.newHashSet(collection), EmbeddedCollector.RESULTS);
}
Also used : CollectionSource(org.apache.beam.runners.apex.translation.utils.CollectionSource) ApexRunnerResult(org.apache.beam.runners.apex.ApexRunnerResult) DAG(com.datatorrent.api.DAG) ApexPipelineOptions(org.apache.beam.runners.apex.ApexPipelineOptions) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Example 7 with ApexRunnerResult

use of org.apache.beam.runners.apex.ApexRunnerResult in project beam by apache.

the class GroupByKeyTranslatorTest method test.

@SuppressWarnings({ "unchecked" })
@Test
public void test() throws Exception {
    ApexPipelineOptions options = PipelineOptionsFactory.as(ApexPipelineOptions.class);
    options.setApplicationName("GroupByKey");
    options.setRunner(ApexRunner.class);
    Pipeline p = Pipeline.create(options);
    List<KV<String, Instant>> data = Lists.newArrayList(KV.of("foo", new Instant(1000)), KV.of("foo", new Instant(1000)), KV.of("foo", new Instant(2000)), KV.of("bar", new Instant(1000)), KV.of("bar", new Instant(2000)), KV.of("bar", new Instant(2000)));
    // expected results assume outputAtLatestInputTimestamp
    List<KV<Instant, KV<String, Long>>> expected = Lists.newArrayList(KV.of(new Instant(1000), KV.of("foo", 2L)), KV.of(new Instant(1000), KV.of("bar", 1L)), KV.of(new Instant(2000), KV.of("foo", 1L)), KV.of(new Instant(2000), KV.of("bar", 2L)));
    p.apply(Read.from(new TestSource(data, new Instant(5000)))).apply(Window.<String>into(FixedWindows.of(Duration.standardSeconds(1))).withTimestampCombiner(TimestampCombiner.LATEST)).apply(Count.<String>perElement()).apply(ParDo.of(new KeyedByTimestamp<KV<String, Long>>())).apply(ParDo.of(new EmbeddedCollector()));
    ApexRunnerResult result = (ApexRunnerResult) p.run();
    result.getApexDAG();
    long timeout = System.currentTimeMillis() + 30000;
    while (System.currentTimeMillis() < timeout) {
        if (EmbeddedCollector.RESULTS.containsAll(expected)) {
            break;
        }
        Thread.sleep(1000);
    }
    Assert.assertEquals(Sets.newHashSet(expected), EmbeddedCollector.RESULTS);
}
Also used : Instant(org.joda.time.Instant) ApexRunnerResult(org.apache.beam.runners.apex.ApexRunnerResult) KV(org.apache.beam.sdk.values.KV) Pipeline(org.apache.beam.sdk.Pipeline) ApexPipelineOptions(org.apache.beam.runners.apex.ApexPipelineOptions) Test(org.junit.Test)

Aggregations

ApexPipelineOptions (org.apache.beam.runners.apex.ApexPipelineOptions)7 ApexRunnerResult (org.apache.beam.runners.apex.ApexRunnerResult)7 Pipeline (org.apache.beam.sdk.Pipeline)7 Test (org.junit.Test)7 DAG (com.datatorrent.api.DAG)3 KV (org.apache.beam.sdk.values.KV)2 ArrayList (java.util.ArrayList)1 ApexRunner (org.apache.beam.runners.apex.ApexRunner)1 TestApexRunner (org.apache.beam.runners.apex.TestApexRunner)1 CollectionSource (org.apache.beam.runners.apex.translation.utils.CollectionSource)1 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)1 PCollection (org.apache.beam.sdk.values.PCollection)1 PCollectionTuple (org.apache.beam.sdk.values.PCollectionTuple)1 TupleTag (org.apache.beam.sdk.values.TupleTag)1 Instant (org.joda.time.Instant)1