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,19 +66,25 @@ func NewTestStore(t *testing.T) *tikv.KVStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
if *withTiKV {
|
if *withTiKV {
|
||||||
addrs := strings.Split(*pdAddrs, ",")
|
return newTiKVStore(t)
|
||||||
pdClient, err := pd.NewClient(addrs, pd.SecurityOption{})
|
}
|
||||||
require.Nil(t, err)
|
client, cluster, pdClient, err := testutils.NewMockTiKV("", nil)
|
||||||
var securityConfig config.Security
|
require.NoError(t, err)
|
||||||
tlsConfig, err := securityConfig.ToTLSConfig()
|
testutils.BootstrapWithSingleStore(cluster)
|
||||||
require.Nil(t, err)
|
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0)
|
||||||
spKV, err := tikv.NewEtcdSafePointKV(addrs, tlsConfig)
|
require.Nil(t, err)
|
||||||
require.Nil(t, err)
|
return store
|
||||||
store, err := tikv.NewKVStore("test-store", &tikv.CodecPDClient{Client: pdClient}, spKV, tikv.NewRPCClient())
|
}
|
||||||
require.Nil(t, err)
|
|
||||||
err = clearStorage(store)
|
// NewTestUniStore creates a KVStore (using tidb/unistore) for testing purpose.
|
||||||
require.Nil(t, err)
|
// TODO: switch to use mockstore and remove it.
|
||||||
return store
|
func NewTestUniStore(t *testing.T) *tikv.KVStore {
|
||||||
|
if !flag.Parsed() {
|
||||||
|
flag.Parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
if *withTiKV {
|
||||||
|
return newTiKVStore(t)
|
||||||
}
|
}
|
||||||
client, pdClient, cluster, err := unistore.New("")
|
client, pdClient, cluster, err := unistore.New("")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
@ -87,6 +94,22 @@ func NewTestStore(t *testing.T) *tikv.KVStore {
|
||||||
return store
|
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 {
|
func clearStorage(store *tikv.KVStore) error {
|
||||||
txn, err := store.Begin()
|
txn, err := store.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue