github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cdc/sink/dispatcher/index_value_test.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 dispatcher 15 16 import ( 17 "github.com/pingcap/check" 18 "github.com/pingcap/ticdc/cdc/model" 19 "github.com/pingcap/ticdc/pkg/util/testleak" 20 ) 21 22 type IndexValueDispatcherSuite struct{} 23 24 var _ = check.Suite(&IndexValueDispatcherSuite{}) 25 26 func (s IndexValueDispatcherSuite) TestIndexValueDispatcher(c *check.C) { 27 defer testleak.AfterTest(c)() 28 testCases := []struct { 29 row *model.RowChangedEvent 30 exceptPartition int32 31 }{ 32 {row: &model.RowChangedEvent{ 33 Table: &model.TableName{ 34 Schema: "test", 35 Table: "t1", 36 }, 37 Columns: []*model.Column{ 38 { 39 Name: "a", 40 Value: 11, 41 Flag: model.HandleKeyFlag, 42 }, { 43 Name: "b", 44 Value: 22, 45 Flag: 0, 46 }, 47 }, 48 }, exceptPartition: 2}, 49 {row: &model.RowChangedEvent{ 50 Table: &model.TableName{ 51 Schema: "test", 52 Table: "t1", 53 }, 54 Columns: []*model.Column{ 55 { 56 Name: "a", 57 Value: 22, 58 Flag: model.HandleKeyFlag, 59 }, { 60 Name: "b", 61 Value: 22, 62 Flag: 0, 63 }, 64 }, 65 }, exceptPartition: 11}, 66 {row: &model.RowChangedEvent{ 67 Table: &model.TableName{ 68 Schema: "test", 69 Table: "t1", 70 }, 71 Columns: []*model.Column{ 72 { 73 Name: "a", 74 Value: 11, 75 Flag: model.HandleKeyFlag, 76 }, { 77 Name: "b", 78 Value: 33, 79 Flag: 0, 80 }, 81 }, 82 }, exceptPartition: 2}, 83 {row: &model.RowChangedEvent{ 84 Table: &model.TableName{ 85 Schema: "test", 86 Table: "t2", 87 }, 88 Columns: []*model.Column{ 89 { 90 Name: "a", 91 Value: 11, 92 Flag: model.HandleKeyFlag, 93 }, { 94 Name: "b", 95 Value: 22, 96 Flag: model.HandleKeyFlag, 97 }, 98 }, 99 }, exceptPartition: 5}, 100 {row: &model.RowChangedEvent{ 101 Table: &model.TableName{ 102 Schema: "test", 103 Table: "t2", 104 }, 105 Columns: []*model.Column{ 106 { 107 Name: "b", 108 Value: 22, 109 Flag: model.HandleKeyFlag, 110 }, { 111 Name: "a", 112 Value: 11, 113 Flag: model.HandleKeyFlag, 114 }, 115 }, 116 }, exceptPartition: 5}, 117 {row: &model.RowChangedEvent{ 118 Table: &model.TableName{ 119 Schema: "test", 120 Table: "t2", 121 }, 122 Columns: []*model.Column{ 123 { 124 Name: "a", 125 Value: 11, 126 Flag: model.HandleKeyFlag, 127 }, { 128 Name: "b", 129 Value: 0, 130 Flag: model.HandleKeyFlag, 131 }, 132 }, 133 }, exceptPartition: 14}, 134 {row: &model.RowChangedEvent{ 135 Table: &model.TableName{ 136 Schema: "test", 137 Table: "t2", 138 }, 139 Columns: []*model.Column{ 140 { 141 Name: "a", 142 Value: 11, 143 Flag: model.HandleKeyFlag, 144 }, { 145 Name: "b", 146 Value: 33, 147 Flag: model.HandleKeyFlag, 148 }, 149 }, 150 }, exceptPartition: 2}, 151 } 152 p := newIndexValueDispatcher(16) 153 for _, tc := range testCases { 154 c.Assert(p.Dispatch(tc.row), check.Equals, tc.exceptPartition) 155 } 156 }