github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/integration/integration.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  
    19  	"github.com/pingcap/log"
    20  	"github.com/pingcap/ticdc/integration/framework"
    21  	"github.com/pingcap/ticdc/integration/framework/avro"
    22  	"github.com/pingcap/ticdc/integration/framework/canal"
    23  	"github.com/pingcap/ticdc/integration/framework/mysql"
    24  	"github.com/pingcap/ticdc/integration/tests"
    25  	"go.uber.org/zap"
    26  	"go.uber.org/zap/zapcore"
    27  )
    28  
    29  var (
    30  	testProtocol      = flag.String("protocol", "avro", "the protocol we want to test: avro or canal")
    31  	dockerComposeFile = flag.String("docker-compose-file", "", "the path of the Docker-compose yml file")
    32  )
    33  
    34  func testAvro() {
    35  	env := avro.NewKafkaDockerEnv(*dockerComposeFile)
    36  	env.DockerComposeOperator.ExecEnv = []string{"CDC_TIME_ZONE=America/Los_Angeles"}
    37  	task := &avro.SingleTableTask{TableName: "test"}
    38  	testCases := []framework.Task{
    39  		tests.NewDateTimeCase(task),
    40  		tests.NewSimpleCase(task),
    41  		tests.NewDeleteCase(task),
    42  		tests.NewManyTypesCase(task),
    43  		tests.NewUnsignedCase(task),
    44  		tests.NewCompositePKeyCase(task),
    45  		tests.NewAlterCase(task), // this case is slow, so put it last
    46  	}
    47  
    48  	runTests(testCases, env)
    49  }
    50  
    51  func testCanal() {
    52  	env := canal.NewKafkaDockerEnv(*dockerComposeFile)
    53  	env.DockerComposeOperator.ExecEnv = []string{"USE_FLAT_MESSAGE=false"}
    54  	task := &canal.SingleTableTask{TableName: "test"}
    55  	testCases := []framework.Task{
    56  		tests.NewSimpleCase(task),
    57  		tests.NewDeleteCase(task),
    58  		tests.NewManyTypesCase(task),
    59  		// tests.NewUnsignedCase(task), //now canal adapter can not deal with unsigned int greater than int max
    60  		tests.NewCompositePKeyCase(task),
    61  		// tests.NewAlterCase(task), // basic implementation can not grantee ddl dml sequence, so can not pass
    62  	}
    63  
    64  	runTests(testCases, env)
    65  }
    66  
    67  func testCanalJSON() {
    68  	env := canal.NewKafkaDockerEnv(*dockerComposeFile)
    69  	env.DockerComposeOperator.ExecEnv = []string{"USE_FLAT_MESSAGE=true"}
    70  	task := &canal.SingleTableTask{TableName: "test", UseJSON: true}
    71  	testCases := []framework.Task{
    72  		tests.NewSimpleCase(task),
    73  		tests.NewDeleteCase(task),
    74  		tests.NewManyTypesCase(task),
    75  		// tests.NewUnsignedCase(task), //now canal adapter can not deal with unsigned int greater than int max
    76  		tests.NewCompositePKeyCase(task),
    77  		tests.NewAlterCase(task),
    78  	}
    79  
    80  	runTests(testCases, env)
    81  }
    82  
    83  func testMySQL() {
    84  	env := mysql.NewDockerEnv(*dockerComposeFile)
    85  	task := &mysql.SingleTableTask{TableName: "test"}
    86  	testCases := []framework.Task{
    87  		tests.NewSimpleCase(task),
    88  		tests.NewDeleteCase(task),
    89  		tests.NewManyTypesCase(task),
    90  		tests.NewUnsignedCase(task),
    91  		tests.NewCompositePKeyCase(task),
    92  		tests.NewAlterCase(task),
    93  	}
    94  
    95  	runTests(testCases, env)
    96  }
    97  
    98  func testMySQLWithCheckingOldvValue() {
    99  	env := mysql.NewDockerEnv(*dockerComposeFile)
   100  	env.DockerComposeOperator.ExecEnv = []string{"GO_FAILPOINTS=github.com/pingcap/ticdc/cdc/sink/SimpleMySQLSinkTester=return(ture)"}
   101  	task := &mysql.SingleTableTask{TableName: "test", CheckOleValue: true}
   102  	testCases := []framework.Task{
   103  		tests.NewSimpleCase(task),
   104  		tests.NewDeleteCase(task),
   105  		tests.NewManyTypesCase(task),
   106  		tests.NewUnsignedCase(task),
   107  		tests.NewCompositePKeyCase(task),
   108  		tests.NewAlterCase(task),
   109  	}
   110  
   111  	runTests(testCases, env)
   112  }
   113  
   114  func runTests(cases []framework.Task, env framework.Environment) {
   115  	log.SetLevel(zapcore.DebugLevel)
   116  	env.Setup()
   117  
   118  	for i := range cases {
   119  		env.RunTest(cases[i])
   120  		if i < len(cases)-1 {
   121  			env.Reset()
   122  		}
   123  	}
   124  
   125  	env.TearDown()
   126  }
   127  
   128  func main() {
   129  	flag.Parse()
   130  	if *testProtocol == "avro" {
   131  		testAvro()
   132  	} else if *testProtocol == "canal" {
   133  		testCanal()
   134  	} else if *testProtocol == "canalJson" {
   135  		testCanalJSON()
   136  	} else if *testProtocol == "mysql" {
   137  		testMySQL()
   138  	} else if *testProtocol == "simple-mysql-checking-old-value" {
   139  		testMySQLWithCheckingOldvValue()
   140  	} else {
   141  		log.Fatal("Unknown sink protocol", zap.String("protocol", *testProtocol))
   142  	}
   143  }