github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/integration/framework/mysql/single_table.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 mysql 15 16 import ( 17 "database/sql" 18 "time" 19 20 "github.com/pingcap/log" 21 "github.com/pingcap/ticdc/integration/framework" 22 ) 23 24 const ( 25 testDbName = "testdb" 26 ) 27 28 // SingleTableTask provides a basic implementation for an Avro test case 29 type SingleTableTask struct { 30 TableName string 31 CheckOleValue bool 32 } 33 34 // Name implements Task 35 func (c *SingleTableTask) Name() string { 36 log.Warn("SingleTableTask should be embedded in another Task") 37 return "SingleTableTask-" + c.TableName 38 } 39 40 // GetCDCProfile implements Task 41 func (c *SingleTableTask) GetCDCProfile() *framework.CDCProfile { 42 sinkURI := "mysql://downstream-tidb:4000/" + testDbName 43 if c.CheckOleValue { 44 sinkURI = "simple-mysql://downstream-tidb:4000/" + testDbName + "?check-old-value=true" 45 } 46 return &framework.CDCProfile{ 47 PDUri: "http://upstream-pd:2379", 48 SinkURI: sinkURI, 49 Opts: map[string]string{}, 50 ConfigFile: "/config/enable-oldvalue-config.toml", 51 } 52 } 53 54 // Prepare implements Task 55 func (c *SingleTableTask) Prepare(taskContext *framework.TaskContext) error { 56 err := taskContext.CreateDB(testDbName) 57 if err != nil { 58 return err 59 } 60 61 _ = taskContext.Upstream.Close() 62 taskContext.Upstream, err = sql.Open("mysql", framework.UpstreamDSN+testDbName) 63 if err != nil { 64 return err 65 } 66 67 _ = taskContext.Downstream.Close() 68 taskContext.Downstream, err = sql.Open("mysql", framework.DownstreamDSN+testDbName) 69 if err != nil { 70 return err 71 } 72 taskContext.Downstream.SetConnMaxLifetime(5 * time.Second) 73 74 if taskContext.WaitForReady != nil { 75 log.Info("Waiting for env to be ready") 76 return taskContext.WaitForReady() 77 } 78 return nil 79 } 80 81 // Run implements Task 82 func (c *SingleTableTask) Run(taskContext *framework.TaskContext) error { 83 log.Warn("SingleTableTask has been run") 84 return nil 85 }