github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/pkg/shardddl/optimism/column_test.go (about) 1 // Copyright 2021 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 optimism 15 16 import ( 17 . "github.com/pingcap/check" 18 ) 19 20 type testColumn struct{} 21 22 var _ = Suite(&testColumn{}) 23 24 func (t *testColumn) TestColumnETCD(c *C) { 25 defer clearTestInfoOperation(c) 26 27 var ( 28 task = "test" 29 downSchema = "shardddl" 30 downTable = "tb" 31 source1 = "mysql-replica-1" 32 source2 = "mysql-replica-2" 33 upSchema1 = "shardddl1" 34 upTable1 = "tb1" 35 upSchema2 = "shardddl2" 36 upTable2 = "tb2" 37 info1 = NewInfo(task, source1, upSchema1, upTable1, downSchema, downTable, nil, nil, nil) 38 lockID = genDDLLockID(info1) 39 ) 40 rev1, putted, err := PutDroppedColumns(etcdTestCli, lockID, source1, upSchema1, upTable1, []string{"a"}, DropNotDone) 41 c.Assert(err, IsNil) 42 c.Assert(putted, IsTrue) 43 rev2, putted, err := PutDroppedColumns(etcdTestCli, lockID, source1, upSchema1, upTable1, []string{"b"}, DropNotDone) 44 c.Assert(err, IsNil) 45 c.Assert(putted, IsTrue) 46 c.Assert(rev2, Greater, rev1) 47 rev3, putted, err := PutDroppedColumns(etcdTestCli, lockID, source1, upSchema2, upTable2, []string{"b"}, DropNotDone) 48 c.Assert(err, IsNil) 49 c.Assert(putted, IsTrue) 50 c.Assert(rev3, Greater, rev2) 51 rev4, putted, err := PutDroppedColumns(etcdTestCli, lockID, source2, upSchema1, upTable1, []string{"b"}, DropNotDone) 52 c.Assert(err, IsNil) 53 c.Assert(putted, IsTrue) 54 c.Assert(rev4, Greater, rev3) 55 rev5, putted, err := PutDroppedColumns(etcdTestCli, lockID, source2, upSchema1, upTable1, []string{"b", "c"}, DropNotDone) 56 c.Assert(err, IsNil) 57 c.Assert(putted, IsTrue) 58 c.Assert(rev5, Greater, rev4) 59 60 expectedColm := map[string]map[string]map[string]map[string]map[string]DropColumnStage{ 61 lockID: { 62 "a": {source1: {upSchema1: {upTable1: DropNotDone}}}, 63 "b": { 64 source1: { 65 upSchema1: {upTable1: DropNotDone}, 66 upSchema2: {upTable2: DropNotDone}, 67 }, 68 source2: {upSchema1: {upTable1: DropNotDone}}, 69 }, 70 "c": { 71 source2: {upSchema1: {upTable1: DropNotDone}}, 72 }, 73 }, 74 } 75 colm, rev6, err := GetAllDroppedColumns(etcdTestCli) 76 c.Assert(err, IsNil) 77 c.Assert(colm, DeepEquals, expectedColm) 78 c.Assert(rev6, Equals, rev5) 79 80 rev7, deleted, err := DeleteDroppedColumns(etcdTestCli, lockID, "b", "c") 81 c.Assert(err, IsNil) 82 c.Assert(deleted, IsTrue) 83 c.Assert(rev7, Greater, rev6) 84 85 delete(expectedColm[lockID], "b") 86 delete(expectedColm[lockID], "c") 87 colm, rev8, err := GetAllDroppedColumns(etcdTestCli) 88 c.Assert(err, IsNil) 89 c.Assert(colm, DeepEquals, expectedColm) 90 c.Assert(rev8, Equals, rev7) 91 }