github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/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 accounts, tables, concurrency int 56 interval, testRound int64 57 cleanupOnly bool 58 ) 59 cmd := &cobra.Command{ 60 Use: "bank", 61 Short: "bank is a testcase case that simulates bank scenarios", 62 Run: func(cmd *cobra.Command, args []string) { 63 if len(upstream) == 0 || len(downstream) == 0 { 64 log.Fatal("upstream and downstream should not be empty") 65 } 66 run(ctx, upstream, downstream, accounts, tables, concurrency, interval, testRound, cleanupOnly) 67 }, 68 } 69 cmd.PersistentFlags().StringVarP(&upstream, "upstream", "u", "", "Upstream TiDB DSN, please specify target database in DSN") 70 cmd.PersistentFlags().StringVarP(&downstream, "downstream", "d", "", "Downstream TiDB DSN, please specify target database in DSN") 71 cmd.PersistentFlags().Int64Var(&interval, "interval", 1000, "Interval of verify tables") 72 cmd.PersistentFlags().Int64Var(&testRound, "test-round", 50000, "Total around of upstream updates") 73 cmd.PersistentFlags().IntVar(&tables, "tables", 5, "The number of tables for db") 74 cmd.PersistentFlags().IntVar(&accounts, "accounts", 100, "The number of Accounts for each table") 75 cmd.PersistentFlags().IntVar(&concurrency, "concurrency", 10, "concurrency of transaction for each table") 76 cmd.PersistentFlags().BoolVar(&cleanupOnly, "cleanup", false, "cleanup all tables used in the testcase") 77 78 // Outputs cmd.Print to stdout. 79 cmd.SetOut(os.Stdout) 80 if err := cmd.Execute(); err != nil { 81 os.Exit(1) 82 } 83 }