github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/mq_protocol_tests/main.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/tiflow/tests/mq_protocol_tests/cases" 21 "github.com/pingcap/tiflow/tests/mq_protocol_tests/framework" 22 "github.com/pingcap/tiflow/tests/mq_protocol_tests/framework/avro" 23 "github.com/pingcap/tiflow/tests/mq_protocol_tests/framework/canal" 24 "github.com/pingcap/tiflow/tests/mq_protocol_tests/framework/mysql" 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 task := &avro.SingleTableTask{TableName: "test"} 37 testCases := []framework.Task{ 38 cases.NewAlterCase(task), // this case is slow, so put it last 39 cases.NewDateTimeCase(task), 40 cases.NewSimpleCase(task), 41 cases.NewDeleteCase(task), 42 cases.NewManyTypesCase(task), 43 cases.NewUnsignedCase(task), 44 cases.NewCompositePKeyCase(task), 45 cases.NewHandleKeyCase(task), 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 cases.NewSimpleCase(task), 57 cases.NewDeleteCase(task), 58 cases.NewManyTypesCase(task), 59 // cases.NewUnsignedCase(task), 60 cases.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 cases.NewSimpleCase(task), 73 cases.NewDeleteCase(task), 74 cases.NewManyTypesCase(task), 75 // cases.NewUnsignedCase(task), //now canal adapter can not deal with unsigned int greater than int max 76 cases.NewCompositePKeyCase(task), 77 cases.NewAlterCase(task), 78 } 79 80 runTests(testCases, env) 81 } 82 83 func testCanalJSONWatermark() { 84 env := canal.NewKafkaDockerEnv(*dockerComposeFile) 85 env.DockerComposeOperator.ExecEnv = []string{"USE_FLAT_MESSAGE=true"} 86 task := &canal.SingleTableTask{TableName: "test", UseJSON: true, EnableTiDBExtension: true} 87 testCases := []framework.Task{ 88 cases.NewSimpleCase(task), 89 cases.NewDeleteCase(task), 90 cases.NewManyTypesCase(task), 91 // tests.NewUnsignedCase(task), //now canal adapter can not deal with unsigned int greater than int max 92 cases.NewCompositePKeyCase(task), 93 cases.NewAlterCase(task), 94 } 95 96 runTests(testCases, env) 97 } 98 99 func testMySQL() { 100 env := mysql.NewDockerEnv(*dockerComposeFile) 101 task := &mysql.SingleTableTask{TableName: "test"} 102 testCases := []framework.Task{ 103 cases.NewSimpleCase(task), 104 cases.NewDeleteCase(task), 105 cases.NewManyTypesCase(task), 106 cases.NewUnsignedCase(task), 107 cases.NewCompositePKeyCase(task), 108 cases.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 117 for i := range cases { 118 env.Setup() 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 == "canalJson-extension" { 137 testCanalJSONWatermark() 138 } else if *testProtocol == "mysql" { 139 testMySQL() 140 } else { 141 log.Fatal("Unknown sink protocol", zap.String("protocol", *testProtocol)) 142 } 143 }