github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/scheduler/internal/v3/info_provider_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 v3 15 16 import ( 17 "math" 18 "testing" 19 20 "github.com/pingcap/tiflow/cdc/model" 21 "github.com/pingcap/tiflow/cdc/processor/tablepb" 22 "github.com/pingcap/tiflow/cdc/redo" 23 "github.com/pingcap/tiflow/cdc/scheduler/internal" 24 "github.com/pingcap/tiflow/cdc/scheduler/internal/v3/keyspan" 25 "github.com/pingcap/tiflow/cdc/scheduler/internal/v3/member" 26 "github.com/pingcap/tiflow/pkg/config" 27 "github.com/stretchr/testify/require" 28 ) 29 30 func TestInfoProvider(t *testing.T) { 31 t.Parallel() 32 33 cfg := &config.SchedulerConfig{ 34 HeartbeatTick: math.MaxInt, 35 MaxTaskConcurrency: 1, 36 ChangefeedSettings: config.GetDefaultReplicaConfig().Scheduler, 37 } 38 coord := newCoordinatorForTest("a", model.ChangeFeedID{}, 1, cfg, redo.NewDisabledMetaManager()) 39 cfg.ChangefeedSettings = config.GetDefaultReplicaConfig().Scheduler 40 coord.reconciler = keyspan.NewReconcilerForTests( 41 keyspan.NewMockRegionCache(), cfg.ChangefeedSettings) 42 coord.captureM.Captures = map[model.CaptureID]*member.CaptureStatus{ 43 "a": {Tables: []tablepb.TableStatus{{ 44 Span: tablepb.Span{TableID: 1}, 45 Checkpoint: tablepb.Checkpoint{CheckpointTs: 1}, 46 }, { 47 Span: tablepb.Span{TableID: 2}, 48 Checkpoint: tablepb.Checkpoint{CheckpointTs: 1}, 49 }}}, 50 "b": {}, 51 } 52 53 // Smoke testing 54 var ip internal.InfoProvider = coord 55 tasks, err := ip.GetTaskStatuses() 56 require.Nil(t, err) 57 require.EqualValues(t, map[model.CaptureID]*model.TaskStatus{ 58 "a": {Tables: map[model.TableID]*model.TableReplicaInfo{ 59 1: {StartTs: 1}, 60 2: {StartTs: 1}, 61 }}, 62 "b": {Tables: map[model.TableID]*model.TableReplicaInfo{}}, 63 }, tasks) 64 } 65 66 func TestInfoProviderIsInitialized(t *testing.T) { 67 t.Parallel() 68 69 coord := newCoordinatorForTest("a", model.ChangeFeedID{}, 1, &config.SchedulerConfig{ 70 HeartbeatTick: math.MaxInt, 71 MaxTaskConcurrency: 1, 72 ChangefeedSettings: config.GetDefaultReplicaConfig().Scheduler, 73 }, redo.NewDisabledMetaManager()) 74 var ip internal.InfoProvider = coord 75 76 // Has not initialized yet. 77 coord.captureM.Captures = map[model.CaptureID]*member.CaptureStatus{ 78 "a": {State: member.CaptureStateUninitialized}, 79 "b": {State: member.CaptureStateInitialized}, 80 } 81 require.False(t, ip.IsInitialized()) 82 // Has not initialized yet. 83 coord.captureM.Captures = map[model.CaptureID]*member.CaptureStatus{ 84 "a": {State: member.CaptureStateInitialized}, 85 "b": {State: member.CaptureStateInitialized}, 86 } 87 require.False(t, ip.IsInitialized()) 88 89 // SetInitializedForTests 90 coord.captureM.SetInitializedForTests(true) 91 require.True(t, ip.IsInitialized()) 92 }