github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/bank/bank.go (about) 1 // Copyright 2020 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package main 15 16 import ( 17 "context" 18 "fmt" 19 "os" 20 "os/signal" 21 "syscall" 22 23 "github.com/pingcap/log" 24 "github.com/spf13/cobra" 25 "go.uber.org/zap" 26 ) 27 28 func main() { 29 ctx, cancel := context.WithCancel(context.Background()) 30 defer cancel() 31 32 sc := make(chan os.Signal, 1) 33 signal.Notify(sc, 34 syscall.SIGHUP, 35 syscall.SIGINT, 36 syscall.SIGTERM, 37 syscall.SIGQUIT) 38 39 go func() { 40 sig := <-sc 41 fmt.Printf("\nGot signal [%v] to exit.\n", sig) 42 log.Warn("received signal to exit", zap.Stringer("signal", sig)) 43 switch sig { 44 case syscall.SIGTERM: 45 cancel() 46 os.Exit(0) 47 default: 48 cancel() 49 os.Exit(1) 50 } 51 }() 52 53 var ( 54 upstream, downstream string 55 downstreamAPIEndpoint string 56 accounts, tables, concurrency int 57 interval, testRound int64 58 cleanupOnly bool 59 ) 60 cmd := &cobra.Command{ 61 Use: "bank", 62 Short: "bank is a testcase case that simulates bank scenarios", 63 Args: cobra.NoArgs, 64 Run: func(cmd *cobra.Command, args []string) { 65 if len(upstream) == 0 || len(downstream) == 0 { 66 log.Fatal("upstream and downstream should not be empty") 67 } 68 run(ctx, upstream, downstream, downstreamAPIEndpoint, 69 accounts, tables, concurrency, interval, testRound, cleanupOnly) 70 }, 71 } 72 cmd.PersistentFlags().StringVarP(&upstream, "upstream", "u", "", "Upstream TiDB DSN, please specify target database in DSN") 73 cmd.PersistentFlags().StringVarP(&downstream, "downstream", "d", "", "Downstream TiDB DSN, please specify target database in DSN") 74 cmd.PersistentFlags().StringVarP(&downstreamAPIEndpoint, "downstreamEndpoint", "a", "", "Downstream TiDB API endpoint") 75 cmd.PersistentFlags().Int64Var(&interval, "interval", 1000, "Interval of verify tables") 76 cmd.PersistentFlags().Int64Var(&testRound, "test-round", 50000, "Total around of upstream updates") 77 cmd.PersistentFlags().IntVar(&tables, "tables", 5, "The number of tables for db") 78 cmd.PersistentFlags().IntVar(&accounts, "accounts", 100, "The number of Accounts for each table") 79 cmd.PersistentFlags().IntVar(&concurrency, "concurrency", 10, "concurrency of transaction for each table") 80 cmd.PersistentFlags().BoolVar(&cleanupOnly, "cleanup", false, "cleanup all tables used in the testcase") 81 82 // Outputs cmd.Print to stdout. 83 cmd.SetOut(os.Stdout) 84 if err := cmd.Execute(); err != nil { 85 os.Exit(1) 86 } 87 }