Skip to content

Commit

Permalink
tidb/store/tikv: move withtikv to tikv/mockstore package
Browse files Browse the repository at this point in the history
Signed-off-by: shirly <AndreMouche@126.com>
  • Loading branch information
AndreMouche committed Jun 7, 2021
1 parent de20203 commit 40ca049
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 36 deletions.
9 changes: 5 additions & 4 deletions session/pessimistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import (
"github.com/pingcap/tidb/sessionctx/variable"
storeerr "github.com/pingcap/tidb/store/driver/error"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/store/tikv/mockstore"
"github.com/pingcap/tidb/store/tikv/oracle"
tikvutil "github.com/pingcap/tidb/store/tikv/util"

"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/codec"
Expand Down Expand Up @@ -232,7 +233,7 @@ func (s *testPessimisticSuite) TestDeadlock(c *C) {
}

func (s *testPessimisticSuite) TestSingleStatementRollback(c *C) {
if *tikvutil.WithTiKV {
if *mockstore.WithTiKV {
c.Skip("skip with tikv because cluster manipulate is not available")
}
tk := testkit.NewTestKitWithInit(c, s.store)
Expand Down Expand Up @@ -2078,7 +2079,7 @@ func (s *testPessimisticSuite) TestSelectForUpdateConflictRetry(c *C) {

func (s *testPessimisticSuite) TestAsyncCommitWithSchemaChange(c *C) {
// TODO: implement commit_ts calculation in unistore
if !*tikvutil.WithTiKV {
if !*mockstore.WithTiKV {
return
}

Expand Down Expand Up @@ -2152,7 +2153,7 @@ func (s *testPessimisticSuite) TestAsyncCommitWithSchemaChange(c *C) {

func (s *testPessimisticSuite) Test1PCWithSchemaChange(c *C) {
// TODO: implement commit_ts calculation in unistore
if !*tikvutil.WithTiKV {
if !*mockstore.WithTiKV {
return
}

Expand Down
9 changes: 5 additions & 4 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/mockstore/mockcopr"
"github.com/pingcap/tidb/store/tikv"
tikvmockstore "github.com/pingcap/tidb/store/tikv/mockstore"
"github.com/pingcap/tidb/store/tikv/mockstore/cluster"
tikvutil "github.com/pingcap/tidb/store/tikv/util"
"github.com/pingcap/tidb/table/tables"
Expand Down Expand Up @@ -182,7 +183,7 @@ func initPdAddrs() {
func (s *testSessionSuiteBase) SetUpSuite(c *C) {
testleak.BeforeTest()

if *tikvutil.WithTiKV {
if *tikvmockstore.WithTiKV {
initPdAddrs()
s.pdAddr = <-pdAddrChan
var d driver.TiKVDriver
Expand Down Expand Up @@ -218,7 +219,7 @@ func (s *testSessionSuiteBase) TearDownSuite(c *C) {
s.dom.Close()
s.store.Close()
testleak.AfterTest(c)()
if *tikvutil.WithTiKV {
if *tikvmockstore.WithTiKV {
pdAddrChan <- s.pdAddr
}
}
Expand Down Expand Up @@ -3369,7 +3370,7 @@ func (s *testSessionSerialSuite) TestSetTxnScope(c *C) {
func (s *testSessionSerialSuite) TestGlobalAndLocalTxn(c *C) {
// Because the PD config of check_dev_2 test is not compatible with local/global txn yet,
// so we will skip this test for now.
if *tikvutil.WithTiKV {
if *tikvmockstore.WithTiKV {
return
}
tk := testkit.NewTestKitWithInit(c, s.store)
Expand Down Expand Up @@ -3765,7 +3766,7 @@ func (s *testSessionSerialSuite) TestDoDDLJobQuit(c *C) {

func (s *testBackupRestoreSuite) TestBackupAndRestore(c *C) {
// only run BR SQL integration test with tikv store.
if *tikvutil.WithTiKV {
if *tikvmockstore.WithTiKV {
cfg := config.GetGlobalConfig()
cfg.Store = "tikv"
cfg.Path = s.pdAddr
Expand Down
4 changes: 2 additions & 2 deletions store/driver/sql_fail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/store/tikv/util"
"github.com/pingcap/tidb/store/tikv/mockstore"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testkit"
)
Expand All @@ -55,7 +55,7 @@ func (s *testSQLSuiteBase) SetUpSuite(c *C) {
var err error
s.store = NewTestStore(c)
// actual this is better done in `OneByOneSuite.SetUpSuite`, but this would cause circle dependency
if *util.WithTiKV {
if *mockstore.WithTiKV {
session.ResetStoreForWithTiKVTest(s.store)
}

Expand Down
6 changes: 3 additions & 3 deletions store/driver/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/pingcap/tidb/store/copr"
"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/store/tikv/util"
"github.com/pingcap/tidb/store/tikv/mockstore"
)

func TestT(t *testing.T) {
Expand All @@ -43,7 +43,7 @@ func NewTestStore(c *C) kv.Storage {
flag.Parse()
}

if *util.WithTiKV {
if *mockstore.WithTiKV {
var d TiKVDriver
store, err := d.Open(fmt.Sprintf("tikv://%s", *pdAddrs))
c.Assert(err, IsNil)
Expand Down Expand Up @@ -80,4 +80,4 @@ func clearStorage(store kv.Storage) error {
}

// OneByOneSuite is a suite, When with-tikv flag is true, there is only one storage, so the test suite have to run one by one.
type OneByOneSuite = util.OneByOneSuite
type OneByOneSuite = mockstore.OneByOneSuite
4 changes: 2 additions & 2 deletions store/tikv/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/tikvpb"
"github.com/pingcap/tidb/store/tikv/config"
"github.com/pingcap/tidb/store/tikv/mockstore"
"github.com/pingcap/tidb/store/tikv/tikvrpc"
"github.com/pingcap/tidb/store/tikv/util"
"google.golang.org/grpc/metadata"
)

// OneByOneSuite is a suite, When with-tikv flag is true, there is only one storage, so the test suite have to run one by one.
type OneByOneSuite = util.OneByOneSuite
type OneByOneSuite = mockstore.OneByOneSuite

func TestT(t *testing.T) {
CustomVerboseFlag = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package util
package mockstore

import (
"flag"
Expand Down
5 changes: 3 additions & 2 deletions store/tikv/tests/1pc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/store/tikv/metrics"
"github.com/pingcap/tidb/store/tikv/mockstore"
"github.com/pingcap/tidb/store/tikv/oracle"
"github.com/pingcap/tidb/store/tikv/util"
)
Expand Down Expand Up @@ -179,7 +180,7 @@ func (s *testOnePCSuite) Test1PCIsolation(c *C) {

func (s *testOnePCSuite) Test1PCDisallowMultiRegion(c *C) {
// This test doesn't support tikv mode.
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}

Expand Down Expand Up @@ -247,7 +248,7 @@ func (s *testOnePCSuite) Test1PCLinearizability(c *C) {

func (s *testOnePCSuite) Test1PCWithMultiDC(c *C) {
// It requires setting placement rules to run with TiKV
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}

Expand Down
11 changes: 6 additions & 5 deletions store/tikv/tests/async_commit_fail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/store/tikv"
tikverr "github.com/pingcap/tidb/store/tikv/error"
"github.com/pingcap/tidb/store/tikv/mockstore"
"github.com/pingcap/tidb/store/tikv/util"
)

Expand All @@ -43,7 +44,7 @@ func (s *testAsyncCommitFailSuite) SetUpTest(c *C) {
// committing primary region task.
func (s *testAsyncCommitFailSuite) TestFailAsyncCommitPrewriteRpcErrors(c *C) {
// This test doesn't support tikv mode because it needs setting failpoint in unistore.
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}

Expand Down Expand Up @@ -75,7 +76,7 @@ func (s *testAsyncCommitFailSuite) TestFailAsyncCommitPrewriteRpcErrors(c *C) {

func (s *testAsyncCommitFailSuite) TestAsyncCommitPrewriteCancelled(c *C) {
// This test doesn't support tikv mode because it needs setting failpoint in unistore.
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}

Expand Down Expand Up @@ -135,7 +136,7 @@ func (s *testAsyncCommitFailSuite) TestPointGetWithAsyncCommit(c *C) {

func (s *testAsyncCommitFailSuite) TestSecondaryListInPrimaryLock(c *C) {
// This test doesn't support tikv mode.
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}

Expand Down Expand Up @@ -237,7 +238,7 @@ func (s *testAsyncCommitFailSuite) TestAsyncCommitContextCancelCausingUndetermin
// TestAsyncCommitRPCErrorThenWriteConflict verifies that the determined failure error overwrites undetermined error.
func (s *testAsyncCommitFailSuite) TestAsyncCommitRPCErrorThenWriteConflict(c *C) {
// This test doesn't support tikv mode because it needs setting failpoint in unistore.
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}

Expand All @@ -260,7 +261,7 @@ func (s *testAsyncCommitFailSuite) TestAsyncCommitRPCErrorThenWriteConflict(c *C
// overwrites the undetermined error in the parent.
func (s *testAsyncCommitFailSuite) TestAsyncCommitRPCErrorThenWriteConflictInChild(c *C) {
// This test doesn't support tikv mode because it needs setting failpoint in unistore.
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}

Expand Down
7 changes: 4 additions & 3 deletions store/tikv/tests/async_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/pingcap/tidb/store/tikv"
tikverr "github.com/pingcap/tidb/store/tikv/error"
"github.com/pingcap/tidb/store/tikv/mockstore"
"github.com/pingcap/tidb/store/tikv/mockstore/cluster"
"github.com/pingcap/tidb/store/tikv/oracle"
"github.com/pingcap/tidb/store/tikv/tikvrpc"
Expand All @@ -47,7 +48,7 @@ type testAsyncCommitCommon struct {
}

func (s *testAsyncCommitCommon) setUpTest(c *C) {
if *util.WithTiKV {
if *mockstore.WithTiKV {
s.store = NewTestStore(c)
return
}
Expand Down Expand Up @@ -195,7 +196,7 @@ func (s *testAsyncCommitSuite) lockKeysWithAsyncCommit(c *C, keys, values [][]by

func (s *testAsyncCommitSuite) TestCheckSecondaries(c *C) {
// This test doesn't support tikv mode.
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}

Expand Down Expand Up @@ -402,7 +403,7 @@ func (s *testAsyncCommitSuite) TestAsyncCommitLinearizability(c *C) {
// TestAsyncCommitWithMultiDC tests that async commit can only be enabled in global transactions
func (s *testAsyncCommitSuite) TestAsyncCommitWithMultiDC(c *C) {
// It requires setting placement rules to run with TiKV
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}

Expand Down
6 changes: 3 additions & 3 deletions store/tikv/tests/snapshot_fail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/pingcap/tidb/store/tikv"
tikverr "github.com/pingcap/tidb/store/tikv/error"
"github.com/pingcap/tidb/store/tikv/util"
"github.com/pingcap/tidb/store/tikv/mockstore"
)

type testSnapshotFailSuite struct {
Expand Down Expand Up @@ -63,7 +63,7 @@ func (s *testSnapshotFailSuite) cleanup(c *C) {

func (s *testSnapshotFailSuite) TestBatchGetResponseKeyError(c *C) {
// Meaningless to test with tikv because it has a mock key error
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}
defer s.cleanup(c)
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s *testSnapshotFailSuite) TestBatchGetResponseKeyError(c *C) {

func (s *testSnapshotFailSuite) TestScanResponseKeyError(c *C) {
// Meaningless to test with tikv because it has a mock key error
if *util.WithTiKV {
if *mockstore.WithTiKV {
return
}
defer s.cleanup(c)
Expand Down
4 changes: 2 additions & 2 deletions store/tikv/tests/ticlient_slow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/store/tikv/kv"
"github.com/pingcap/tidb/store/tikv/util"
"github.com/pingcap/tidb/store/tikv/mockstore"
)

func (s *testTiclientSuite) TestSplitRegionIn2PC(c *C) {
if *util.WithTiKV {
if *mockstore.WithTiKV {
c.Skip("scatter will timeout with single node TiKV")
}
config := tikv.ConfigProbe{}
Expand Down
6 changes: 3 additions & 3 deletions store/tikv/tests/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/pingcap/tidb/store/mockstore/unistore"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/store/tikv/config"
"github.com/pingcap/tidb/store/tikv/util"
"github.com/pingcap/tidb/store/tikv/mockstore"
"github.com/pingcap/tidb/store/tikv/util/codec"
pd "github.com/tikv/pd/client"
)
Expand All @@ -42,7 +42,7 @@ func NewTestStore(c *C) *tikv.KVStore {
flag.Parse()
}

if *util.WithTiKV {
if *mockstore.WithTiKV {
addrs := strings.Split(*pdAddrs, ",")
pdClient, err := pd.NewClient(addrs, pd.SecurityOption{})
c.Assert(err, IsNil)
Expand Down Expand Up @@ -84,7 +84,7 @@ func clearStorage(store *tikv.KVStore) error {
}

// OneByOneSuite is a suite, When with-tikv flag is true, there is only one storage, so the test suite have to run one by one.
type OneByOneSuite = util.OneByOneSuite
type OneByOneSuite = mockstore.OneByOneSuite

func encodeKey(prefix, s string) []byte {
return codec.EncodeBytes(nil, []byte(fmt.Sprintf("%s_%s", prefix, s)))
Expand Down
4 changes: 2 additions & 2 deletions store/tikv/tikv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"testing"

. "github.com/pingcap/check"
"github.com/pingcap/tidb/store/tikv/util"
"github.com/pingcap/tidb/store/tikv/mockstore"
"github.com/pingcap/tidb/util/logutil"
)

type OneByOneSuite = util.OneByOneSuite
type OneByOneSuite = mockstore.OneByOneSuite
type testTiKVSuite struct {
OneByOneSuite
}
Expand Down

0 comments on commit 40ca049

Please sign in to comment.