github.com/apache/beam/sdks/v2@v2.48.2/go/test/integration/primitives/heap_dump_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 primitives 17 18 import ( 19 "context" 20 "flag" 21 "fmt" 22 "strings" 23 "testing" 24 25 "github.com/apache/beam/sdks/v2/go/pkg/beam/io/filesystem" 26 _ "github.com/apache/beam/sdks/v2/go/pkg/beam/io/filesystem/gcs" 27 "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/ptest" 28 "github.com/apache/beam/sdks/v2/go/test/integration" 29 ) 30 31 func TestOomParDo(t *testing.T) { 32 integration.CheckFilters(t) 33 if flag.Lookup("temp_location") == nil { 34 t.Fatalf("A temp_location must be provided to correctly run TestOomParDo") 35 } 36 tempLocation := flag.Lookup("temp_location").Value.(flag.Getter).Get().(string) 37 if tempLocation == "" { 38 t.Fatalf("A temp_location must be provided to correctly run TestOomParDo") 39 } 40 dumpLocation := fmt.Sprintf("%v/heapProfiles/*", strings.TrimSuffix(tempLocation, "/")) 41 ctx := context.Background() 42 43 fs, err := filesystem.New(ctx, dumpLocation) 44 if err != nil { 45 t.Fatalf("Failed to connect to filesystem: %v", err) 46 } 47 defer fs.Close() 48 49 files, err := fs.List(ctx, dumpLocation) 50 if err != nil { 51 t.Fatalf("Failed to connect to filesystem: %v", err) 52 } 53 startFiles := len(files) 54 55 ptest.Run(OomParDo()) 56 57 files, err = fs.List(ctx, dumpLocation) 58 if err != nil { 59 t.Fatalf("Failed to connect to filesystem: %v", err) 60 } 61 endFiles := len(files) 62 63 if startFiles >= endFiles { 64 t.Fatalf("No new heap dumps generated on OOM. There were %v dumps before running and %v after", startFiles, endFiles) 65 } 66 }