github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/processor/sinkmanager/table_progress_heap_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 sinkmanager 15 16 import ( 17 "testing" 18 19 "github.com/pingcap/tiflow/cdc/processor/sourcemanager/sorter" 20 "github.com/pingcap/tiflow/pkg/spanz" 21 "github.com/stretchr/testify/require" 22 ) 23 24 func TestTableProgresses(t *testing.T) { 25 t.Parallel() 26 27 p := newTableProgresses() 28 p.push(&progress{ 29 span: spanz.TableIDToComparableSpan(1), 30 nextLowerBoundPos: sorter.Position{ 31 StartTs: 1, 32 CommitTs: 2, 33 }, 34 }) 35 p.push(&progress{ 36 span: spanz.TableIDToComparableSpan(3), 37 nextLowerBoundPos: sorter.Position{ 38 StartTs: 2, 39 CommitTs: 2, 40 }, 41 }) 42 p.push(&progress{ 43 span: spanz.TableIDToComparableSpan(2), 44 nextLowerBoundPos: sorter.Position{ 45 StartTs: 2, 46 CommitTs: 3, 47 }, 48 }) 49 50 require.Equal(t, p.len(), 3) 51 52 pg := p.pop() 53 require.Equal(t, spanz.TableIDToComparableSpan(1), pg.span, "table1 is the slowest table") 54 pg = p.pop() 55 require.Equal(t, spanz.TableIDToComparableSpan(3), pg.span, "table2 is the slowest table") 56 pg = p.pop() 57 require.Equal(t, spanz.TableIDToComparableSpan(2), pg.span, "table3 is the slowest table") 58 59 require.Equal(t, p.len(), 0, "all tables are popped") 60 }