github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/kv/client_mock_test.go (about) 1 // Copyright 2021 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 /* 15 This file provides some common struct for unit tests an benchmark tests. 16 */ 17 package kv 18 19 import ( 20 "context" 21 22 "github.com/pingcap/kvproto/pkg/cdcpb" 23 "github.com/pingcap/kvproto/pkg/metapb" 24 "github.com/pingcap/tiflow/pkg/version" 25 pd "github.com/tikv/pd/client" 26 ) 27 28 type mockPDClient struct { 29 pd.Client 30 versionGen func() string 31 } 32 33 var _ pd.Client = &mockPDClient{} 34 35 func (m *mockPDClient) GetStore(ctx context.Context, storeID uint64) (*metapb.Store, error) { 36 s, err := m.Client.GetStore(ctx, storeID) 37 if err != nil { 38 return nil, err 39 } 40 s.Version = m.versionGen() 41 return s, nil 42 } 43 44 var defaultVersionGen = func() string { 45 return version.MinTiKVVersion.String() 46 } 47 48 func mockInitializedEvent(regionID, requestID uint64) *cdcpb.ChangeDataEvent { 49 initialized := &cdcpb.ChangeDataEvent{ 50 Events: []*cdcpb.Event{ 51 { 52 RegionId: regionID, 53 RequestId: requestID, 54 Event: &cdcpb.Event_Entries_{ 55 Entries: &cdcpb.Event_Entries{ 56 Entries: []*cdcpb.Event_Row{ 57 { 58 Type: cdcpb.Event_INITIALIZED, 59 }, 60 }, 61 }, 62 }, 63 }, 64 }, 65 } 66 return initialized 67 }