Search in sources :

Example 1 with CollectionSource

use of org.apache.beam.runners.apex.translation.utils.CollectionSource 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)

Aggregations

DAG (com.datatorrent.api.DAG)1 ApexPipelineOptions (org.apache.beam.runners.apex.ApexPipelineOptions)1 ApexRunnerResult (org.apache.beam.runners.apex.ApexRunnerResult)1 CollectionSource (org.apache.beam.runners.apex.translation.utils.CollectionSource)1 Pipeline (org.apache.beam.sdk.Pipeline)1 Test (org.junit.Test)1