mirror of https://github.com/tikv/client-go.git
integration: replace some unistore with mockstore (#432)
Signed-off-by: disksing <i@disksing.com>
This commit is contained in:
parent
cb9955362c
commit
0214a9efa0
|
|
@ -43,7 +43,7 @@ type testAssertionSuite struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testAssertionSuite) SetupTest() {
|
func (s *testAssertionSuite) SetupTest() {
|
||||||
s.store = tikv.StoreProbe{KVStore: NewTestStore(s.T())}
|
s.store = tikv.StoreProbe{KVStore: NewTestUniStore(s.T())}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testAssertionSuite) TearDownTest() {
|
func (s *testAssertionSuite) TearDownTest() {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ type testLockSuite struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testLockSuite) SetupTest() {
|
func (s *testLockSuite) SetupTest() {
|
||||||
s.store = tikv.StoreProbe{KVStore: NewTestStore(s.T())}
|
s.store = tikv.StoreProbe{KVStore: NewTestUniStore(s.T())}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testLockSuite) TearDownTest() {
|
func (s *testLockSuite) TearDownTest() {
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/pingcap/kvproto/pkg/kvrpcpb"
|
"github.com/pingcap/kvproto/pkg/kvrpcpb"
|
||||||
"github.com/pingcap/tidb/store/mockstore/unistore"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/tikv/client-go/v2/testutils"
|
||||||
"github.com/tikv/client-go/v2/tikv"
|
"github.com/tikv/client-go/v2/tikv"
|
||||||
"github.com/tikv/client-go/v2/txnkv/transaction"
|
"github.com/tikv/client-go/v2/txnkv/transaction"
|
||||||
)
|
)
|
||||||
|
|
@ -48,9 +48,9 @@ import (
|
||||||
func TestSetMinCommitTSInAsyncCommit(t *testing.T) {
|
func TestSetMinCommitTSInAsyncCommit(t *testing.T) {
|
||||||
require, assert := require.New(t), assert.New(t)
|
require, assert := require.New(t), assert.New(t)
|
||||||
|
|
||||||
client, pdClient, cluster, err := unistore.New("")
|
client, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
|
||||||
require.Nil(err)
|
require.Nil(err)
|
||||||
unistore.BootstrapWithSingleStore(cluster)
|
testutils.BootstrapWithSingleStore(cluster)
|
||||||
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0)
|
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0)
|
||||||
require.Nil(err)
|
require.Nil(err)
|
||||||
defer store.Close()
|
defer store.Close()
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ import (
|
||||||
|
|
||||||
"github.com/pingcap/failpoint"
|
"github.com/pingcap/failpoint"
|
||||||
"github.com/pingcap/kvproto/pkg/kvrpcpb"
|
"github.com/pingcap/kvproto/pkg/kvrpcpb"
|
||||||
"github.com/pingcap/tidb/store/mockstore/unistore"
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
tikverr "github.com/tikv/client-go/v2/error"
|
tikverr "github.com/tikv/client-go/v2/error"
|
||||||
"github.com/tikv/client-go/v2/oracle"
|
"github.com/tikv/client-go/v2/oracle"
|
||||||
|
|
@ -62,11 +61,7 @@ type testSnapshotFailSuite struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *testSnapshotFailSuite) SetupSuite() {
|
func (s *testSnapshotFailSuite) SetupSuite() {
|
||||||
client, pdClient, cluster, err := unistore.New("")
|
store := NewTestUniStore(s.T())
|
||||||
s.Require().Nil(err)
|
|
||||||
unistore.BootstrapWithSingleStore(cluster)
|
|
||||||
store, err := tikv.NewTestTiKVStore(fpClient{Client: client}, pdClient, nil, nil, 0)
|
|
||||||
s.Require().Nil(err)
|
|
||||||
s.store = tikv.StoreProbe{KVStore: store}
|
s.store = tikv.StoreProbe{KVStore: store}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ import (
|
||||||
"github.com/pingcap/tidb/store/mockstore/unistore"
|
"github.com/pingcap/tidb/store/mockstore/unistore"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/tikv/client-go/v2/config"
|
"github.com/tikv/client-go/v2/config"
|
||||||
|
"github.com/tikv/client-go/v2/testutils"
|
||||||
"github.com/tikv/client-go/v2/tikv"
|
"github.com/tikv/client-go/v2/tikv"
|
||||||
"github.com/tikv/client-go/v2/txnkv/transaction"
|
"github.com/tikv/client-go/v2/txnkv/transaction"
|
||||||
"github.com/tikv/client-go/v2/util/codec"
|
"github.com/tikv/client-go/v2/util/codec"
|
||||||
|
|
@ -65,6 +66,35 @@ func NewTestStore(t *testing.T) *tikv.KVStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
if *withTiKV {
|
if *withTiKV {
|
||||||
|
return newTiKVStore(t)
|
||||||
|
}
|
||||||
|
client, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
testutils.BootstrapWithSingleStore(cluster)
|
||||||
|
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0)
|
||||||
|
require.Nil(t, err)
|
||||||
|
return store
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTestUniStore creates a KVStore (using tidb/unistore) for testing purpose.
|
||||||
|
// TODO: switch to use mockstore and remove it.
|
||||||
|
func NewTestUniStore(t *testing.T) *tikv.KVStore {
|
||||||
|
if !flag.Parsed() {
|
||||||
|
flag.Parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
if *withTiKV {
|
||||||
|
return newTiKVStore(t)
|
||||||
|
}
|
||||||
|
client, pdClient, cluster, err := unistore.New("")
|
||||||
|
require.Nil(t, err)
|
||||||
|
unistore.BootstrapWithSingleStore(cluster)
|
||||||
|
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0)
|
||||||
|
require.Nil(t, err)
|
||||||
|
return store
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTiKVStore(t *testing.T) *tikv.KVStore {
|
||||||
addrs := strings.Split(*pdAddrs, ",")
|
addrs := strings.Split(*pdAddrs, ",")
|
||||||
pdClient, err := pd.NewClient(addrs, pd.SecurityOption{})
|
pdClient, err := pd.NewClient(addrs, pd.SecurityOption{})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
@ -78,13 +108,6 @@ func NewTestStore(t *testing.T) *tikv.KVStore {
|
||||||
err = clearStorage(store)
|
err = clearStorage(store)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
return store
|
return store
|
||||||
}
|
|
||||||
client, pdClient, cluster, err := unistore.New("")
|
|
||||||
require.Nil(t, err)
|
|
||||||
unistore.BootstrapWithSingleStore(cluster)
|
|
||||||
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0)
|
|
||||||
require.Nil(t, err)
|
|
||||||
return store
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func clearStorage(store *tikv.KVStore) error {
|
func clearStorage(store *tikv.KVStore) error {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue