Search in sources :

Example 1 with TestPipeline

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

the class BeamSetOperatorRelBaseTest method testDifferentWindows.

@Test(expected = IllegalArgumentException.class)
public void testDifferentWindows() throws Exception {
    String sql = "SELECT " + " order_id, site_id, count(*) as cnt " + "FROM ORDER_DETAILS GROUP BY order_id, site_id" + ", TUMBLE(order_time, INTERVAL '1' HOUR) " + " UNION SELECT " + " order_id, site_id, count(*) as cnt " + "FROM ORDER_DETAILS GROUP BY order_id, site_id" + ", TUMBLE(order_time, INTERVAL '2' HOUR) ";
    // use a real pipeline rather than the TestPipeline because we are
    // testing exceptions, the pipeline will not actually run.
    Pipeline pipeline1 = Pipeline.create(PipelineOptionsFactory.create());
    compilePipeline(sql, pipeline1);
    pipeline.run();
}
Also used : TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Example 2 with TestPipeline

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

the class RampupThrottlingFnTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.openMocks(this);
    DateTimeUtils.setCurrentMillisFixed(0);
    TestPipeline pipeline = TestPipeline.create();
    PCollectionView<Instant> startTimeView = pipeline.apply(Create.of(Instant.now())).apply(View.asSingleton());
    RampupThrottlingFn<Void> rampupThrottlingFn = new RampupThrottlingFn<Void>(1, startTimeView) {

        @Override
        @Setup
        public void setup() {
            super.setup();
            this.sleeper = mockSleeper;
        }
    };
    rampupThrottlingFnTester = DoFnTester.of(rampupThrottlingFn);
    rampupThrottlingFnTester.setSideInput(startTimeView, GlobalWindow.INSTANCE, Instant.now());
    rampupThrottlingFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
    rampupThrottlingFnTester.startBundle();
    rampupThrottlingFn.throttlingMsecs = mockCounter;
}
Also used : TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Instant(org.joda.time.Instant) Before(org.junit.Before)

Example 3 with TestPipeline

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

the class TestUtils method createTestPipeline.

public static TestPipeline createTestPipeline() {
    final PipelineOptions pipelineOptions = PipelineOptionsFactory.create();
    pipelineOptions.as(EuphoriaOptions.class).setTranslatorProvider(new PrimitiveOutputTranslatorProvider());
    final TestPipeline testPipeline = TestPipeline.fromOptions(pipelineOptions);
    testPipeline.getCoderRegistry().registerCoderForClass(Object.class, KryoCoder.of(pipelineOptions));
    return testPipeline;
}
Also used : EuphoriaOptions(org.apache.beam.sdk.extensions.euphoria.core.translate.EuphoriaOptions) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions)

Example 4 with TestPipeline

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

the class UnionTest method testBuild_ThreeDataSet.

@Test
public void testBuild_ThreeDataSet() {
    final TestPipeline pipeline = TestUtils.createTestPipeline();
    final PCollection<String> first = TestUtils.createMockDataset(pipeline, TypeDescriptors.strings());
    final PCollection<String> second = TestUtils.createMockDataset(pipeline, TypeDescriptors.strings());
    final PCollection<String> third = TestUtils.createMockDataset(pipeline, TypeDescriptors.strings());
    final PCollection<String> unioned = Union.named("Union1").of(first, second, third).output();
    final Union union = (Union) TestUtils.getProducer(unioned);
    assertTrue(union.getName().isPresent());
    assertEquals("Union1", union.getName().get());
}
Also used : TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Test(org.junit.Test)

Example 5 with TestPipeline

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

the class PCollectionTupleTest method testEquals.

@Test
public void testEquals() {
    TestPipeline p = TestPipeline.create();
    TupleTag<Long> longTag = new TupleTag<>();
    PCollection<Long> longs = p.apply(GenerateSequence.from(0));
    TupleTag<String> strTag = new TupleTag<>();
    PCollection<String> strs = p.apply(Create.of("foo", "bar"));
    EqualsTester tester = new EqualsTester();
    // Empty tuples in the same pipeline are equal
    tester.addEqualityGroup(PCollectionTuple.empty(p), PCollectionTuple.empty(p));
    tester.addEqualityGroup(PCollectionTuple.of(longTag, longs).and(strTag, strs), PCollectionTuple.of(longTag, longs).and(strTag, strs));
    tester.addEqualityGroup(PCollectionTuple.of(longTag, longs));
    tester.addEqualityGroup(PCollectionTuple.of(strTag, strs));
    TestPipeline otherPipeline = TestPipeline.create();
    // Empty tuples in different pipelines are not equal
    tester.addEqualityGroup(PCollectionTuple.empty(otherPipeline));
    tester.testEquals();
}
Also used : TestPipeline(org.apache.beam.sdk.testing.TestPipeline) EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

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