github.com/apache/beam/sdks/v2@v2.48.2/go/examples/snippets/10metrics_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 snippets 17 18 import ( 19 "context" 20 "testing" 21 22 "github.com/apache/beam/sdks/v2/go/pkg/beam" 23 ) 24 25 func TestMetricsPipeline(t *testing.T) { 26 p, s := beam.NewPipelineWithRoot() 27 input := beam.Create(s, 1, 2, 3, 4, 5, 6, 7) 28 addMetricDoFnToPipeline(s, input) 29 ms, err := executePipelineAndGetMetrics(context.Background(), p) 30 if err != nil { 31 t.Errorf("error executing pipeline: %v", err) 32 } 33 if got, want := len(ms.Counters()), 1; got != want { 34 t.Errorf("got %v counters, want %v: %+v", got, want, ms.Counters()) 35 } 36 c := ms.Counters()[0] 37 if got, want := c.Committed, int64(7); got != want { 38 t.Errorf("Attempted Counter: got %v, want %v: %+v", got, want, c) 39 } 40 }