Skip to content

Commit

Permalink
store/tikv: move split test to /tests (#23643)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing authored Mar 30, 2021
1 parent a8a52c0 commit 402e3c8
Show file tree
Hide file tree
Showing 3 changed files with 255 additions and 258 deletions.
112 changes: 0 additions & 112 deletions store/tikv/split_test.go

This file was deleted.

146 changes: 0 additions & 146 deletions store/tikv/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@ import (
"time"

. "github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
pb "github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/tidb/store/tikv/kv"
"github.com/pingcap/tidb/store/tikv/oracle"
"github.com/pingcap/tidb/store/tikv/oracle/oracles"
"github.com/pingcap/tidb/store/tikv/tikvrpc"
pd "github.com/tikv/pd/client"
)

var errStopped = errors.New("stopped")

type testStoreSuite struct {
testStoreSuiteBase
}
Expand Down Expand Up @@ -100,146 +94,6 @@ func (s *testStoreSuite) TestOracle(c *C) {
wg.Wait()
}

type mockPDClient struct {
sync.RWMutex
client pd.Client
stop bool
}

func (c *mockPDClient) enable() {
c.Lock()
defer c.Unlock()
c.stop = false
}

func (c *mockPDClient) disable() {
c.Lock()
defer c.Unlock()
c.stop = true
}

func (c *mockPDClient) GetAllMembers(ctx context.Context) ([]*pdpb.Member, error) {
return nil, nil
}

func (c *mockPDClient) GetClusterID(context.Context) uint64 {
return 1
}

func (c *mockPDClient) GetTS(ctx context.Context) (int64, int64, error) {
c.RLock()
defer c.RUnlock()

if c.stop {
return 0, 0, errors.Trace(errStopped)
}
return c.client.GetTS(ctx)
}

func (c *mockPDClient) GetLocalTS(ctx context.Context, dcLocation string) (int64, int64, error) {
return c.GetTS(ctx)
}

func (c *mockPDClient) GetTSAsync(ctx context.Context) pd.TSFuture {
return nil
}

func (c *mockPDClient) GetLocalTSAsync(ctx context.Context, dcLocation string) pd.TSFuture {
return nil
}

func (c *mockPDClient) GetRegion(ctx context.Context, key []byte) (*pd.Region, error) {
c.RLock()
defer c.RUnlock()

if c.stop {
return nil, errors.Trace(errStopped)
}
return c.client.GetRegion(ctx, key)
}

func (c *mockPDClient) GetRegionFromMember(ctx context.Context, key []byte, memberURLs []string) (*pd.Region, error) {
return nil, nil
}

func (c *mockPDClient) GetPrevRegion(ctx context.Context, key []byte) (*pd.Region, error) {
c.RLock()
defer c.RUnlock()

if c.stop {
return nil, errors.Trace(errStopped)
}
return c.client.GetPrevRegion(ctx, key)
}

func (c *mockPDClient) GetRegionByID(ctx context.Context, regionID uint64) (*pd.Region, error) {
c.RLock()
defer c.RUnlock()

if c.stop {
return nil, errors.Trace(errStopped)
}
return c.client.GetRegionByID(ctx, regionID)
}

func (c *mockPDClient) ScanRegions(ctx context.Context, startKey []byte, endKey []byte, limit int) ([]*pd.Region, error) {
c.RLock()
defer c.RUnlock()

if c.stop {
return nil, errors.Trace(errStopped)
}
return c.client.ScanRegions(ctx, startKey, endKey, limit)
}

func (c *mockPDClient) GetStore(ctx context.Context, storeID uint64) (*metapb.Store, error) {
c.RLock()
defer c.RUnlock()

if c.stop {
return nil, errors.Trace(errStopped)
}
return c.client.GetStore(ctx, storeID)
}

func (c *mockPDClient) GetAllStores(ctx context.Context, opts ...pd.GetStoreOption) ([]*metapb.Store, error) {
c.RLock()
defer c.Unlock()

if c.stop {
return nil, errors.Trace(errStopped)
}
return c.client.GetAllStores(ctx)
}

func (c *mockPDClient) UpdateGCSafePoint(ctx context.Context, safePoint uint64) (uint64, error) {
panic("unimplemented")
}

func (c *mockPDClient) UpdateServiceGCSafePoint(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error) {
panic("unimplemented")
}

func (c *mockPDClient) Close() {}

func (c *mockPDClient) ScatterRegion(ctx context.Context, regionID uint64) error {
return nil
}

func (c *mockPDClient) ScatterRegions(ctx context.Context, regionsID []uint64, opts ...pd.RegionsOption) (*pdpb.ScatterRegionResponse, error) {
return nil, nil
}

func (c *mockPDClient) SplitRegions(ctx context.Context, splitKeys [][]byte, opts ...pd.RegionsOption) (*pdpb.SplitRegionsResponse, error) {
return nil, nil
}

func (c *mockPDClient) GetOperator(ctx context.Context, regionID uint64) (*pdpb.GetOperatorResponse, error) {
return &pdpb.GetOperatorResponse{Status: pdpb.OperatorStatus_SUCCESS}, nil
}

func (c *mockPDClient) GetLeaderAddr() string { return "mockpd" }

type checkRequestClient struct {
Client
priority pb.CommandPri
Expand Down
Loading

0 comments on commit 402e3c8

Please sign in to comment.