github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cdc/sink/dispatcher/table_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 TableDispatcherSuite struct{} 23 24 var _ = check.Suite(&TableDispatcherSuite{}) 25 26 func (s TableDispatcherSuite) TestTableDispatcher(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 CommitTs: 1, 38 }, exceptPartition: 15}, 39 {row: &model.RowChangedEvent{ 40 Table: &model.TableName{ 41 Schema: "test", 42 Table: "t1", 43 }, 44 CommitTs: 2, 45 }, exceptPartition: 15}, 46 {row: &model.RowChangedEvent{ 47 Table: &model.TableName{ 48 Schema: "test", 49 Table: "t1", 50 }, 51 CommitTs: 3, 52 }, exceptPartition: 15}, 53 {row: &model.RowChangedEvent{ 54 Table: &model.TableName{ 55 Schema: "test", 56 Table: "t2", 57 }, 58 CommitTs: 1, 59 }, exceptPartition: 5}, 60 {row: &model.RowChangedEvent{ 61 Table: &model.TableName{ 62 Schema: "test", 63 Table: "t2", 64 }, 65 CommitTs: 2, 66 }, exceptPartition: 5}, 67 {row: &model.RowChangedEvent{ 68 Table: &model.TableName{ 69 Schema: "test", 70 Table: "t2", 71 }, 72 CommitTs: 3, 73 }, exceptPartition: 5}, 74 {row: &model.RowChangedEvent{ 75 Table: &model.TableName{ 76 Schema: "test", 77 Table: "t3", 78 }, 79 CommitTs: 3, 80 }, exceptPartition: 3}, 81 } 82 p := newTableDispatcher(16) 83 for _, tc := range testCases { 84 c.Assert(p.Dispatch(tc.row), check.Equals, tc.exceptPartition) 85 } 86 }