Search in sources :

Example 11 with TestPipeline

use of org.apache.beam.sdk.testing.TestPipeline in project components by Talend.

the class TCompBoundedSourceSinkAdapterTest method testPipeline.

@Test
public void testPipeline() {
    Pipeline pipeline = TestPipeline.create();
    FixedFlowProperties fixedFlowProperties = new FixedFlowProperties("fixedFlowProperties");
    fixedFlowProperties.init();
    fixedFlowProperties.data.setValue("a;b;c");
    fixedFlowProperties.rowDelimited.setValue(";");
    AssertResultProperties assertResultProperties = new AssertResultProperties("assertResultProperties");
    assertResultProperties.init();
    assertResultProperties.data.setValue("b;c;a");
    assertResultProperties.rowDelimited.setValue(";");
    FixedFlowSource fixedFlowSource = new FixedFlowSource();
    fixedFlowSource.initialize(null, fixedFlowProperties);
    AssertResultSink assertResultSink = new AssertResultSink();
    assertResultSink.initialize(null, assertResultProperties);
    TCompBoundedSourceAdapter source = new TCompBoundedSourceAdapter(fixedFlowSource);
    TCompSinkAdapter sink = new TCompSinkAdapter(assertResultSink);
    pipeline.apply(Read.from(source)).apply(Write.to(sink));
    pipeline.run();
}
Also used : AssertResultProperties(org.talend.components.adapter.beam.example.AssertResultProperties) FixedFlowSource(org.talend.components.adapter.beam.example.FixedFlowSource) AssertResultSink(org.talend.components.adapter.beam.example.AssertResultSink) FixedFlowProperties(org.talend.components.adapter.beam.example.FixedFlowProperties) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Example 12 with TestPipeline

use of org.apache.beam.sdk.testing.TestPipeline in project beam by apache.

the class PubsubIOTest method testRuntimeValueProviderTopic.

@Test
public void testRuntimeValueProviderTopic() {
    TestPipeline pipeline = TestPipeline.create();
    ValueProvider<String> topic = pipeline.newProvider("projects/project/topics/topic");
    Read<String> pubsubRead = PubsubIO.readStrings().fromTopic(topic);
    pipeline.apply(pubsubRead);
    assertThat(pubsubRead.getTopicProvider(), not(nullValue()));
    assertThat(pubsubRead.getTopicProvider().isAccessible(), is(false));
}
Also used : TestPipeline(org.apache.beam.sdk.testing.TestPipeline) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 13 with TestPipeline

use of org.apache.beam.sdk.testing.TestPipeline in project beam by apache.

the class BeamSortRelTest method testOrderBy_exception.

@Test
public void testOrderBy_exception() {
    thrown.expect(UnsupportedOperationException.class);
    thrown.expectMessage("`ORDER BY` is only supported for GlobalWindows");
    String sql = "INSERT INTO SUB_ORDER_RAM(order_id, site_id)  SELECT " + " order_id, COUNT(*) " + "FROM ORDER_DETAILS " + "GROUP BY order_id, TUMBLE(order_time, INTERVAL '1' HOUR)" + "ORDER BY order_id asc limit 11";
    TestPipeline pipeline = TestPipeline.create();
    compilePipeline(sql, pipeline);
}
Also used : TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Test(org.junit.Test)

Example 14 with TestPipeline

use of org.apache.beam.sdk.testing.TestPipeline in project beam by apache.

the class FlinkTransformOverridesTest method testRunnerDeterminedSharding.

@Test
public void testRunnerDeterminedSharding() {
    FlinkPipelineOptions options = FlinkPipelineOptions.defaults();
    options.setRunner(TestFlinkRunner.class);
    options.setFlinkMaster("[auto]");
    options.setParallelism(5);
    TestPipeline p = TestPipeline.fromOptions(options);
    StreamingShardedWriteFactory<Object, Void, Object> factory = new StreamingShardedWriteFactory<>(p.getOptions());
    WriteFiles<Object, Void, Object> original = WriteFiles.to(new TestSink(tmpFolder.toString()));
    @SuppressWarnings("unchecked") PCollection<Object> objs = (PCollection) p.apply(Create.empty(VoidCoder.of()));
    AppliedPTransform<PCollection<Object>, WriteFilesResult<Void>, WriteFiles<Object, Void, Object>> originalApplication = AppliedPTransform.of("writefiles", PValues.expandInput(objs), Collections.emptyMap(), original, ResourceHints.create(), p);
    WriteFiles<Object, Void, Object> replacement = (WriteFiles<Object, Void, Object>) factory.getReplacementTransform(originalApplication).getTransform();
    assertThat(replacement, not(equalTo((Object) original)));
    assertThat(replacement.getNumShardsProvider().get(), is(10));
}
Also used : StreamingShardedWriteFactory(org.apache.beam.runners.flink.FlinkStreamingPipelineTranslator.StreamingShardedWriteFactory) WriteFilesResult(org.apache.beam.sdk.io.WriteFilesResult) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) PCollection(org.apache.beam.sdk.values.PCollection) WriteFiles(org.apache.beam.sdk.io.WriteFiles) Test(org.junit.Test)

Example 15 with TestPipeline

use of org.apache.beam.sdk.testing.TestPipeline in project beam by apache.

the class DataflowRunnerTest method testStreamingWriteOverride.

private void testStreamingWriteOverride(PipelineOptions options, int expectedNumShards) {
    TestPipeline p = TestPipeline.fromOptions(options);
    StreamingShardedWriteFactory<Object, Void, Object> factory = new StreamingShardedWriteFactory<>(p.getOptions());
    WriteFiles<Object, Void, Object> original = WriteFiles.to(new TestSink(tmpFolder.toString()));
    PCollection<Object> objs = (PCollection) p.apply(Create.empty(VoidCoder.of()));
    AppliedPTransform<PCollection<Object>, WriteFilesResult<Void>, WriteFiles<Object, Void, Object>> originalApplication = AppliedPTransform.of("writefiles", PValues.expandInput(objs), Collections.emptyMap(), original, ResourceHints.create(), p);
    WriteFiles<Object, Void, Object> replacement = (WriteFiles<Object, Void, Object>) factory.getReplacementTransform(originalApplication).getTransform();
    assertThat(replacement, not(equalTo((Object) original)));
    assertThat(replacement.getNumShardsProvider().get(), equalTo(expectedNumShards));
    WriteFilesResult<Void> originalResult = objs.apply(original);
    WriteFilesResult<Void> replacementResult = objs.apply(replacement);
    Map<PCollection<?>, ReplacementOutput> res = factory.mapOutputs(PValues.expandOutput(originalResult), replacementResult);
    assertEquals(1, res.size());
    assertEquals(originalResult.getPerDestinationOutputFilenames(), res.get(replacementResult.getPerDestinationOutputFilenames()).getOriginal().getValue());
}
Also used : StreamingShardedWriteFactory(org.apache.beam.runners.dataflow.DataflowRunner.StreamingShardedWriteFactory) WriteFilesResult(org.apache.beam.sdk.io.WriteFilesResult) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) PCollection(org.apache.beam.sdk.values.PCollection) ReplacementOutput(org.apache.beam.sdk.runners.PTransformOverrideFactory.ReplacementOutput) StorageObject(com.google.api.services.storage.model.StorageObject) WriteFiles(org.apache.beam.sdk.io.WriteFiles)

Aggregations

TestPipeline (org.apache.beam.sdk.testing.TestPipeline)19 Test (org.junit.Test)11 KV (org.apache.beam.sdk.values.KV)5 PCollection (org.apache.beam.sdk.values.PCollection)3 ByteString (com.google.protobuf.ByteString)2 Pipeline (org.apache.beam.sdk.Pipeline)2 WriteFiles (org.apache.beam.sdk.io.WriteFiles)2 WriteFilesResult (org.apache.beam.sdk.io.WriteFilesResult)2 StorageObject (com.google.api.services.storage.model.StorageObject)1 EqualsTester (com.google.common.testing.EqualsTester)1 StreamingShardedWriteFactory (org.apache.beam.runners.dataflow.DataflowRunner.StreamingShardedWriteFactory)1 StreamingShardedWriteFactory (org.apache.beam.runners.flink.FlinkStreamingPipelineTranslator.StreamingShardedWriteFactory)1 EuphoriaOptions (org.apache.beam.sdk.extensions.euphoria.core.translate.EuphoriaOptions)1 PipelineOptions (org.apache.beam.sdk.options.PipelineOptions)1 ReplacementOutput (org.apache.beam.sdk.runners.PTransformOverrideFactory.ReplacementOutput)1 Instant (org.joda.time.Instant)1 Before (org.junit.Before)1 Parameters (org.junit.runners.Parameterized.Parameters)1 AssertResultProperties (org.talend.components.adapter.beam.example.AssertResultProperties)1 AssertResultSink (org.talend.components.adapter.beam.example.AssertResultSink)1