Search in sources :

Example 6 with PTransformOverride

use of org.apache.beam.sdk.runners.PTransformOverride in project beam by apache.

the class FlinkPipelineExecutionEnvironmentTest method shouldProvideParallelismToTransformOverrides.

@Test
public void shouldProvideParallelismToTransformOverrides() {
    FlinkPipelineOptions options = FlinkPipelineOptions.defaults();
    options.setStreaming(true);
    options.setRunner(FlinkRunner.class);
    FlinkPipelineExecutionEnvironment flinkEnv = new FlinkPipelineExecutionEnvironment(options);
    Pipeline p = Pipeline.create(options);
    // Create a transform applicable for PTransformMatchers.writeWithRunnerDeterminedSharding()
    // which requires parallelism
    p.apply(Create.of("test")).apply(TextIO.write().to("/tmp"));
    p = Mockito.spy(p);
    // If this succeeds we're ok
    flinkEnv.translate(p);
    // Verify we were using desired replacement transform
    ArgumentCaptor<ImmutableList> captor = ArgumentCaptor.forClass(ImmutableList.class);
    Mockito.verify(p).replaceAll(captor.capture());
    ImmutableList<PTransformOverride> overridesList = captor.getValue();
    assertThat(overridesList, hasItem(new BaseMatcher<PTransformOverride>() {

        @Override
        public void describeTo(Description description) {
        }

        @Override
        public boolean matches(Object actual) {
            if (actual instanceof PTransformOverride) {
                PTransformOverrideFactory overrideFactory = ((PTransformOverride) actual).getOverrideFactory();
                if (overrideFactory instanceof FlinkStreamingPipelineTranslator.StreamingShardedWriteFactory) {
                    FlinkStreamingPipelineTranslator.StreamingShardedWriteFactory factory = (FlinkStreamingPipelineTranslator.StreamingShardedWriteFactory) overrideFactory;
                    return factory.options.getParallelism() > 0;
                }
            }
            return false;
        }
    }));
}
Also used : Description(org.hamcrest.Description) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) PTransformOverride(org.apache.beam.sdk.runners.PTransformOverride) Pipeline(org.apache.beam.sdk.Pipeline) BaseMatcher(org.hamcrest.BaseMatcher) PTransformOverrideFactory(org.apache.beam.sdk.runners.PTransformOverrideFactory) Test(org.junit.Test)

Aggregations

PTransformOverride (org.apache.beam.sdk.runners.PTransformOverride)6 Test (org.junit.Test)4 Pipeline (org.apache.beam.sdk.Pipeline)3 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)3 ImmutableList (com.google.common.collect.ImmutableList)1 HashSet (java.util.HashSet)1 BatchCombineGloballyAsSingletonViewFactory (org.apache.beam.runners.dataflow.BatchViewOverrides.BatchCombineGloballyAsSingletonViewFactory)1 StreamingCreatePCollectionViewFactory (org.apache.beam.runners.dataflow.StreamingViewOverrides.StreamingCreatePCollectionViewFactory)1 GenerateSequence (org.apache.beam.sdk.io.GenerateSequence)1 Read (org.apache.beam.sdk.io.Read)1 PTransformMatcher (org.apache.beam.sdk.runners.PTransformMatcher)1 PTransformOverrideFactory (org.apache.beam.sdk.runners.PTransformOverrideFactory)1 Node (org.apache.beam.sdk.runners.TransformHierarchy.Node)1 GroupedValues (org.apache.beam.sdk.transforms.Combine.GroupedValues)1 Create (org.apache.beam.sdk.transforms.Create)1 ParDo (org.apache.beam.sdk.transforms.ParDo)1 View (org.apache.beam.sdk.transforms.View)1 PCollectionView (org.apache.beam.sdk.values.PCollectionView)1 BaseMatcher (org.hamcrest.BaseMatcher)1 Description (org.hamcrest.Description)1