github.com/apache/beam/sdks/v2@v2.48.2/go/test/integration/driver/driver.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 // The integration driver provides a suite of tests to run against a registered runner. 17 package main 18 19 import ( 20 "context" 21 "flag" 22 "regexp" 23 "sync" 24 "sync/atomic" 25 26 "github.com/apache/beam/sdks/v2/go/pkg/beam" 27 "github.com/apache/beam/sdks/v2/go/pkg/beam/io/filesystem/memfs" 28 "github.com/apache/beam/sdks/v2/go/pkg/beam/log" 29 "github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx" 30 "github.com/apache/beam/sdks/v2/go/test/integration/primitives" 31 "github.com/apache/beam/sdks/v2/go/test/integration/synthetic" 32 "github.com/apache/beam/sdks/v2/go/test/integration/wordcount" 33 ) 34 35 var ( 36 parallel = flag.Int("parallel", 10, "Number of tests to run in parallel") 37 filter = flag.String("filter", ".*", "Test filer to run a subset of tests") 38 ) 39 40 const old_pond = "memfs://old_pond" 41 42 func init() { 43 memfs.Write(old_pond, []byte("old pond \na frog leaps in\nwater's sound\n")) 44 } 45 46 type namedPipeline struct { 47 name string 48 p *beam.Pipeline 49 } 50 51 func main() { 52 flag.Parse() 53 beam.Init() 54 55 if *parallel < 1 { 56 *parallel = 1 57 } 58 59 pipelines := []namedPipeline{ 60 {"wordcount:memfs", wordcount.WordCount(old_pond, "+Qj8iAnV5BI2A4sbzUbb6Q==", 8)}, 61 {"wordcount:kinglear", wordcount.WordCount("gs://apache-beam-samples/shakespeare/kinglear.txt", "7ZCh5ih9m8IW1w+iS8sRKg==", 4749)}, 62 {"synthetic:simple", synthetic.SimplePipeline()}, 63 {"synthetic:splittable", synthetic.SplittablePipeline()}, 64 {"pardo:multioutput", primitives.ParDoMultiOutput()}, 65 {"pardo:sideinput", primitives.ParDoSideInput()}, 66 {"pardo:kvsideinput", primitives.ParDoKVSideInput()}, 67 {"cogbk:cogbk", primitives.CoGBK()}, 68 {"flatten:flatten", primitives.Flatten()}, 69 // {"flatten:dup", primitives.FlattenDup()}, 70 {"reshuffle:reshuffle", primitives.Reshuffle()}, 71 {"reshuffle:reshufflekv", primitives.ReshuffleKV()}, 72 {"window:sums", func() *beam.Pipeline { 73 p, s := beam.NewPipelineWithRoot() 74 primitives.WindowSums_GBK(s) 75 primitives.WindowSums_Lifted(s) 76 return p 77 }(), 78 }, 79 } 80 81 re := regexp.MustCompile(*filter) 82 83 ctx := context.Background() 84 85 ch := make(chan namedPipeline, len(pipelines)) 86 for _, np := range pipelines { 87 if re.MatchString(np.name) { 88 ch <- np 89 } 90 } 91 close(ch) 92 93 var failures int32 94 var wg sync.WaitGroup 95 for i := 0; i < *parallel; i++ { 96 wg.Add(1) 97 go func() { 98 defer wg.Done() 99 for np := range ch { 100 log.Infof(ctx, "Running %v test ..", np.name) 101 102 if err := beamx.Run(ctx, np.p); err != nil { 103 atomic.AddInt32(&failures, 1) 104 log.Errorf(ctx, "Test %v failed: %v", np.name, err) 105 } else { 106 log.Infof(ctx, "Test %v completed", np.name) 107 } 108 } 109 }() 110 } 111 wg.Wait() 112 113 if failures > 0 { 114 log.Exitf(ctx, "Result: %v tests failed", failures) 115 } 116 log.Infof(ctx, "Result: all tests passed!") 117 }