Search in sources :

Example 1 with StreamingShardedWriteFactory

use of org.apache.beam.runners.flink.FlinkStreamingPipelineTranslator.StreamingShardedWriteFactory 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)

Aggregations

StreamingShardedWriteFactory (org.apache.beam.runners.flink.FlinkStreamingPipelineTranslator.StreamingShardedWriteFactory)1 WriteFiles (org.apache.beam.sdk.io.WriteFiles)1 WriteFilesResult (org.apache.beam.sdk.io.WriteFilesResult)1 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)1 PCollection (org.apache.beam.sdk.values.PCollection)1 Test (org.junit.Test)1