testkit

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2023 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WithTiKV = flag.String("with-tikv", "", "address of tikv cluster, if set, running test with real tikv cluster")

WithTiKV flag is only used for debugging locally with real tikv cluster.

Functions

func CreateMockStore

func CreateMockStore(t testing.TB, opts ...mockstore.MockTiKVStoreOption) kv.Storage

CreateMockStore return a new mock kv.Storage.

func CreateMockStoreAndDomain

func CreateMockStoreAndDomain(t testing.TB, opts ...mockstore.MockTiKVStoreOption) (kv.Storage, *domain.Domain)

CreateMockStoreAndDomain return a new mock kv.Storage and *domain.Domain.

func CreateMockStoreAndDomainWithSchemaLease

func CreateMockStoreAndDomainWithSchemaLease(t testing.TB, lease time.Duration, opts ...mockstore.MockTiKVStoreOption) (kv.Storage, *domain.Domain)

CreateMockStoreAndDomainWithSchemaLease return a new mock kv.Storage and *domain.Domain.

func CreateMockStoreWithSchemaLease

func CreateMockStoreWithSchemaLease(t testing.TB, lease time.Duration, opts ...mockstore.MockTiKVStoreOption) kv.Storage

CreateMockStoreWithSchemaLease return a new mock kv.Storage.

func GetStack

func GetStack() []byte

GetStack gets the stacktrace.

func Rows

func Rows(args ...string) [][]interface{}

Rows is similar to RowsWithSep, use white space as separator string.

func RowsWithSep

func RowsWithSep(sep string, args ...string) [][]interface{}

RowsWithSep is a convenient function to wrap args to a slice of []interface. The arg represents a row, split by sep.

func TryRetrieveSession

func TryRetrieveSession(ctx context.Context) session.Session

TryRetrieveSession tries retrieve session from context.

func WithPruneMode

func WithPruneMode(tk *TestKit, mode variable.PartitionPruneMode, f func())

WithPruneMode run test case under prune mode.

Types

type AsyncTestKit

type AsyncTestKit struct {
	// contains filtered or unexported fields
}

AsyncTestKit is a utility to run sql concurrently.

func NewAsyncTestKit

func NewAsyncTestKit(t *testing.T, store kv.Storage) *AsyncTestKit

NewAsyncTestKit returns a new *AsyncTestKit.

func (*AsyncTestKit) CloseSession

func (tk *AsyncTestKit) CloseSession(ctx context.Context)

CloseSession closes exists session from ctx.

func (*AsyncTestKit) ConcurrentRun

func (tk *AsyncTestKit) ConcurrentRun(
	concurrent int,
	loops int,
	prepareFunc func(ctx context.Context, tk *AsyncTestKit, concurrent int, currentLoop int) [][][]interface{},
	writeFunc func(ctx context.Context, tk *AsyncTestKit, input [][]interface{}),
	checkFunc func(ctx context.Context, tk *AsyncTestKit),
)

ConcurrentRun run test in current. - concurrent: controls the concurrent worker count. - loops: controls run test how much times. - prepareFunc: provide test data and will be called for every loop. - checkFunc: used to do some check after all workers done. works like create table better be put in front of this method calling. see more example at TestBatchInsertWithOnDuplicate

func (*AsyncTestKit) Exec

func (tk *AsyncTestKit) Exec(ctx context.Context, sql string, args ...interface{}) (sqlexec.RecordSet, error)

Exec executes a sql statement.

func (*AsyncTestKit) MustExec

func (tk *AsyncTestKit) MustExec(ctx context.Context, sql string, args ...interface{})

MustExec executes a sql statement and asserts nil error.

func (*AsyncTestKit) MustQuery

func (tk *AsyncTestKit) MustQuery(ctx context.Context, sql string, args ...interface{}) *Result

MustQuery query the statements and returns result rows. If expected result is set it asserts the query result equals expected result.

func (*AsyncTestKit) OpenSession

func (tk *AsyncTestKit) OpenSession(ctx context.Context, db string) context.Context

OpenSession opens new session ctx if no exists one and use db.

type DBTestKit

type DBTestKit struct {
	// contains filtered or unexported fields
}

DBTestKit is a utility to run sql with a db connection.

func NewDBTestKit

func NewDBTestKit(t *testing.T, db *sql.DB) *DBTestKit

NewDBTestKit returns a new *DBTestKit.

func (*DBTestKit) GetDB

func (tk *DBTestKit) GetDB() *sql.DB

GetDB returns the underlay sql.DB instance.

func (*DBTestKit) MustExec

func (tk *DBTestKit) MustExec(sql string, args ...interface{}) sql.Result

MustExec query the statements and returns the result.

func (*DBTestKit) MustExecPrepared

func (tk *DBTestKit) MustExecPrepared(stmt *sql.Stmt, args ...interface{}) sql.Result

MustExecPrepared executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.

func (*DBTestKit) MustPrepare

func (tk *DBTestKit) MustPrepare(query string) *sql.Stmt

MustPrepare creates a prepared statement for later queries or executions.

func (*DBTestKit) MustQuery

func (tk *DBTestKit) MustQuery(sql string, args ...interface{}) *sql.Rows

MustQuery query the statements and returns result rows.

func (*DBTestKit) MustQueryPrepared

func (tk *DBTestKit) MustQueryPrepared(stmt *sql.Stmt, args ...interface{}) *sql.Rows

MustQueryPrepared executes a prepared query statement with the given arguments and returns the query results as a *Rows.

func (*DBTestKit) MustQueryRows

func (tk *DBTestKit) MustQueryRows(query string, args ...interface{})

MustQueryRows query the statements

type MockSessionManager

type MockSessionManager struct {
	PS      []*util.ProcessInfo
	PSMu    sync.RWMutex
	SerID   uint64
	TxnInfo []*txninfo.TxnInfo
	Dom     *domain.Domain
	Conn    map[uint64]session.Session
	// contains filtered or unexported fields
}

MockSessionManager is a mocked session manager which is used for test.

func (*MockSessionManager) CheckOldRunningTxn

func (msm *MockSessionManager) CheckOldRunningTxn(job2ver map[int64]int64, job2ids map[int64]string)

CheckOldRunningTxn is to get all startTS of every transactions running in the current internal sessions

func (*MockSessionManager) DeleteInternalSession

func (*MockSessionManager) DeleteInternalSession(interface{})

DeleteInternalSession is to delete the internal session pointer from the map in the SessionManager

func (*MockSessionManager) GetInternalSessionStartTSList

func (*MockSessionManager) GetInternalSessionStartTSList() []uint64

GetInternalSessionStartTSList is to get all startTS of every transactions running in the current internal sessions

func (*MockSessionManager) GetProcessInfo

func (msm *MockSessionManager) GetProcessInfo(id uint64) (*util.ProcessInfo, bool)

GetProcessInfo implements the SessionManager.GetProcessInfo interface.

func (*MockSessionManager) Kill

func (*MockSessionManager) Kill(uint64, bool)

Kill implements the SessionManager.Kill interface.

func (*MockSessionManager) KillAllConnections

func (*MockSessionManager) KillAllConnections()

KillAllConnections implements the SessionManager.KillAllConections interface.

func (*MockSessionManager) KillNonFlashbackClusterConn

func (msm *MockSessionManager) KillNonFlashbackClusterConn()

KillNonFlashbackClusterConn implement SessionManager interface.

func (*MockSessionManager) ServerID

func (msm *MockSessionManager) ServerID() uint64

ServerID get server id.

func (*MockSessionManager) ShowProcessList

func (msm *MockSessionManager) ShowProcessList() map[uint64]*util.ProcessInfo

ShowProcessList implements the SessionManager.ShowProcessList interface.

func (*MockSessionManager) ShowTxnList

func (msm *MockSessionManager) ShowTxnList() []*txninfo.TxnInfo

ShowTxnList is to show txn list.

func (*MockSessionManager) StoreInternalSession

func (*MockSessionManager) StoreInternalSession(interface{})

StoreInternalSession is to store internal session.

func (*MockSessionManager) UpdateTLSConfig

func (*MockSessionManager) UpdateTLSConfig(*tls.Config)

UpdateTLSConfig implements the SessionManager.UpdateTLSConfig interface.

type RegionProperityClient

type RegionProperityClient struct {
	tikv.Client
	// contains filtered or unexported fields
}

RegionProperityClient is to get region properties.

func (*RegionProperityClient) SendRequest

func (c *RegionProperityClient) SendRequest(ctx context.Context, addr string, req *tikvrpc.Request, timeout time.Duration) (*tikvrpc.Response, error)

SendRequest is to mock send request.

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result is the result returned by MustQuery.

func (*Result) AddComment

func (res *Result) AddComment(c string)

AddComment adds the extra comment for the Result's output.

func (*Result) Check

func (res *Result) Check(expected [][]interface{})

Check asserts the result equals the expected results.

func (*Result) CheckAt

func (res *Result) CheckAt(cols []int, expected [][]interface{})

CheckAt asserts the result of selected columns equals the expected results.

func (*Result) CheckContain

func (res *Result) CheckContain(expected string)

CheckContain checks whether the result contains the expected string

func (*Result) CheckWithFunc

func (res *Result) CheckWithFunc(expected [][]interface{}, f func([]string, []interface{}) bool)

CheckWithFunc asserts the result match the expected results in the way `f` specifies.

func (*Result) Rows

func (res *Result) Rows() [][]interface{}

Rows returns the result data.

func (*Result) Sort

func (res *Result) Sort() *Result

Sort sorts and return the result.

type SteppedTestKit

type SteppedTestKit struct {
	// contains filtered or unexported fields
}

SteppedTestKit is the testkit that can run stepped command

func NewSteppedTestKit

func NewSteppedTestKit(t testing.TB, store kv.Storage) *SteppedTestKit

NewSteppedTestKit creates a new SteppedTestKit

func (*SteppedTestKit) Continue

func (tk *SteppedTestKit) Continue() *SteppedTestKit

Continue continues current command

func (*SteppedTestKit) ExpectIdle

func (tk *SteppedTestKit) ExpectIdle()

ExpectIdle checks no command is running

func (*SteppedTestKit) ExpectStopOnAnyBreakPoint

func (tk *SteppedTestKit) ExpectStopOnAnyBreakPoint()

ExpectStopOnAnyBreakPoint checks stopped on any break point

func (*SteppedTestKit) ExpectStopOnBreakPoint

func (tk *SteppedTestKit) ExpectStopOnBreakPoint(breakPoint string)

ExpectStopOnBreakPoint checks stopped on the specified break point

func (*SteppedTestKit) GetQueryResult

func (tk *SteppedTestKit) GetQueryResult() *Result

GetQueryResult returns the query result of the latest command

func (*SteppedTestKit) GetResult

func (tk *SteppedTestKit) GetResult() any

GetResult returns the result of the latest command

func (*SteppedTestKit) MustExec

func (tk *SteppedTestKit) MustExec(sql string, args ...interface{})

MustExec executes a sql statement and asserts nil error.

func (*SteppedTestKit) MustQuery

func (tk *SteppedTestKit) MustQuery(sql string, args ...interface{}) *Result

MustQuery query the statements and returns result rows. If expected result is set it asserts the query result equals expected result.

func (*SteppedTestKit) SetBreakPoints

func (tk *SteppedTestKit) SetBreakPoints(breakPoints ...string)

SetBreakPoints sets the break points we want to stop at

func (*SteppedTestKit) SteppedMustExec

func (tk *SteppedTestKit) SteppedMustExec(sql string, args ...interface{}) *SteppedTestKit

SteppedMustExec creates a new stepped task for MustExec

func (*SteppedTestKit) SteppedMustQuery

func (tk *SteppedTestKit) SteppedMustQuery(sql string, args ...interface{}) *SteppedTestKit

SteppedMustQuery creates a new stepped task for MustQuery

type TestKit

type TestKit struct {
	// contains filtered or unexported fields
}

TestKit is a utility to run sql test.

func NewTestKit

func NewTestKit(t testing.TB, store kv.Storage) *TestKit

NewTestKit returns a new *TestKit.

func NewTestKitWithSession

func NewTestKitWithSession(t testing.TB, store kv.Storage, se session.Session) *TestKit

NewTestKitWithSession returns a new *TestKit.

func (*TestKit) CheckExecResult

func (tk *TestKit) CheckExecResult(affectedRows, insertID int64)

CheckExecResult checks the affected rows and the insert id after executing MustExec.

func (*TestKit) CheckLastMessage

func (tk *TestKit) CheckLastMessage(msg string)

CheckLastMessage checks last message after executing MustExec

func (*TestKit) Exec

func (tk *TestKit) Exec(sql string, args ...interface{}) (sqlexec.RecordSet, error)

Exec executes a sql statement using the prepared stmt API

func (*TestKit) ExecToErr

func (tk *TestKit) ExecToErr(sql string, args ...interface{}) error

ExecToErr executes a sql statement and discard results.

func (*TestKit) ExecWithContext

func (tk *TestKit) ExecWithContext(ctx context.Context, sql string, args ...interface{}) (rs sqlexec.RecordSet, err error)

ExecWithContext executes a sql statement using the prepared stmt API

func (*TestKit) HasKeywordInOperatorInfo

func (tk *TestKit) HasKeywordInOperatorInfo(sql string, keyword string, args ...interface{}) bool

HasKeywordInOperatorInfo checks if the result execution plan contains specific keyword in the operator info.

func (*TestKit) HasPlan

func (tk *TestKit) HasPlan(sql string, plan string, args ...interface{}) bool

HasPlan checks if the result execution plan contains specific plan.

func (*TestKit) HasPlan4ExplainFor

func (tk *TestKit) HasPlan4ExplainFor(result *Result, plan string) bool

HasPlan4ExplainFor checks if the result execution plan contains specific plan.

func (*TestKit) HasPlanForLastExecution

func (tk *TestKit) HasPlanForLastExecution(plan string) bool

HasPlanForLastExecution checks if the execution plan of the last execution contains specific plan.

func (*TestKit) HasTiFlashPlan

func (tk *TestKit) HasTiFlashPlan(sql string, args ...interface{}) bool

HasTiFlashPlan checks if the result execution plan contains TiFlash plan.

func (*TestKit) MustContainErrMsg

func (tk *TestKit) MustContainErrMsg(sql string, errStr interface{})

MustContainErrMsg executes a sql statement and assert its error message containing errStr.

func (*TestKit) MustExec

func (tk *TestKit) MustExec(sql string, args ...interface{})

MustExec executes a sql statement and asserts nil error.

func (*TestKit) MustExecToErr

func (tk *TestKit) MustExecToErr(sql string, args ...interface{})

MustExecToErr executes a sql statement and must return Error.

func (*TestKit) MustExecWithContext

func (tk *TestKit) MustExecWithContext(ctx context.Context, sql string, args ...interface{})

MustExecWithContext executes a sql statement and asserts nil error.

func (*TestKit) MustGetDBError

func (tk *TestKit) MustGetDBError(sql string, dberr *terror.Error)

MustGetDBError executes a sql statement and assert its terror.

func (*TestKit) MustGetErrCode

func (tk *TestKit) MustGetErrCode(sql string, errCode int)

MustGetErrCode executes a sql statement and assert it's error code.

func (*TestKit) MustGetErrMsg

func (tk *TestKit) MustGetErrMsg(sql string, errStr string)

MustGetErrMsg executes a sql statement and assert its error message.

func (*TestKit) MustIndexLookup

func (tk *TestKit) MustIndexLookup(sql string, args ...interface{}) *Result

MustIndexLookup checks whether the plan for the sql is IndexLookUp.

func (*TestKit) MustMatchErrMsg

func (tk *TestKit) MustMatchErrMsg(sql string, errRx interface{})

MustMatchErrMsg executes a sql statement and assert its error message matching errRx.

func (*TestKit) MustNoGlobalStats

func (tk *TestKit) MustNoGlobalStats(table string) bool

MustNoGlobalStats checks if there is no global stats.

func (*TestKit) MustPartition

func (tk *TestKit) MustPartition(sql string, partitions string, args ...interface{}) *Result

MustPartition checks if the result execution plan must read specific partitions.

func (*TestKit) MustPartitionByList

func (tk *TestKit) MustPartitionByList(sql string, partitions []string, args ...interface{}) *Result

MustPartitionByList checks if the result execution plan must read specific partitions by list.

func (*TestKit) MustPointGet

func (tk *TestKit) MustPointGet(sql string, args ...interface{}) *Result

MustPointGet checks whether the plan for the sql is Point_Get.

func (*TestKit) MustQuery

func (tk *TestKit) MustQuery(sql string, args ...interface{}) *Result

MustQuery query the statements and returns result rows. If expected result is set it asserts the query result equals expected result.

func (*TestKit) MustQueryWithContext

func (tk *TestKit) MustQueryWithContext(ctx context.Context, sql string, args ...interface{}) *Result

MustQueryWithContext query the statements and returns result rows.

func (*TestKit) MustUseIndex

func (tk *TestKit) MustUseIndex(sql string, index string, args ...interface{}) bool

MustUseIndex checks if the result execution plan contains specific index(es).

func (*TestKit) MustUseIndex4ExplainFor

func (tk *TestKit) MustUseIndex4ExplainFor(result *Result, index string) bool

MustUseIndex4ExplainFor checks if the result execution plan contains specific index(es).

func (*TestKit) NotHasKeywordInOperatorInfo

func (tk *TestKit) NotHasKeywordInOperatorInfo(sql string, keyword string, args ...interface{}) bool

NotHasKeywordInOperatorInfo checks if the result execution plan doesn't contain specific keyword in the operator info.

func (*TestKit) QueryToErr

func (tk *TestKit) QueryToErr(sql string, args ...interface{}) error

QueryToErr executes a sql statement and discard results.

func (*TestKit) RefreshConnectionID

func (tk *TestKit) RefreshConnectionID()

RefreshConnectionID refresh the connection ID for session of the testkit

func (*TestKit) RefreshSession

func (tk *TestKit) RefreshSession()

RefreshSession set a new session for the testkit

func (*TestKit) ResultSetToResult

func (tk *TestKit) ResultSetToResult(rs sqlexec.RecordSet, comment string) *Result

ResultSetToResult converts sqlexec.RecordSet to testkit.Result. It is used to check results of execute statement in binary mode.

func (*TestKit) ResultSetToResultWithCtx

func (tk *TestKit) ResultSetToResultWithCtx(ctx context.Context, rs sqlexec.RecordSet, comment string) *Result

ResultSetToResultWithCtx converts sqlexec.RecordSet to testkit.Result.

func (*TestKit) Session

func (tk *TestKit) Session() session.Session

Session return the session associated with the testkit

func (*TestKit) SetSession

func (tk *TestKit) SetSession(session session.Session)

SetSession set the session of testkit

func (*TestKit) UsedPartitions

func (tk *TestKit) UsedPartitions(sql string, args ...interface{}) *Result

UsedPartitions returns the partition names that will be used or all/dual.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL