github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_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/tiflow/tests/integration_tests/cdc/dailytest"
    24  	"github.com/pingcap/tiflow/tests/integration_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  	// TODO(dongmen): remove the useless code
    60  	sourceDBs, err := util.CreateSourceDBs()
    61  	if err != nil {
    62  		log.S().Fatal(err)
    63  	}
    64  	defer func() {
    65  		if err := util.CloseDBs(sourceDBs); err != nil {
    66  			log.S().Errorf("Failed to close source databases: %s\n", err)
    67  		}
    68  	}()
    69  
    70  	dailytest.Run(sourceDB, targetDB, cfg.SourceDBCfg[0].Name, cfg.WorkerCount, cfg.JobCount, cfg.Batch)
    71  }