github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/tests/cdc/cdc.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 "flag" 18 "os" 19 20 _ "github.com/go-sql-driver/mysql" 21 "github.com/pingcap/errors" 22 "github.com/pingcap/log" 23 "github.com/pingcap/ticdc/tests/dailytest" 24 "github.com/pingcap/ticdc/tests/util" 25 ) 26 27 func main() { 28 cfg := util.NewConfig() 29 err := cfg.Parse(os.Args[1:]) 30 switch errors.Cause(err) { 31 case nil: 32 case flag.ErrHelp: 33 os.Exit(0) 34 default: 35 log.S().Errorf("parse cmd flags err %s\n", err) 36 os.Exit(2) 37 } 38 39 sourceDB, err := util.CreateDB(cfg.SourceDBCfg[0]) 40 if err != nil { 41 log.S().Fatal(err) 42 } 43 defer func() { 44 if err := util.CloseDB(sourceDB); err != nil { 45 log.S().Errorf("Failed to close source database: %s\n", err) 46 } 47 }() 48 49 targetDB, err := util.CreateDB(cfg.TargetDBCfg) 50 if err != nil { 51 log.S().Fatal(err) 52 } 53 defer func() { 54 if err := util.CloseDB(targetDB); err != nil { 55 log.S().Errorf("Failed to close target database: %s\n", err) 56 } 57 }() 58 59 sourceDBs, err := util.CreateSourceDBs() 60 if err != nil { 61 log.S().Fatal(err) 62 } 63 defer func() { 64 if err := util.CloseDBs(sourceDBs); err != nil { 65 log.S().Errorf("Failed to close source databases: %s\n", err) 66 } 67 }() 68 69 dailytest.Run(sourceDB, targetDB, cfg.SourceDBCfg[0].Name, cfg.WorkerCount, cfg.JobCount, cfg.Batch) 70 }