diff --git a/bindinfo/bind_test.go b/bindinfo/bind_test.go index fd34c73b683bf..0ec409e37a06e 100644 --- a/bindinfo/bind_test.go +++ b/bindinfo/bind_test.go @@ -45,7 +45,7 @@ import ( "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" dto "github.com/prometheus/client_model/go" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) func TestT(t *testing.T) { @@ -62,7 +62,7 @@ func TestT(t *testing.T) { var _ = Suite(&testSuite{}) type testSuite struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage domain *domain.Domain *parser.Parser @@ -115,7 +115,7 @@ func (s *testSuite) SetUpSuite(c *C) { useMockTikv := *mockTikv if useMockTikv { store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 0cc98f6ef35e6..39fee9b9d7432 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -48,7 +48,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testutil" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) var _ = Suite(&testIntegrationSuite1{&testIntegrationSuite{}}) @@ -60,7 +60,7 @@ var _ = Suite(&testIntegrationSuite6{&testIntegrationSuite{}}) type testIntegrationSuite struct { lease time.Duration - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage dom *domain.Domain ctx sessionctx.Context @@ -72,7 +72,7 @@ func setupIntegrationSuite(s *testIntegrationSuite, c *C) { ddl.SetWaitTimeWhenErrorOccurred(0) s.store, err = mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/ddl/db_test.go b/ddl/db_test.go index a98c9107e67ad..e786e24019dde 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -61,7 +61,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testutil" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) const ( @@ -86,7 +86,7 @@ const defaultBatchSize = 1024 const defaultReorgBatchSize = 256 type testDBSuite struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage dom *domain.Domain schemaName string @@ -107,7 +107,7 @@ func setUpSuite(s *testDBSuite, c *C) { ddl.SetWaitTimeWhenErrorOccurred(0) s.store, err = mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/ddl/failtest/fail_db_test.go b/ddl/failtest/fail_db_test.go index 877210cb7e51c..0581e7e87b2cd 100644 --- a/ddl/failtest/fail_db_test.go +++ b/ddl/failtest/fail_db_test.go @@ -41,7 +41,7 @@ import ( "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" . "github.com/pingcap/tidb/util/testutil" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) func TestT(t *testing.T) { @@ -63,7 +63,7 @@ func TestT(t *testing.T) { var _ = SerialSuites(&testFailDBSuite{}) type testFailDBSuite struct { - cluster cluster.Cluster + cluster testutils.Cluster lease time.Duration store kv.Storage dom *domain.Domain @@ -78,7 +78,7 @@ func (s *testFailDBSuite) SetUpSuite(c *C) { ddl.SetWaitTimeWhenErrorOccurred(1 * time.Microsecond) var err error s.store, err = mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/ddl/serial_test.go b/ddl/serial_test.go index 82ed77d82fd16..8c6e094e046a7 100644 --- a/ddl/serial_test.go +++ b/ddl/serial_test.go @@ -49,7 +49,7 @@ import ( "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/testkit" . "github.com/pingcap/tidb/util/testutil" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) // Make it serial because config is modified in test cases. @@ -61,7 +61,7 @@ var _ = Suite(&testIntegrationSuite7{&testIntegrationSuite{}}) type testSerialSuite struct { CommonHandleSuite store kv.Storage - cluster cluster.Cluster + cluster testutils.Cluster dom *domain.Domain } @@ -76,7 +76,7 @@ func (s *testSerialSuite) SetUpSuite(c *C) { var err error s.store, err = mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/executor/aggfuncs/aggfunc_test.go b/executor/aggfuncs/aggfunc_test.go index bd067d308e40c..96bc093a48214 100644 --- a/executor/aggfuncs/aggfunc_test.go +++ b/executor/aggfuncs/aggfunc_test.go @@ -42,7 +42,7 @@ import ( "github.com/pingcap/tidb/util/hack" "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tidb/util/set" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) const ( @@ -61,7 +61,7 @@ func TestT(t *testing.T) { type testSuite struct { *parser.Parser ctx sessionctx.Context - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage domain *domain.Domain } @@ -71,7 +71,7 @@ func (s *testSuite) SetUpSuite(c *C) { s.ctx = mock.NewContext() s.ctx.GetSessionVars().StmtCtx.TimeZone = time.Local store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/executor/analyze_test.go b/executor/analyze_test.go index 7ea9c0996526d..4c76ec844686f 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -45,7 +45,7 @@ import ( "github.com/pingcap/tidb/util/collate" "github.com/pingcap/tidb/util/israce" "github.com/pingcap/tidb/util/testkit" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" "github.com/tikv/client-go/v2/tikvrpc" ) @@ -288,9 +288,9 @@ func (s *testSuite1) TestAnalyzeIndexExtractTopN(c *C) { } func (s *testFastAnalyze) TestAnalyzeFastSample(c *C) { - var cls cluster.Cluster + var cls testutils.Cluster store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) cls = c }), @@ -395,9 +395,9 @@ func checkHistogram(sc *stmtctx.StatementContext, hg *statistics.Histogram) (boo } func (s *testFastAnalyze) TestFastAnalyze(c *C) { - var cls cluster.Cluster + var cls testutils.Cluster store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) cls = c }), @@ -714,9 +714,9 @@ func (s *testFastAnalyze) TestFastAnalyzeRetryRowCount(c *C) { return cli } - var cls cluster.Cluster + var cls testutils.Cluster store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) cls = c }), diff --git a/executor/chunk_size_control_test.go b/executor/chunk_size_control_test.go index 9e2c575d9a417..7c33f3fd9c3e9 100644 --- a/executor/chunk_size_control_test.go +++ b/executor/chunk_size_control_test.go @@ -30,7 +30,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/testkit" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" "github.com/tikv/client-go/v2/tikvrpc" ) @@ -67,7 +67,7 @@ func (c *testSlowClient) GetDelay(regionID uint64) time.Duration { } // manipulateCluster splits this cluster's region by splitKeys and returns regionIDs after split -func manipulateCluster(cluster cluster.Cluster, splitKeys [][]byte) []uint64 { +func manipulateCluster(cluster testutils.Cluster, splitKeys [][]byte) []uint64 { if len(splitKeys) == 0 { return nil } @@ -113,7 +113,7 @@ type testChunkSizeControlKit struct { dom *domain.Domain tk *testkit.TestKit client *testSlowClient - cluster cluster.Cluster + cluster testutils.Cluster } type testChunkSizeControlSuite struct { @@ -135,7 +135,7 @@ func (s *testChunkSizeControlSuite) SetUpSuite(c *C) { var err error kit.store, err = mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) kit.cluster = c }), @@ -157,7 +157,7 @@ func (s *testChunkSizeControlSuite) SetUpSuite(c *C) { } func (s *testChunkSizeControlSuite) getKit(name string) ( - kv.Storage, *domain.Domain, *testkit.TestKit, *testSlowClient, cluster.Cluster) { + kv.Storage, *domain.Domain, *testkit.TestKit, *testSlowClient, testutils.Cluster) { x := s.m[name] return x.store, x.dom, x.tk, x.client, x.cluster } diff --git a/executor/executor_test.go b/executor/executor_test.go index 3e8a377e4d45c..bd53f3622552a 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -77,8 +77,8 @@ import ( "github.com/pingcap/tidb/util/testutil" "github.com/pingcap/tidb/util/timeutil" "github.com/pingcap/tipb/go-tipb" - "github.com/tikv/client-go/v2/mockstore/cluster" "github.com/tikv/client-go/v2/oracle" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" "github.com/tikv/client-go/v2/tikvrpc" "google.golang.org/grpc" @@ -168,13 +168,13 @@ type testStaleTxnSuite struct{ *baseTestSuite } type testCoprCache struct { store kv.Storage dom *domain.Domain - cls cluster.Cluster + cls testutils.Cluster } type testPrepareSuite struct{ testData testutil.TestData } type testResourceTagSuite struct{ *baseTestSuite } type baseTestSuite struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage domain *domain.Domain *parser.Parser @@ -189,7 +189,7 @@ func (s *baseTestSuite) SetUpSuite(c *C) { useMockTikv := *mockTikv if useMockTikv { store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), @@ -5707,7 +5707,7 @@ func (s *testSuite) TestOOMPanicAction(c *C) { type testRecoverTable struct { store kv.Storage dom *domain.Domain - cluster cluster.Cluster + cluster testutils.Cluster cli *regionProperityClient } @@ -5722,7 +5722,7 @@ func (s *testRecoverTable) SetUpSuite(c *C) { var err error s.store, err = mockstore.NewMockStore( mockstore.WithClientHijacker(hijackClient), - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), @@ -7362,7 +7362,7 @@ func (s *testCoprCache) SetUpSuite(c *C) { } var err error s.store, err = mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cls = c }), diff --git a/executor/sample_test.go b/executor/sample_test.go index 08bffe904cf47..dec765a2bb555 100644 --- a/executor/sample_test.go +++ b/executor/sample_test.go @@ -27,13 +27,13 @@ import ( "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/util/testkit" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) var _ = SerialSuites(&testTableSampleSuite{}) type testTableSampleSuite struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage domain *domain.Domain } @@ -43,7 +43,7 @@ func (s *testTableSampleSuite) SetUpSuite(c *C) { useMockTikv := *mockTikv if useMockTikv { store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/executor/seqtest/seq_executor_test.go b/executor/seqtest/seq_executor_test.go index 69d05c658de35..a6f7e46aebe7d 100644 --- a/executor/seqtest/seq_executor_test.go +++ b/executor/seqtest/seq_executor_test.go @@ -58,7 +58,7 @@ import ( "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testutil" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" "github.com/tikv/client-go/v2/tikvrpc" ) @@ -81,7 +81,7 @@ var _ = SerialSuites(&seqTestSuite{}) var _ = SerialSuites(&seqTestSuite1{}) type seqTestSuite struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage domain *domain.Domain *parser.Parser @@ -96,7 +96,7 @@ func (s *seqTestSuite) SetUpSuite(c *C) { if useMockTikv { var err error s.store, err = mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/executor/tiflash_test.go b/executor/tiflash_test.go index cca6bbe4841e5..865841dd43324 100644 --- a/executor/tiflash_test.go +++ b/executor/tiflash_test.go @@ -37,7 +37,7 @@ import ( "github.com/pingcap/tidb/util/israce" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) type tiflashTestSuite struct { @@ -49,7 +49,7 @@ type tiflashTestSuite struct { func (s *tiflashTestSuite) SetUpSuite(c *C) { var err error s.store, err = mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockCluster := c.(*unistore.Cluster) _, _, region1 := mockstore.BootstrapWithSingleStore(c) tiflashIdx := 0 diff --git a/executor/update_test.go b/executor/update_test.go index a467e03c4df6f..49a980ec01676 100644 --- a/executor/update_test.go +++ b/executor/update_test.go @@ -26,11 +26,11 @@ import ( "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/util/testkit" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) type testUpdateSuite struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage domain *domain.Domain *parser.Parser @@ -42,7 +42,7 @@ func (s *testUpdateSuite) SetUpSuite(c *C) { useMockTikv := *mockTikv if useMockTikv { store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/go.mod b/go.mod index 8a354b9b08e15..c21ad7064baba 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,7 @@ require ( github.com/shirou/gopsutil v3.21.2+incompatible github.com/soheilhy/cmux v0.1.4 github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 - github.com/tikv/client-go/v2 v2.0.0-alpha.0.20210706041121-6ca00989ddb4 + github.com/tikv/client-go/v2 v2.0.0-alpha.0.20210708041317-16fb6792bffa github.com/tikv/pd v1.1.0-beta.0.20210323121136-78679e5e209d github.com/twmb/murmur3 v1.1.3 github.com/uber-go/atomic v1.4.0 diff --git a/go.sum b/go.sum index 8a84ca11b900a..9f6cd155e2da8 100644 --- a/go.sum +++ b/go.sum @@ -562,8 +562,8 @@ github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfK github.com/tidwall/gjson v1.3.5/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/tikv/client-go/v2 v2.0.0-alpha.0.20210706041121-6ca00989ddb4 h1:kokFPtkpQ2ZH910iuxfmKMk8M9zzCLskN8h1LELWN20= -github.com/tikv/client-go/v2 v2.0.0-alpha.0.20210706041121-6ca00989ddb4/go.mod h1:crzTwbliZf57xC5ZSzmQx4iMZCLCGhA364to+E2JAPU= +github.com/tikv/client-go/v2 v2.0.0-alpha.0.20210708041317-16fb6792bffa h1:NuHeobWz2bqkN+ei+bp8qKqBYhWm5HiLj9SVYzzq1As= +github.com/tikv/client-go/v2 v2.0.0-alpha.0.20210708041317-16fb6792bffa/go.mod h1:crzTwbliZf57xC5ZSzmQx4iMZCLCGhA364to+E2JAPU= github.com/tikv/pd v1.1.0-beta.0.20210323121136-78679e5e209d h1:K0XnvsnT6ofLDuM8Rt3PuFQO4p8bNraeHYstspD316g= github.com/tikv/pd v1.1.0-beta.0.20210323121136-78679e5e209d/go.mod h1:Jw9KG11C/23Rr7DW4XWQ7H5xOgGZo6DFL1OKAF4+Igw= github.com/tklauser/go-sysconf v0.3.4 h1:HT8SVixZd3IzLdfs/xlpq0jeSfTX57g1v6wB1EuzV7M= diff --git a/server/conn_test.go b/server/conn_test.go index 6c259303d78a6..dfdc52ff234dc 100644 --- a/server/conn_test.go +++ b/server/conn_test.go @@ -38,7 +38,7 @@ import ( "github.com/pingcap/tidb/util/arena" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) type ConnTestSuite struct { @@ -52,7 +52,7 @@ func (ts *ConnTestSuite) SetUpSuite(c *C) { testleak.BeforeTest() var err error ts.store, err = mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockCluster := c.(*unistore.Cluster) _, _, region1 := mockstore.BootstrapWithSingleStore(c) store := c.AllocID() diff --git a/session/session_test.go b/session/session_test.go index 1b96824bd06b2..67f68f27764ad 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -62,7 +62,7 @@ import ( "github.com/pingcap/tidb/util/testleak" "github.com/pingcap/tidb/util/testutil" "github.com/pingcap/tipb/go-binlog" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" "go.etcd.io/etcd/clientv3" "google.golang.org/grpc" @@ -89,7 +89,7 @@ var _ = SerialSuites(&testTxnStateSerialSuite{}) var _ = SerialSuites(&testStatisticsSuite{}) type testSessionSuiteBase struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage dom *domain.Domain pdAddr string @@ -209,7 +209,7 @@ func (s *testSessionSuiteBase) SetUpSuite(c *C) { s.store = store } else { store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), @@ -2004,7 +2004,7 @@ func (s *testSessionSuite2) TestInformationSchemaCreateTime(c *C) { } type testSchemaSuiteBase struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage dom *domain.Domain } @@ -2029,7 +2029,7 @@ func (s *testSchemaSuiteBase) TearDownTest(c *C) { func (s *testSchemaSuiteBase) SetUpSuite(c *C) { testleak.BeforeTest() store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/store/batch_coprocessor_test.go b/store/batch_coprocessor_test.go index 2ecf86e2b7438..964f07cb8d56d 100644 --- a/store/batch_coprocessor_test.go +++ b/store/batch_coprocessor_test.go @@ -30,7 +30,7 @@ import ( "github.com/pingcap/tidb/store/mockstore/unistore" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/util/testkit" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) type testBatchCopSuite struct { @@ -40,7 +40,7 @@ var _ = SerialSuites(&testBatchCopSuite{}) func newStoreWithBootstrap(tiflashNum int) (kv.Storage, *domain.Domain, error) { store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockCluster := c.(*unistore.Cluster) _, _, region1 := mockstore.BootstrapWithSingleStore(c) tiflashIdx := 0 diff --git a/store/copr/coprocessor_test.go b/store/copr/coprocessor_test.go index dcc821c483240..afd99cdbb4c50 100644 --- a/store/copr/coprocessor_test.go +++ b/store/copr/coprocessor_test.go @@ -20,7 +20,7 @@ import ( . "github.com/pingcap/check" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/driver/backoff" - "github.com/tikv/client-go/v2/mockstore/mocktikv" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" ) @@ -37,9 +37,10 @@ var _ = Suite(&testCoprocessorSuite{}) func (s *testCoprocessorSuite) TestBuildTasks(c *C) { // nil --- 'g' --- 'n' --- 't' --- nil // <- 0 -> <- 1 -> <- 2 -> <- 3 -> - cluster := mocktikv.NewCluster(mocktikv.MustNewMVCCStore()) - _, regionIDs, _ := mocktikv.BootstrapWithMultiRegions(cluster, []byte("g"), []byte("n"), []byte("t")) - pdCli := &tikv.CodecPDClient{Client: mocktikv.NewPDClient(cluster)} + _, cluster, pdClient, err := testutils.NewMockTiKV("", nil) + c.Assert(err, IsNil) + _, regionIDs, _ := testutils.BootstrapWithMultiRegions(cluster, []byte("g"), []byte("n"), []byte("t")) + pdCli := &tikv.CodecPDClient{Client: pdClient} cache := NewRegionCache(tikv.NewRegionCache(pdCli)) defer cache.Close() @@ -154,9 +155,9 @@ func (s *testCoprocessorSuite) TestBuildTasks(c *C) { func (s *testCoprocessorSuite) TestSplitRegionRanges(c *C) { // nil --- 'g' --- 'n' --- 't' --- nil // <- 0 -> <- 1 -> <- 2 -> <- 3 -> - cluster := mocktikv.NewCluster(mocktikv.MustNewMVCCStore()) - mocktikv.BootstrapWithMultiRegions(cluster, []byte("g"), []byte("n"), []byte("t")) - pdCli := &tikv.CodecPDClient{Client: mocktikv.NewPDClient(cluster)} + _, cluster, pdClient, err := testutils.NewMockTiKV("", nil) + testutils.BootstrapWithMultiRegions(cluster, []byte("g"), []byte("n"), []byte("t")) + pdCli := &tikv.CodecPDClient{Client: pdClient} cache := NewRegionCache(tikv.NewRegionCache(pdCli)) defer cache.Close() @@ -207,9 +208,10 @@ func (s *testCoprocessorSuite) TestSplitRegionRanges(c *C) { func (s *testCoprocessorSuite) TestRebuild(c *C) { // nil --- 'm' --- nil // <- 0 -> <- 1 -> - cluster := mocktikv.NewCluster(mocktikv.MustNewMVCCStore()) - storeID, regionIDs, peerIDs := mocktikv.BootstrapWithMultiRegions(cluster, []byte("m")) - pdCli := &tikv.CodecPDClient{Client: mocktikv.NewPDClient(cluster)} + _, cluster, pdClient, err := testutils.NewMockTiKV("", nil) + c.Assert(err, IsNil) + storeID, regionIDs, peerIDs := testutils.BootstrapWithMultiRegions(cluster, []byte("m")) + pdCli := &tikv.CodecPDClient{Client: pdClient} cache := NewRegionCache(tikv.NewRegionCache(pdCli)) defer cache.Close() bo := backoff.NewBackofferWithVars(context.Background(), 3000, nil) diff --git a/store/gcworker/gc_worker_test.go b/store/gcworker/gc_worker_test.go index 5cb17c0a57f37..9eae0ee64107c 100644 --- a/store/gcworker/gc_worker_test.go +++ b/store/gcworker/gc_worker_test.go @@ -38,10 +38,9 @@ import ( "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/store/mockstore" - "github.com/tikv/client-go/v2/mockstore/cluster" - "github.com/tikv/client-go/v2/mockstore/mocktikv" "github.com/tikv/client-go/v2/oracle" "github.com/tikv/client-go/v2/oracle/oracles" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" "github.com/tikv/client-go/v2/tikvrpc" pd "github.com/tikv/pd/client" @@ -55,7 +54,7 @@ func TestT(t *testing.T) { type testGCWorkerSuite struct { store kv.Storage tikvStore tikv.Storage - cluster cluster.Cluster + cluster testutils.Cluster oracle *oracles.MockOracle gcWorker *GCWorker dom *domain.Domain @@ -81,7 +80,7 @@ func (s *testGCWorkerSuite) SetUpTest(c *C) { store, err := mockstore.NewMockStore( mockstore.WithStoreType(mockstore.MockTiKV), - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { s.initRegion.storeIDs, s.initRegion.peerIDs, s.initRegion.regionID, _ = mockstore.BootstrapWithMultiStores(c, 3) s.cluster = c }), @@ -940,7 +939,7 @@ func (s *testGCWorkerSuite) TestResolveLockRangeMeetRegionEnlargeCausedByRegionM if regionID.GetID() == s.initRegion.regionID && *firstAccessRef { *firstAccessRef = false // merge region2 into region1 and return EpochNotMatch error. - mCluster := s.cluster.(*mocktikv.Cluster) + mCluster := s.cluster.(*testutils.MockCluster) mCluster.Merge(s.initRegion.regionID, region2) regionMeta, _ := mCluster.GetRegion(s.initRegion.regionID) _, err := s.tikvStore.GetRegionCache().OnRegionEpochNotMatch( diff --git a/store/helper/helper_test.go b/store/helper/helper_test.go index e4b86cf74dc89..04105edb198bf 100644 --- a/store/helper/helper_test.go +++ b/store/helper/helper_test.go @@ -28,7 +28,7 @@ import ( "github.com/pingcap/tidb/store/helper" "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/util/pdapi" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" "go.uber.org/zap" ) @@ -72,7 +72,7 @@ func (s *HelperTestSuite) SetUpSuite(c *C) { url := s.mockPDHTTPServer(c) time.Sleep(100 * time.Millisecond) mockTikvStore, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithMultiRegions(c, []byte("x")) }), ) diff --git a/store/mockstore/cluster_test.go b/store/mockstore/cluster_test.go index f5ae2ac37633c..be150126b2ea4 100644 --- a/store/mockstore/cluster_test.go +++ b/store/mockstore/cluster_test.go @@ -28,7 +28,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/rowcodec" - "github.com/tikv/client-go/v2/mockstore/mocktikv" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" ) @@ -39,10 +39,11 @@ type testClusterSuite struct { } func (s *testClusterSuite) TestClusterSplit(c *C) { - rpcClient, cluster, pdClient, err := mocktikv.NewTiKVAndPDClient("", nil) + rpcClient, cluster, pdClient, err := testutils.NewMockTiKV("", nil) c.Assert(err, IsNil) - mocktikv.BootstrapWithSingleStore(cluster) + testutils.BootstrapWithSingleStore(cluster) mvccStore := rpcClient.MvccStore + store, err := tikv.NewTestTiKVStore(rpcClient, pdClient, nil, nil, 0) c.Assert(err, IsNil) s.store = store @@ -85,8 +86,8 @@ func (s *testClusterSuite) TestClusterSplit(c *C) { allKeysMap := make(map[string]bool) recordPrefix := tablecodec.GenTableRecordPrefix(tblID) for _, region := range regions { - startKey := mocktikv.MvccKey(region.Meta.StartKey).Raw() - endKey := mocktikv.MvccKey(region.Meta.EndKey).Raw() + startKey := toRawKey(region.Meta.StartKey) + endKey := toRawKey(region.Meta.EndKey) if !bytes.HasPrefix(startKey, recordPrefix) { continue } @@ -107,8 +108,8 @@ func (s *testClusterSuite) TestClusterSplit(c *C) { indexPrefix := tablecodec.EncodeTableIndexPrefix(tblID, idxID) regions = cluster.GetAllRegions() for _, region := range regions { - startKey := mocktikv.MvccKey(region.Meta.StartKey).Raw() - endKey := mocktikv.MvccKey(region.Meta.EndKey).Raw() + startKey := toRawKey(region.Meta.StartKey) + endKey := toRawKey(region.Meta.EndKey) if !bytes.HasPrefix(startKey, indexPrefix) { continue } @@ -122,3 +123,14 @@ func (s *testClusterSuite) TestClusterSplit(c *C) { } c.Assert(allIndexMap, HasLen, 1000) } + +func toRawKey(k []byte) []byte { + if len(k) == 0 { + return nil + } + _, k, err := codec.DecodeBytes(k, nil) + if err != nil { + panic(err) + } + return k +} diff --git a/store/mockstore/mockcopr/cop_handler_dag.go b/store/mockstore/mockcopr/cop_handler_dag.go index f2a697c1653f5..fb7b6ef1b9607 100644 --- a/store/mockstore/mockcopr/cop_handler_dag.go +++ b/store/mockstore/mockcopr/cop_handler_dag.go @@ -41,7 +41,7 @@ import ( "github.com/pingcap/tidb/util/rowcodec" "github.com/pingcap/tidb/util/timeutil" "github.com/pingcap/tipb/go-tipb" - "github.com/tikv/client-go/v2/mockstore/mocktikv" + "github.com/tikv/client-go/v2/testutils" "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) @@ -592,7 +592,7 @@ func (mock *mockCopStreamClient) Recv() (*coprocessor.Response, error) { chunk, finish, ran, counts, warnings, err := mock.readBlockFromExecutor() resp.Range = ran if err != nil { - if locked, ok := errors.Cause(err).(*mocktikv.ErrLocked); ok { + if locked, ok := errors.Cause(err).(*testutils.ErrLocked); ok { resp.Locked = &kvrpcpb.LockInfo{ Key: locked.Key, PrimaryLock: locked.Primary, @@ -784,7 +784,7 @@ func buildResp(selResp *tipb.SelectResponse, execDetails []*execDetail, err erro } // Select errors have been contained in `SelectResponse.Error` - if locked, ok := errors.Cause(err).(*mocktikv.ErrLocked); ok { + if locked, ok := errors.Cause(err).(*testutils.ErrLocked); ok { resp.Locked = &kvrpcpb.LockInfo{ Key: locked.Key, PrimaryLock: locked.Primary, diff --git a/store/mockstore/mockcopr/copr_handler.go b/store/mockstore/mockcopr/copr_handler.go index 75349bfc5eee0..75aede593e89c 100644 --- a/store/mockstore/mockcopr/copr_handler.go +++ b/store/mockstore/mockcopr/copr_handler.go @@ -20,11 +20,11 @@ import ( "github.com/pingcap/kvproto/pkg/coprocessor" "github.com/pingcap/tidb/kv" "github.com/pingcap/tipb/go-tipb" - "github.com/tikv/client-go/v2/mockstore/mocktikv" + "github.com/tikv/client-go/v2/testutils" ) type coprHandler struct { - *mocktikv.Session + *testutils.RPCSession } func (h coprHandler) handleBatchCopRequest(ctx context.Context, req *coprocessor.BatchRequest) (*mockBatchCopDataClient, error) { diff --git a/store/mockstore/mockcopr/executor.go b/store/mockstore/mockcopr/executor.go index 409421db14326..9c9cbfe03c973 100644 --- a/store/mockstore/mockcopr/executor.go +++ b/store/mockstore/mockcopr/executor.go @@ -32,7 +32,7 @@ import ( "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/rowcodec" "github.com/pingcap/tipb/go-tipb" - "github.com/tikv/client-go/v2/mockstore/mocktikv" + "github.com/tikv/client-go/v2/testutils" ) var ( @@ -77,7 +77,7 @@ type tableScanExec struct { startTS uint64 isolationLevel kvrpcpb.IsolationLevel resolvedLocks []uint64 - mvccStore mocktikv.MVCCStore + mvccStore testutils.MVCCStore cursor int seekKey []byte start int @@ -209,8 +209,8 @@ func (e *tableScanExec) getRowFromRange(ran kv.KeyRange) ([][]byte, error) { e.seekKey = ran.StartKey } } - var pairs []mocktikv.Pair - var pair mocktikv.Pair + var pairs []testutils.MVCCPair + var pair testutils.MVCCPair if e.Desc { pairs = e.mvccStore.ReverseScan(ran.StartKey, e.seekKey, 1, e.startTS, e.isolationLevel, e.resolvedLocks) } else { @@ -256,7 +256,7 @@ type indexScanExec struct { startTS uint64 isolationLevel kvrpcpb.IsolationLevel resolvedLocks []uint64 - mvccStore mocktikv.MVCCStore + mvccStore testutils.MVCCStore cursor int seekKey []byte hdStatus tablecodec.HandleStatus @@ -383,8 +383,8 @@ func (e *indexScanExec) getRowFromRange(ran kv.KeyRange) ([][]byte, error) { e.seekKey = ran.StartKey } } - var pairs []mocktikv.Pair - var pair mocktikv.Pair + var pairs []testutils.MVCCPair + var pair testutils.MVCCPair if e.Desc { pairs = e.mvccStore.ReverseScan(ran.StartKey, e.seekKey, 1, e.startTS, e.isolationLevel, e.resolvedLocks) } else { diff --git a/store/mockstore/mockcopr/executor_test.go b/store/mockstore/mockcopr/executor_test.go index e196e9d219305..d3e67961a3202 100644 --- a/store/mockstore/mockcopr/executor_test.go +++ b/store/mockstore/mockcopr/executor_test.go @@ -30,6 +30,7 @@ import ( "github.com/pingcap/tidb/util/testkit" "github.com/tikv/client-go/v2/mockstore/mocktikv" "github.com/tikv/client-go/v2/oracle" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" ) @@ -41,16 +42,16 @@ func TestT(t *testing.T) { var _ = Suite(&testExecutorSuite{}) type testExecutorSuite struct { - cluster *mocktikv.Cluster + cluster *testutils.MockCluster store kv.Storage - mvccStore mocktikv.MVCCStore + mvccStore testutils.MVCCStore dom *domain.Domain } func (s *testExecutorSuite) SetUpSuite(c *C) { - rpcClient, cluster, pdClient, err := mocktikv.NewTiKVAndPDClient("", mockcopr.NewCoprRPCHandler()) + rpcClient, cluster, pdClient, err := testutils.NewMockTiKV("", mockcopr.NewCoprRPCHandler()) c.Assert(err, IsNil) - mocktikv.BootstrapWithSingleStore(cluster) + testutils.BootstrapWithSingleStore(cluster) s.cluster = cluster s.mvccStore = rpcClient.MvccStore store, err := tikv.NewTestTiKVStore(rpcClient, pdClient, nil, nil, 0) @@ -93,8 +94,8 @@ func (s *testExecutorSuite) TestResolvedLargeTxnLocks(c *C) { // Simulate a large txn (holding a pk lock with large TTL). // Secondary lock 200ms, primary lock 100s - c.Assert(mocktikv.MustPrewrite(s.mvccStore, mocktikv.PutMutations("primary", "value"), "primary", tso, 100000), IsTrue) - c.Assert(mocktikv.MustPrewrite(s.mvccStore, mocktikv.PutMutations(string(key), "value"), "primary", tso, 200), IsTrue) + c.Assert(prewriteMVCCStore(s.mvccStore, putMutations("primary", "value"), "primary", tso, 100000), IsTrue) + c.Assert(prewriteMVCCStore(s.mvccStore, putMutations(string(key), "value"), "primary", tso, 200), IsTrue) // Simulate the action of reading meet the lock of a large txn. // The lock of the large transaction should not block read. @@ -131,3 +132,32 @@ func (s *testExecutorSuite) TestIssue15662(c *C) { tk.MustQuery("select table1.`col_int` as field1, table1.`col_int` as field2 from V as table1 left join F as table2 on table1.`col_int` = table2.`col_int` order by field1, field2 desc limit 2"). Check(testkit.Rows("8 8")) } + +func putMutations(kvpairs ...string) []*kvrpcpb.Mutation { + var mutations []*kvrpcpb.Mutation + for i := 0; i < len(kvpairs); i += 2 { + mutations = append(mutations, &kvrpcpb.Mutation{ + Op: kvrpcpb.Op_Put, + Key: []byte(kvpairs[i]), + Value: []byte(kvpairs[i+1]), + }) + } + return mutations +} + +func prewriteMVCCStore(store testutils.MVCCStore, mutations []*kvrpcpb.Mutation, primary string, startTS uint64, ttl uint64) bool { + req := &kvrpcpb.PrewriteRequest{ + Mutations: mutations, + PrimaryLock: []byte(primary), + StartVersion: startTS, + LockTtl: ttl, + MinCommitTs: startTS + 1, + } + errs := store.Prewrite(req) + for _, err := range errs { + if err != nil { + return false + } + } + return true +} diff --git a/store/mockstore/mockcopr/rpc_copr.go b/store/mockstore/mockcopr/rpc_copr.go index daaa01186a2cf..e77d0d5f66963 100644 --- a/store/mockstore/mockcopr/rpc_copr.go +++ b/store/mockstore/mockcopr/rpc_copr.go @@ -22,7 +22,7 @@ import ( "github.com/pingcap/kvproto/pkg/coprocessor" "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/kv" - "github.com/tikv/client-go/v2/mockstore/mocktikv" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikvrpc" ) @@ -32,7 +32,7 @@ type coprRPCHandler struct { } // NewCoprRPCHandler creates a handler to process coprocessor requests. -func NewCoprRPCHandler() mocktikv.CoprRPCHandler { +func NewCoprRPCHandler() testutils.CoprRPCHandler { ch := make(chan *tikvrpc.Lease, 1024) done := make(chan struct{}) go tikvrpc.CheckStreamTimeoutLoop(ch, done) @@ -42,7 +42,7 @@ func NewCoprRPCHandler() mocktikv.CoprRPCHandler { } } -func (mc *coprRPCHandler) HandleCmdCop(reqCtx *kvrpcpb.Context, session *mocktikv.Session, r *coprocessor.Request) *coprocessor.Response { +func (mc *coprRPCHandler) HandleCmdCop(reqCtx *kvrpcpb.Context, session *testutils.RPCSession, r *coprocessor.Request) *coprocessor.Response { if err := session.CheckRequestContext(reqCtx); err != nil { return &coprocessor.Response{RegionError: err} } @@ -60,7 +60,7 @@ func (mc *coprRPCHandler) HandleCmdCop(reqCtx *kvrpcpb.Context, session *mocktik return res } -func (mc *coprRPCHandler) HandleBatchCop(ctx context.Context, reqCtx *kvrpcpb.Context, session *mocktikv.Session, r *coprocessor.BatchRequest, timeout time.Duration) (*tikvrpc.BatchCopStreamResponse, error) { +func (mc *coprRPCHandler) HandleBatchCop(ctx context.Context, reqCtx *kvrpcpb.Context, session *testutils.RPCSession, r *coprocessor.BatchRequest, timeout time.Duration) (*tikvrpc.BatchCopStreamResponse, error) { if err := session.CheckRequestContext(reqCtx); err != nil { return &tikvrpc.BatchCopStreamResponse{ Tikv_BatchCoprocessorClient: &mockBathCopErrClient{Error: err}, @@ -88,7 +88,7 @@ func (mc *coprRPCHandler) HandleBatchCop(ctx context.Context, reqCtx *kvrpcpb.Co return batchResp, nil } -func (mc *coprRPCHandler) HandleCopStream(ctx context.Context, reqCtx *kvrpcpb.Context, session *mocktikv.Session, r *coprocessor.Request, timeout time.Duration) (*tikvrpc.CopStreamResponse, error) { +func (mc *coprRPCHandler) HandleCopStream(ctx context.Context, reqCtx *kvrpcpb.Context, session *testutils.RPCSession, r *coprocessor.Request, timeout time.Duration) (*tikvrpc.CopStreamResponse, error) { if err := session.CheckRequestContext(reqCtx); err != nil { return &tikvrpc.CopStreamResponse{ Tikv_CoprocessorStreamClient: &mockCopStreamErrClient{Error: err}, diff --git a/store/mockstore/mockstore.go b/store/mockstore/mockstore.go index e28b3450c35e8..c371e3dbdb6fb 100644 --- a/store/mockstore/mockstore.go +++ b/store/mockstore/mockstore.go @@ -21,8 +21,7 @@ import ( "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/mockstore/unistore" - "github.com/tikv/client-go/v2/mockstore/cluster" - "github.com/tikv/client-go/v2/mockstore/mocktikv" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" pd "github.com/tikv/pd/client" ) @@ -84,7 +83,7 @@ const ( ) type mockOptions struct { - clusterInspector func(cluster.Cluster) + clusterInspector func(testutils.Cluster) clientHijacker func(tikv.Client) tikv.Client pdClientHijacker func(pd.Client) pd.Client path string @@ -112,7 +111,7 @@ func WithPDClientHijacker(hijacker func(pd.Client) pd.Client) MockTiKVStoreOptio } // WithClusterInspector lets user to inspect the mock cluster handler. -func WithClusterInspector(inspector func(cluster.Cluster)) MockTiKVStoreOption { +func WithClusterInspector(inspector func(testutils.Cluster)) MockTiKVStoreOption { return func(c *mockOptions) { c.clusterInspector = inspector } @@ -143,7 +142,7 @@ func WithTxnLocalLatches(capacity uint) MockTiKVStoreOption { // If path is an empty string, a memory storage will be created. func NewMockStore(options ...MockTiKVStoreOption) (kv.Storage, error) { opt := mockOptions{ - clusterInspector: func(c cluster.Cluster) { + clusterInspector: func(c testutils.Cluster) { BootstrapWithSingleStore(c) }, storeType: defaultStoreType, @@ -163,10 +162,10 @@ func NewMockStore(options ...MockTiKVStoreOption) (kv.Storage, error) { } // BootstrapWithSingleStore initializes a Cluster with 1 Region and 1 Store. -func BootstrapWithSingleStore(cluster cluster.Cluster) (storeID, peerID, regionID uint64) { +func BootstrapWithSingleStore(cluster testutils.Cluster) (storeID, peerID, regionID uint64) { switch x := cluster.(type) { - case *mocktikv.Cluster: - return mocktikv.BootstrapWithSingleStore(x) + case *testutils.MockCluster: + return testutils.BootstrapWithSingleStore(x) case *unistore.Cluster: return unistore.BootstrapWithSingleStore(x) default: @@ -175,10 +174,10 @@ func BootstrapWithSingleStore(cluster cluster.Cluster) (storeID, peerID, regionI } // BootstrapWithMultiStores initializes a Cluster with 1 Region and n Stores. -func BootstrapWithMultiStores(cluster cluster.Cluster, n int) (storeIDs, peerIDs []uint64, regionID uint64, leaderPeer uint64) { +func BootstrapWithMultiStores(cluster testutils.Cluster, n int) (storeIDs, peerIDs []uint64, regionID uint64, leaderPeer uint64) { switch x := cluster.(type) { - case *mocktikv.Cluster: - return mocktikv.BootstrapWithMultiStores(x, n) + case *testutils.MockCluster: + return testutils.BootstrapWithMultiStores(x, n) case *unistore.Cluster: return unistore.BootstrapWithMultiStores(x, n) default: @@ -188,10 +187,10 @@ func BootstrapWithMultiStores(cluster cluster.Cluster, n int) (storeIDs, peerIDs // BootstrapWithMultiRegions initializes a Cluster with multiple Regions and 1 // Store. The number of Regions will be len(splitKeys) + 1. -func BootstrapWithMultiRegions(cluster cluster.Cluster, splitKeys ...[]byte) (storeID uint64, regionIDs, peerIDs []uint64) { +func BootstrapWithMultiRegions(cluster testutils.Cluster, splitKeys ...[]byte) (storeID uint64, regionIDs, peerIDs []uint64) { switch x := cluster.(type) { - case *mocktikv.Cluster: - return mocktikv.BootstrapWithMultiRegions(x, splitKeys...) + case *testutils.MockCluster: + return testutils.BootstrapWithMultiRegions(x, splitKeys...) case *unistore.Cluster: return unistore.BootstrapWithMultiRegions(x, splitKeys...) default: diff --git a/store/mockstore/tikv.go b/store/mockstore/tikv.go index c26826c17905d..e35d1939c19d1 100644 --- a/store/mockstore/tikv.go +++ b/store/mockstore/tikv.go @@ -18,14 +18,14 @@ import ( "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/store/mockstore/mockcopr" "github.com/pingcap/tidb/store/mockstore/mockstorage" - "github.com/tikv/client-go/v2/mockstore/mocktikv" + "github.com/tikv/client-go/v2/testutils" "github.com/tikv/client-go/v2/tikv" ) // newMockTikvStore creates a mocked tikv store, the path is the file path to store the data. // If path is an empty string, a memory storage will be created. func newMockTikvStore(opt *mockOptions) (kv.Storage, error) { - client, cluster, pdClient, err := mocktikv.NewTiKVAndPDClient(opt.path, mockcopr.NewCoprRPCHandler()) + client, cluster, pdClient, err := testutils.NewMockTiKV(opt.path, mockcopr.NewCoprRPCHandler()) if err != nil { return nil, errors.Trace(err) } diff --git a/store/mockstore/unistore/cluster.go b/store/mockstore/unistore/cluster.go index 9a40b73d995f8..c1b2c27144a82 100644 --- a/store/mockstore/unistore/cluster.go +++ b/store/mockstore/unistore/cluster.go @@ -21,7 +21,7 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" us "github.com/pingcap/tidb/store/mockstore/unistore/tikv" "github.com/pingcap/tidb/util/codec" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) type delayKey struct { @@ -29,7 +29,7 @@ type delayKey struct { regionID uint64 } -var _ cluster.Cluster = new(Cluster) +var _ testutils.Cluster = new(Cluster) // Cluster simulates a TiKV cluster. It focuses on management and the change of // meta data. A Cluster mainly includes following 3 kinds of meta data: diff --git a/telemetry/data_feature_usage_test.go b/telemetry/data_feature_usage_test.go index c64201a4bb0b2..af0770e2b3106 100644 --- a/telemetry/data_feature_usage_test.go +++ b/telemetry/data_feature_usage_test.go @@ -23,13 +23,13 @@ import ( "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/telemetry" "github.com/pingcap/tidb/util/testkit" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) var _ = Suite(&testFeatureInfoSuite{}) type testFeatureInfoSuite struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage dom *domain.Domain se session.Session @@ -37,7 +37,7 @@ type testFeatureInfoSuite struct { func (s *testFeatureInfoSuite) SetUpTest(c *C) { store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/types/const_test.go b/types/const_test.go index 6c6e52f9134a4..131df7dd6f464 100644 --- a/types/const_test.go +++ b/types/const_test.go @@ -26,13 +26,13 @@ import ( "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/util/testkit" "github.com/pingcap/tidb/util/testleak" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) var _ = Suite(&testMySQLConstSuite{}) type testMySQLConstSuite struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage dom *domain.Domain *parser.Parser @@ -46,7 +46,7 @@ func (s *testMySQLConstSuite) SetUpSuite(c *C) { useMockTikv := *mockTikv if useMockTikv { store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }), diff --git a/util/admin/admin_integration_test.go b/util/admin/admin_integration_test.go index 5a2a9e4b76216..9e6f16f6216c7 100644 --- a/util/admin/admin_integration_test.go +++ b/util/admin/admin_integration_test.go @@ -23,20 +23,20 @@ import ( "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/util/testkit" - "github.com/tikv/client-go/v2/mockstore/cluster" + "github.com/tikv/client-go/v2/testutils" ) var _ = Suite(&testAdminSuite{}) type testAdminSuite struct { - cluster cluster.Cluster + cluster testutils.Cluster store kv.Storage domain *domain.Domain } func (s *testAdminSuite) SetUpSuite(c *C) { store, err := mockstore.NewMockStore( - mockstore.WithClusterInspector(func(c cluster.Cluster) { + mockstore.WithClusterInspector(func(c testutils.Cluster) { mockstore.BootstrapWithSingleStore(c) s.cluster = c }),