github.com/apache/beam/sdks/v2@v2.48.2/go/test/integration/synthetic/synthetic_test.go (about) 1 // Licensed to the Apache Software Foundation (ASF) under one or more 2 // contributor license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright ownership. 4 // The ASF licenses this file to You under the Apache License, Version 2.0 5 // (the "License"); you may not use this file except in compliance with 6 // the License. You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 package synthetic 17 18 import ( 19 "testing" 20 21 "github.com/apache/beam/sdks/v2/go/pkg/beam" 22 "github.com/apache/beam/sdks/v2/go/pkg/beam/io/synthetic" 23 _ "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/dataflow" 24 _ "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/flink" 25 _ "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/samza" 26 _ "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/spark" 27 "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/passert" 28 "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/ptest" 29 "github.com/apache/beam/sdks/v2/go/test/integration" 30 ) 31 32 // TestSimplePipeline creates a very simple synthetic pipeline to test that 33 // basic synthetic pipelines work. 34 func TestSimplePipeline(t *testing.T) { 35 integration.CheckFilters(t) 36 37 p, s := beam.NewPipelineWithRoot() 38 const size = 100 39 40 src := synthetic.SourceSingle(s, 41 synthetic.DefaultSourceConfig().NumElements(size).Build()) 42 step := synthetic.Step(s, synthetic.DefaultStepConfig().Build(), src) 43 passert.Count(s, step, "out", size) 44 45 ptest.RunAndValidate(t, p) 46 } 47 48 // TestSplittablePipeline creates a simple synthetic pipeline that exercises 49 // splitting-related behavior. 50 func TestSplittablePipeline(t *testing.T) { 51 integration.CheckFilters(t) 52 53 p, s := beam.NewPipelineWithRoot() 54 const srcSize1 = 50 55 const srcSize2 = 10 56 const stepMult = 500 57 const outCount = (srcSize1 + srcSize2) * stepMult 58 59 configs := beam.Create(s, 60 synthetic.DefaultSourceConfig().NumElements(srcSize1).InitialSplits(3).Build(), 61 synthetic.DefaultSourceConfig().NumElements(srcSize2).InitialSplits(3).Build()) 62 src := synthetic.Source(s, configs) 63 step := synthetic.Step( 64 s, 65 synthetic. 66 DefaultStepConfig(). 67 OutputPerInput(stepMult). 68 Splittable(true). 69 InitialSplits(8). 70 Build(), 71 src) 72 passert.Count(s, step, "out", outCount) 73 74 ptest.RunAndValidate(t, p) 75 } 76 77 func TestMain(m *testing.M) { 78 ptest.Main(m) 79 }