github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cdc/sink/txns_heap_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 sink
    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 TxnsHeapSuite struct{}
    23  
    24  var _ = check.Suite(&TxnsHeapSuite{})
    25  
    26  func (s TxnsHeapSuite) TestTxnsHeap(c *check.C) {
    27  	defer testleak.AfterTest(c)()
    28  	testCases := []struct {
    29  		txnsMap  map[model.TableID][]*model.SingleTableTxn
    30  		expected []*model.SingleTableTxn
    31  	}{{
    32  		txnsMap:  nil,
    33  		expected: nil,
    34  	}, {
    35  		txnsMap: map[model.TableID][]*model.SingleTableTxn{
    36  			1: {
    37  				{CommitTs: 1}, {CommitTs: 3}, {CommitTs: 5}, {CommitTs: 7}, {CommitTs: 9},
    38  			},
    39  			2: {
    40  				{CommitTs: 1}, {CommitTs: 10}, {CommitTs: 15}, {CommitTs: 15}, {CommitTs: 15},
    41  			},
    42  			3: {
    43  				{CommitTs: 1}, {CommitTs: 1}, {CommitTs: 1}, {CommitTs: 2}, {CommitTs: 3},
    44  			},
    45  		},
    46  		expected: []*model.SingleTableTxn{
    47  			{CommitTs: 1},
    48  			{CommitTs: 1},
    49  			{CommitTs: 1},
    50  			{CommitTs: 1},
    51  			{CommitTs: 1},
    52  			{CommitTs: 2},
    53  			{CommitTs: 3},
    54  			{CommitTs: 3},
    55  			{CommitTs: 5},
    56  			{CommitTs: 7},
    57  			{CommitTs: 9},
    58  			{CommitTs: 10},
    59  			{CommitTs: 15},
    60  			{CommitTs: 15},
    61  			{CommitTs: 15},
    62  		},
    63  	}}
    64  
    65  	for _, tc := range testCases {
    66  		h := newTxnsHeap(tc.txnsMap)
    67  		i := 0
    68  		h.iter(func(txn *model.SingleTableTxn) {
    69  			c.Assert(txn, check.DeepEquals, tc.expected[i])
    70  			i++
    71  		})
    72  	}
    73  }