-
Notifications
You must be signed in to change notification settings - Fork 726
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
close #8823 Signed-off-by: ti-chi-bot <[email protected]> Signed-off-by: Ryan Leung <[email protected]> Co-authored-by: Ryan Leung <[email protected]> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
86d4ad0
commit ec3892a
Showing
4 changed files
with
117 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2024 TiKV Project Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mockserver | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pingcap/kvproto/pkg/pdpb" | ||
"github.com/tikv/pd/pkg/core" | ||
"github.com/tikv/pd/pkg/storage" | ||
"github.com/tikv/pd/pkg/utils/grpcutil" | ||
) | ||
|
||
// MockServer is used to mock Server for test use. | ||
type MockServer struct { | ||
ctx context.Context | ||
member, leader *pdpb.Member | ||
storage storage.Storage | ||
bc *core.BasicCluster | ||
} | ||
|
||
// NewMockServer creates a new MockServer. | ||
func NewMockServer(ctx context.Context, member, leader *pdpb.Member, storage storage.Storage, bc *core.BasicCluster) *MockServer { | ||
return &MockServer{ | ||
ctx: ctx, | ||
member: member, | ||
leader: leader, | ||
storage: storage, | ||
bc: bc, | ||
} | ||
} | ||
|
||
// LoopContext returns the context of the server. | ||
func (s *MockServer) LoopContext() context.Context { | ||
return s.ctx | ||
} | ||
|
||
// ClusterID returns the cluster ID of the server. | ||
func (*MockServer) ClusterID() uint64 { | ||
return 1 | ||
} | ||
|
||
// GetMemberInfo returns the member info of the server. | ||
func (s *MockServer) GetMemberInfo() *pdpb.Member { | ||
return s.member | ||
} | ||
|
||
// GetLeader returns the leader of the server. | ||
func (s *MockServer) GetLeader() *pdpb.Member { | ||
return s.leader | ||
} | ||
|
||
// GetStorage returns the storage of the server. | ||
func (s *MockServer) GetStorage() storage.Storage { | ||
return s.storage | ||
} | ||
|
||
// Name returns the name of the server. | ||
func (*MockServer) Name() string { | ||
return "mock-server" | ||
} | ||
|
||
// GetRegions returns the regions of the server. | ||
func (s *MockServer) GetRegions() []*core.RegionInfo { | ||
return s.bc.GetRegions() | ||
} | ||
|
||
// GetTLSConfig returns the TLS config of the server. | ||
func (*MockServer) GetTLSConfig() *grpcutil.TLSConfig { | ||
return &grpcutil.TLSConfig{} | ||
} | ||
|
||
// GetBasicCluster returns the basic cluster of the server. | ||
func (s *MockServer) GetBasicCluster() *core.BasicCluster { | ||
return s.bc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters