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() {
|
||||
s.store = tikv.StoreProbe{KVStore: NewTestStore(s.T())}
|
||||
s.store = tikv.StoreProbe{KVStore: NewTestUniStore(s.T())}
|
||||
}
|
||||
|
||||
func (s *testAssertionSuite) TearDownTest() {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ type testLockSuite struct {
|
|||
}
|
||||
|
||||
func (s *testLockSuite) SetupTest() {
|
||||
s.store = tikv.StoreProbe{KVStore: NewTestStore(s.T())}
|
||||
s.store = tikv.StoreProbe{KVStore: NewTestUniStore(s.T())}
|
||||
}
|
||||
|
||||
func (s *testLockSuite) TearDownTest() {
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/pingcap/kvproto/pkg/kvrpcpb"
|
||||
"github.com/pingcap/tidb/store/mockstore/unistore"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"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/txnkv/transaction"
|
||||
)
|
||||
|
|
@ -48,9 +48,9 @@ import (
|
|||
func TestSetMinCommitTSInAsyncCommit(t *testing.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)
|
||||
unistore.BootstrapWithSingleStore(cluster)
|
||||
testutils.BootstrapWithSingleStore(cluster)
|
||||
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0)
|
||||
require.Nil(err)
|
||||
defer store.Close()
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ import (
|
|||
|
||||
"github.com/pingcap/failpoint"
|
||||
"github.com/pingcap/kvproto/pkg/kvrpcpb"
|
||||
"github.com/pingcap/tidb/store/mockstore/unistore"
|
||||
"github.com/stretchr/testify/suite"
|
||||
tikverr "github.com/tikv/client-go/v2/error"
|
||||
"github.com/tikv/client-go/v2/oracle"
|
||||
|
|
@ -62,11 +61,7 @@ type testSnapshotFailSuite struct {
|
|||
}
|
||||
|
||||
func (s *testSnapshotFailSuite) SetupSuite() {
|
||||
client, pdClient, cluster, err := unistore.New("")
|
||||
s.Require().Nil(err)
|
||||
unistore.BootstrapWithSingleStore(cluster)
|
||||
store, err := tikv.NewTestTiKVStore(fpClient{Client: client}, pdClient, nil, nil, 0)
|
||||
s.Require().Nil(err)
|
||||
store := NewTestUniStore(s.T())
|
||||
s.store = tikv.StoreProbe{KVStore: store}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import (
|
|||
"github.com/pingcap/tidb/store/mockstore/unistore"
|
||||
"github.com/stretchr/testify/require"
|
||||
"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/txnkv/transaction"
|
||||
"github.com/tikv/client-go/v2/util/codec"
|
||||
|
|
@ -65,19 +66,25 @@ func NewTestStore(t *testing.T) *tikv.KVStore {
|
|||
}
|
||||
|
||||
if *withTiKV {
|
||||
addrs := strings.Split(*pdAddrs, ",")
|
||||
pdClient, err := pd.NewClient(addrs, pd.SecurityOption{})
|
||||
require.Nil(t, err)
|
||||
var securityConfig config.Security
|
||||
tlsConfig, err := securityConfig.ToTLSConfig()
|
||||
require.Nil(t, err)
|
||||
spKV, err := tikv.NewEtcdSafePointKV(addrs, tlsConfig)
|
||||
require.Nil(t, err)
|
||||
store, err := tikv.NewKVStore("test-store", &tikv.CodecPDClient{Client: pdClient}, spKV, tikv.NewRPCClient())
|
||||
require.Nil(t, err)
|
||||
err = clearStorage(store)
|
||||
require.Nil(t, err)
|
||||
return store
|
||||
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)
|
||||
|
|
@ -87,6 +94,22 @@ func NewTestStore(t *testing.T) *tikv.KVStore {
|
|||
return store
|
||||
}
|
||||
|
||||
func newTiKVStore(t *testing.T) *tikv.KVStore {
|
||||
addrs := strings.Split(*pdAddrs, ",")
|
||||
pdClient, err := pd.NewClient(addrs, pd.SecurityOption{})
|
||||
require.Nil(t, err)
|
||||
var securityConfig config.Security
|
||||
tlsConfig, err := securityConfig.ToTLSConfig()
|
||||
require.Nil(t, err)
|
||||
spKV, err := tikv.NewEtcdSafePointKV(addrs, tlsConfig)
|
||||
require.Nil(t, err)
|
||||
store, err := tikv.NewKVStore("test-store", &tikv.CodecPDClient{Client: pdClient}, spKV, tikv.NewRPCClient())
|
||||
require.Nil(t, err)
|
||||
err = clearStorage(store)
|
||||
require.Nil(t, err)
|
||||
return store
|
||||
}
|
||||
|
||||
func clearStorage(store *tikv.KVStore) error {
|
||||
txn, err := store.Begin()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue