github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/sink/dmlsink/mq/dispatcher/partition/table_test.go (about) 1 // Copyright 2022 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 partition 15 16 import ( 17 "testing" 18 19 "github.com/pingcap/tiflow/cdc/model" 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestTableDispatcher(t *testing.T) { 24 t.Parallel() 25 26 testCases := []struct { 27 row *model.RowChangedEvent 28 expectPartition int32 29 }{ 30 {row: &model.RowChangedEvent{ 31 TableInfo: &model.TableInfo{ 32 TableName: model.TableName{ 33 Schema: "test", 34 Table: "t1", 35 }, 36 }, 37 CommitTs: 1, 38 }, expectPartition: 15}, 39 {row: &model.RowChangedEvent{ 40 TableInfo: &model.TableInfo{ 41 TableName: model.TableName{ 42 Schema: "test", 43 Table: "t1", 44 }, 45 }, 46 CommitTs: 2, 47 }, expectPartition: 15}, 48 {row: &model.RowChangedEvent{ 49 TableInfo: &model.TableInfo{ 50 TableName: model.TableName{ 51 Schema: "test", 52 Table: "t1", 53 }, 54 }, 55 CommitTs: 3, 56 }, expectPartition: 15}, 57 {row: &model.RowChangedEvent{ 58 TableInfo: &model.TableInfo{ 59 TableName: model.TableName{ 60 Schema: "test", 61 Table: "t2", 62 }, 63 }, 64 CommitTs: 1, 65 }, expectPartition: 5}, 66 {row: &model.RowChangedEvent{ 67 TableInfo: &model.TableInfo{ 68 TableName: model.TableName{ 69 Schema: "test", 70 Table: "t2", 71 }, 72 }, 73 CommitTs: 2, 74 }, expectPartition: 5}, 75 {row: &model.RowChangedEvent{ 76 TableInfo: &model.TableInfo{ 77 TableName: model.TableName{ 78 Schema: "test", 79 Table: "t2", 80 }, 81 }, 82 CommitTs: 3, 83 }, expectPartition: 5}, 84 {row: &model.RowChangedEvent{ 85 TableInfo: &model.TableInfo{ 86 TableName: model.TableName{ 87 Schema: "test", 88 Table: "t3", 89 }, 90 }, 91 CommitTs: 3, 92 }, expectPartition: 3}, 93 } 94 p := NewTableDispatcher() 95 for _, tc := range testCases { 96 index, _, err := p.DispatchRowChangedEvent(tc.row, 16) 97 require.NoError(t, err) 98 require.Equal(t, tc.expectPartition, index) 99 } 100 }