github.com/KinWaiYuen/client-go/v2@v2.5.4/testutils/mockstore.go (about) 1 // Copyright 2021 TiKV Authors 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package testutils 16 17 import ( 18 "github.com/KinWaiYuen/client-go/v2/internal/mockstore/cluster" 19 "github.com/KinWaiYuen/client-go/v2/internal/mockstore/mocktikv" 20 pd "github.com/tikv/pd/client" 21 ) 22 23 // Cluster simulates a TiKV cluster. 24 type Cluster = cluster.Cluster 25 26 // CoprRPCHandler is the interface to handle coprocessor RPC commands. 27 type CoprRPCHandler = mocktikv.CoprRPCHandler 28 29 // MVCCStore is a mvcc key-value storage. 30 type MVCCStore = mocktikv.MVCCStore 31 32 // MVCCPair is a KV pair read from MvccStore or an error if any occurs. 33 type MVCCPair = mocktikv.Pair 34 35 // MockCluster simulates a TiKV cluster. 36 type MockCluster = mocktikv.Cluster 37 38 // MockClient sends kv RPC calls to mock cluster. 39 type MockClient = mocktikv.RPCClient 40 41 // RPCSession stores session scope rpc data. 42 type RPCSession = mocktikv.Session 43 44 // NewMockTiKV creates a TiKV client and PD client from options. 45 func NewMockTiKV(path string, coprHandler CoprRPCHandler) (*MockClient, *MockCluster, pd.Client, error) { 46 return mocktikv.NewTiKVAndPDClient(path, coprHandler) 47 } 48 49 // BootstrapWithSingleStore initializes a Cluster with 1 Region and 1 Store. 50 var BootstrapWithSingleStore = mocktikv.BootstrapWithSingleStore 51 52 // BootstrapWithMultiStores initializes a Cluster with 1 Region and n Stores. 53 var BootstrapWithMultiStores = mocktikv.BootstrapWithMultiStores 54 55 // BootstrapWithMultiRegions initializes a Cluster with multiple Regions and 1 56 // Store. The number of Regions will be len(splitKeys) + 1. 57 var BootstrapWithMultiRegions = mocktikv.BootstrapWithMultiRegions 58 59 // ErrLocked is returned when trying to Read/Write on a locked key. Client should 60 // backoff or cleanup the lock then retry. 61 type ErrLocked = mocktikv.ErrLocked