github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cdc/sink/dispatcher/ts_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  	"testing"
    18  
    19  	"github.com/pingcap/check"
    20  	"github.com/pingcap/ticdc/cdc/model"
    21  	"github.com/pingcap/ticdc/pkg/util/testleak"
    22  )
    23  
    24  func Test(t *testing.T) { check.TestingT(t) }
    25  
    26  type TsDispatcherSuite struct{}
    27  
    28  var _ = check.Suite(&TsDispatcherSuite{})
    29  
    30  func (s TsDispatcherSuite) TestTsDispatcher(c *check.C) {
    31  	defer testleak.AfterTest(c)()
    32  	testCases := []struct {
    33  		row             *model.RowChangedEvent
    34  		exceptPartition int32
    35  	}{
    36  		{row: &model.RowChangedEvent{
    37  			Table: &model.TableName{
    38  				Schema: "test",
    39  				Table:  "t1",
    40  			},
    41  			CommitTs: 1,
    42  		}, exceptPartition: 1},
    43  		{row: &model.RowChangedEvent{
    44  			Table: &model.TableName{
    45  				Schema: "test",
    46  				Table:  "t1",
    47  			},
    48  			CommitTs: 2,
    49  		}, exceptPartition: 2},
    50  		{row: &model.RowChangedEvent{
    51  			Table: &model.TableName{
    52  				Schema: "test",
    53  				Table:  "t1",
    54  			},
    55  			CommitTs: 3,
    56  		}, exceptPartition: 3},
    57  		{row: &model.RowChangedEvent{
    58  			Table: &model.TableName{
    59  				Schema: "test",
    60  				Table:  "t2",
    61  			},
    62  			CommitTs: 1,
    63  		}, exceptPartition: 1},
    64  		{row: &model.RowChangedEvent{
    65  			Table: &model.TableName{
    66  				Schema: "test",
    67  				Table:  "t2",
    68  			},
    69  			CommitTs: 2,
    70  		}, exceptPartition: 2},
    71  		{row: &model.RowChangedEvent{
    72  			Table: &model.TableName{
    73  				Schema: "test",
    74  				Table:  "t2",
    75  			},
    76  			CommitTs: 3,
    77  		}, exceptPartition: 3},
    78  	}
    79  	p := &tsDispatcher{partitionNum: 16}
    80  	for _, tc := range testCases {
    81  		c.Assert(p.Dispatch(tc.row), check.Equals, tc.exceptPartition)
    82  	}
    83  }