mock

package
v1.1.0-beta.0...-ec288d9 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Overview

Package mock is just for test only.

Index

Constants

This section is empty.

Variables

View Source
var MockInfoschema func(tbList []*model.TableInfo) infoschema.MetaOnlyInfoSchema

MockInfoschema only serves for test.

Functions

This section is empty.

Types

type Client

type Client struct {
	kv.RequestTypeSupportedChecker
	MockResponse kv.Response
}

Client implement kv.Client interface, mocked from "CopClient" defined in "store/tikv/copprocessor.go".

func (*Client) Send

func (c *Client) Send(_ context.Context, _ *kv.Request, _ any, _ *kv.ClientSendOption) kv.Response

Send implement kv.Client interface.

type Context

type Context struct {
	planctx.EmptyPlanContextExtended
	*sessionexpr.ExprContext

	Store kv.Storage // mock global variable
	// contains filtered or unexported fields
}

Context represents mocked sessionctx.Context.

func NewContext

func NewContext() *Context

NewContext creates a new mocked sessionctx.Context. This function should only be used for testing.

func NewContextDeprecated

func NewContextDeprecated() *Context

NewContextDeprecated creates a new mocked sessionctx.Context. Deprecated: This method is only used for some legacy code. DO NOT use mock.Context in new production code, and use the real Context instead.

func (*Context) AddTableLock

func (*Context) AddTableLock(_ []model.TableLockTpInfo)

AddTableLock implements the sessionctx.Context interface.

func (*Context) Cancel

func (c *Context) Cancel()

Cancel implements the Session interface.

func (*Context) CheckTableLocked

func (*Context) CheckTableLocked(_ int64) (bool, pmodel.TableLockType)

CheckTableLocked implements the sessionctx.Context interface.

func (*Context) ClearValue

func (c *Context) ClearValue(key fmt.Stringer)

ClearValue implements sessionctx.Context ClearValue interface.

func (*Context) Close

func (*Context) Close()

Close implements the sessionctx.Context interface.

func (*Context) CommitTxn

func (c *Context) CommitTxn(ctx context.Context) error

CommitTxn indicates an expected call of CommitTxn.

func (*Context) DecodeSessionStates

DecodeSessionStates implements sessionctx.Context DecodeSessionStates interface.

func (*Context) DisableSandBoxMode

func (c *Context) DisableSandBoxMode()

DisableSandBoxMode enable the sandbox mode.

func (*Context) EnableSandBoxMode

func (c *Context) EnableSandBoxMode()

EnableSandBoxMode enable the sandbox mode.

func (*Context) EncodeSessionStates

EncodeSessionStates implements sessionctx.Context EncodeSessionStates interface.

func (*Context) ExecRestrictedSQL

func (*Context) ExecRestrictedSQL(_ context.Context, _ []sqlexec.OptionFuncAlias, _ string, _ ...any) ([]chunk.Row, []*resolve.ResultField, error)

ExecRestrictedSQL implements sqlexec.RestrictedSQLExecutor ExecRestrictedSQL interface.

func (*Context) ExecRestrictedStmt

func (*Context) ExecRestrictedStmt(_ context.Context, _ ast.StmtNode, _ ...sqlexec.OptionFuncAlias) ([]chunk.Row, []*resolve.ResultField, error)

ExecRestrictedStmt implements sqlexec.RestrictedSQLExecutor ExecRestrictedStmt interface.

func (*Context) Execute

func (*Context) Execute(_ context.Context, _ string) ([]sqlexec.RecordSet, error)

Execute implements sqlexec.SQLExecutor Execute interface.

func (*Context) ExecuteInternal

func (*Context) ExecuteInternal(_ context.Context, _ string, _ ...any) (sqlexec.RecordSet, error)

ExecuteInternal implements sqlexec.SQLExecutor ExecuteInternal interface.

func (*Context) ExecuteStmt

func (*Context) ExecuteStmt(_ context.Context, _ ast.StmtNode) (sqlexec.RecordSet, error)

ExecuteStmt implements sqlexec.SQLExecutor ExecuteStmt interface.

func (*Context) GetAdvisoryLock

func (*Context) GetAdvisoryLock(_ string, _ int64) error

GetAdvisoryLock acquires an advisory lock

func (*Context) GetAllTableLocks

func (*Context) GetAllTableLocks() []model.TableLockTpInfo

GetAllTableLocks implements the sessionctx.Context interface.

func (*Context) GetBuildPBCtx

func (c *Context) GetBuildPBCtx() *planctx.BuildPBContext

GetBuildPBCtx returns the `ToPB` context of the session

func (*Context) GetBuiltinFunctionUsage

func (*Context) GetBuiltinFunctionUsage() map[string]uint32

GetBuiltinFunctionUsage implements sessionctx.Context GetBuiltinFunctionUsage interface.

func (*Context) GetClient

func (c *Context) GetClient() kv.Client

GetClient implements sessionctx.Context GetClient interface.

func (*Context) GetCommitWaitGroup

func (*Context) GetCommitWaitGroup() *sync.WaitGroup

GetCommitWaitGroup implements the sessionctx.Context interface

func (*Context) GetCursorTracker

func (*Context) GetCursorTracker() cursor.Tracker

GetCursorTracker implements the sessionctx.Context interface

func (*Context) GetDistSQLCtx

func (c *Context) GetDistSQLCtx() *distsqlctx.DistSQLContext

GetDistSQLCtx returns the distsql context of the session

func (*Context) GetDomainInfoSchema

func (c *Context) GetDomainInfoSchema() infoschema.MetaOnlyInfoSchema

GetDomainInfoSchema returns the latest information schema in domain

func (*Context) GetExprCtx

func (c *Context) GetExprCtx() exprctx.ExprContext

GetExprCtx returns the expression context of the session.

func (*Context) GetExtensions

func (*Context) GetExtensions() *extension.SessionExtensions

GetExtensions returns the `*extension.SessionExtensions` object

func (*Context) GetGlobalSysVar

func (*Context) GetGlobalSysVar(_ sessionctx.Context, name string) (string, error)

GetGlobalSysVar implements GlobalVarAccessor GetGlobalSysVar interface.

func (*Context) GetInfoSchema

func (c *Context) GetInfoSchema() infoschema.MetaOnlyInfoSchema

GetInfoSchema implements sessionctx.Context GetInfoSchema interface.

func (*Context) GetMPPClient

func (c *Context) GetMPPClient() kv.MPPClient

GetMPPClient implements sessionctx.Context GetMPPClient interface.

func (*Context) GetNullRejectCheckExprCtx

func (c *Context) GetNullRejectCheckExprCtx() exprctx.ExprContext

GetNullRejectCheckExprCtx gets the expression context with null rejected check.

func (*Context) GetPlanCtx

func (c *Context) GetPlanCtx() planctx.PlanContext

GetPlanCtx returns the PlanContext.

func (*Context) GetPreparedTxnFuture

func (c *Context) GetPreparedTxnFuture() sessionctx.TxnFuture

GetPreparedTxnFuture returns the TxnFuture if it is prepared. It returns nil otherwise.

func (*Context) GetRangerCtx

func (c *Context) GetRangerCtx() *rangerctx.RangerContext

GetRangerCtx returns the context used in `ranger` related functions

func (*Context) GetRestrictedSQLExecutor

func (c *Context) GetRestrictedSQLExecutor() sqlexec.RestrictedSQLExecutor

GetRestrictedSQLExecutor returns the RestrictedSQLExecutor.

func (*Context) GetSQLExecutor

func (c *Context) GetSQLExecutor() sqlexec.SQLExecutor

GetSQLExecutor returns the SQLExecutor.

func (*Context) GetSessionManager

func (c *Context) GetSessionManager() util.SessionManager

GetSessionManager implements the sessionctx.Context interface.

func (*Context) GetSessionPlanCache

func (c *Context) GetSessionPlanCache() sessionctx.SessionPlanCache

GetSessionPlanCache implements the sessionctx.Context interface.

func (*Context) GetSessionVars

func (c *Context) GetSessionVars() *variable.SessionVars

GetSessionVars implements the sessionctx.Context GetSessionVars interface.

func (*Context) GetStmtStats

func (*Context) GetStmtStats() *stmtstats.StatementStats

GetStmtStats implements the sessionctx.Context interface.

func (*Context) GetStore

func (c *Context) GetStore() kv.Storage

GetStore gets the store of session.

func (*Context) GetTableCtx

func (c *Context) GetTableCtx() tblctx.MutateContext

GetTableCtx returns the table.MutateContext

func (*Context) GetTxnWriteThroughputSLI

func (*Context) GetTxnWriteThroughputSLI() *sli.TxnWriteThroughputSLI

GetTxnWriteThroughputSLI implements the sessionctx.Context interface.

func (*Context) GoCtx

func (c *Context) GoCtx() context.Context

GoCtx returns standard sessionctx.Context that bind with current transaction.

func (*Context) HasDirtyContent

func (*Context) HasDirtyContent(_ int64) bool

HasDirtyContent implements sessionctx.Context ClearValue interface.

func (*Context) HasLockedTables

func (*Context) HasLockedTables() bool

HasLockedTables implements the sessionctx.Context interface.

func (*Context) InSandBoxMode

func (c *Context) InSandBoxMode() bool

InSandBoxMode indicates that this Session is in sandbox mode

func (*Context) IsDDLOwner

func (c *Context) IsDDLOwner() bool

IsDDLOwner checks whether this session is DDL owner.

func (*Context) IsUsedAdvisoryLock

func (*Context) IsUsedAdvisoryLock(_ string) uint64

IsUsedAdvisoryLock check if a lock name is in use

func (*Context) NewStaleTxnWithStartTS

func (c *Context) NewStaleTxnWithStartTS(ctx context.Context, _ uint64) error

NewStaleTxnWithStartTS implements the sessionctx.Context interface.

func (*Context) NewStmtIndexUsageCollector

func (*Context) NewStmtIndexUsageCollector() *indexusage.StmtIndexUsageCollector

NewStmtIndexUsageCollector implements the sessionctx.Context interface

func (*Context) NewTxn

func (c *Context) NewTxn(context.Context) error

NewTxn implements the sessionctx.Context interface.

func (*Context) ParseWithParams

func (*Context) ParseWithParams(_ context.Context, _ string, _ ...any) (ast.StmtNode, error)

ParseWithParams implements sqlexec.RestrictedSQLExecutor ParseWithParams interface.

func (*Context) PrepareTSFuture

func (c *Context) PrepareTSFuture(_ context.Context, future oracle.Future, _ string) error

PrepareTSFuture implements the sessionctx.Context interface.

func (*Context) RefreshTxnCtx

func (c *Context) RefreshTxnCtx(ctx context.Context) error

RefreshTxnCtx implements the sessionctx.Context interface.

func (*Context) ReleaseAdvisoryLock

func (*Context) ReleaseAdvisoryLock(_ string) bool

ReleaseAdvisoryLock releases an advisory lock

func (*Context) ReleaseAllAdvisoryLocks

func (*Context) ReleaseAllAdvisoryLocks() int

ReleaseAllAdvisoryLocks releases all advisory locks

func (*Context) ReleaseAllTableLocks

func (*Context) ReleaseAllTableLocks()

ReleaseAllTableLocks implements the sessionctx.Context interface.

func (*Context) ReleaseTableLockByTableIDs

func (*Context) ReleaseTableLockByTableIDs(_ []int64)

ReleaseTableLockByTableIDs implements the sessionctx.Context interface.

func (*Context) ReleaseTableLocks

func (*Context) ReleaseTableLocks(_ []model.TableLockTpInfo)

ReleaseTableLocks implements the sessionctx.Context interface.

func (*Context) ReportUsageStats

func (*Context) ReportUsageStats()

ReportUsageStats implements the sessionctx.Context interface.

func (*Context) ResetSessionAndStmtTimeZone

func (c *Context) ResetSessionAndStmtTimeZone(tz *time.Location)

ResetSessionAndStmtTimeZone resets the timezone for session and statement.

func (*Context) RollbackTxn

func (c *Context) RollbackTxn(_ context.Context)

RollbackTxn indicates an expected call of RollbackTxn.

func (*Context) SetGlobalSysVar

func (*Context) SetGlobalSysVar(_ sessionctx.Context, name string, value string) error

SetGlobalSysVar implements GlobalVarAccessor SetGlobalSysVar interface.

func (*Context) SetInfoSchema

func (c *Context) SetInfoSchema(is infoschema.MetaOnlyInfoSchema)

SetInfoSchema is to set info shema for the test.

func (*Context) SetIsDDLOwner

func (c *Context) SetIsDDLOwner(isOwner bool)

SetIsDDLOwner sets return value of IsDDLOwner.

func (*Context) SetSessionManager

func (c *Context) SetSessionManager(sm util.SessionManager)

SetSessionManager set the session manager.

func (*Context) SetValue

func (c *Context) SetValue(key fmt.Stringer, value any)

SetValue implements sessionctx.Context SetValue interface.

func (*Context) ShowProcess

func (*Context) ShowProcess() *util.ProcessInfo

ShowProcess implements sessionctx.Context ShowProcess interface.

func (*Context) StmtCommit

func (*Context) StmtCommit(context.Context)

StmtCommit implements the sessionctx.Context interface.

func (*Context) StmtRollback

func (*Context) StmtRollback(context.Context, bool)

StmtRollback implements the sessionctx.Context interface.

func (*Context) StoreIndexUsage

func (*Context) StoreIndexUsage(_ int64, _ int64, _ int64)

StoreIndexUsage strores the index usage information.

func (*Context) Txn

func (c *Context) Txn(bool) (kv.Transaction, error)

Txn implements sessionctx.Context Txn interface.

func (*Context) UpdateColStatsUsage

func (*Context) UpdateColStatsUsage(_ iter.Seq[model.TableItemID])

UpdateColStatsUsage updates the column stats usage.

func (*Context) Value

func (c *Context) Value(key fmt.Stringer) any

Value implements sessionctx.Context Value interface.

type HookKeyForTest

type HookKeyForTest string

HookKeyForTest is as alias, used by context.WithValue. golint forbits using string type as key in context.WithValue.

type MetricsCounter

type MetricsCounter struct {
	prometheus.Counter
	// contains filtered or unexported fields
}

MetricsCounter is a mock for metrics counter

func (*MetricsCounter) Add

func (c *MetricsCounter) Add(v float64)

Add adds the value

func (*MetricsCounter) Inc

func (c *MetricsCounter) Inc()

Inc increase the value

func (*MetricsCounter) Val

func (c *MetricsCounter) Val() float64

Val returns val

type MockedIter

type MockedIter struct {
	kv.Iterator
	// contains filtered or unexported fields
}

MockedIter is a mocked iter for test

func NewMockIterFromRecords

func NewMockIterFromRecords(t *testing.T, records []*kv.Entry, failOnMultiClose bool) *MockedIter

NewMockIterFromRecords creates a new MockedIter

func (*MockedIter) Close

func (i *MockedIter) Close()

Close implements kv.Iterator.Close

func (*MockedIter) Closed

func (i *MockedIter) Closed() bool

Closed returns if the iter is closed

func (*MockedIter) FailOnMultiClose

func (i *MockedIter) FailOnMultiClose(fail bool)

FailOnMultiClose set if should fail when Close is invoked more than once

func (*MockedIter) GetInjectedNextError

func (i *MockedIter) GetInjectedNextError() error

GetInjectedNextError get the injected error

func (*MockedIter) InjectNextError

func (i *MockedIter) InjectNextError(err error)

InjectNextError injects error to its Next

func (*MockedIter) Next

func (i *MockedIter) Next() error

Next implements kv.Iterator.Next

type SliceIter

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

SliceIter is used to iterate slice

func NewSliceIter

func NewSliceIter(data []*kv.Entry) *SliceIter

NewSliceIter creates a new SliceIter

func (*SliceIter) Close

func (i *SliceIter) Close()

Close closes the iterator.

func (*SliceIter) GetSlice

func (i *SliceIter) GetSlice() []*kv.Entry

GetSlice returns the inner slice

func (*SliceIter) Key

func (i *SliceIter) Key() kv.Key

Key returns the current key.

func (*SliceIter) Next

func (i *SliceIter) Next() error

Next goes the next position. Always return error for this iterator

func (*SliceIter) Valid

func (i *SliceIter) Valid() bool

Valid returns true if the current iterator is valid.

func (*SliceIter) Value

func (i *SliceIter) Value() []byte

Value returns the current value.

type Store

type Store struct {
	Client kv.Client
}

Store implements kv.Storage interface.

func (*Store) Begin

func (*Store) Begin(_ ...tikv.TxnOption) (kv.Transaction, error)

Begin implements kv.Storage interface.

func (*Store) Close

func (*Store) Close() error

Close implements kv.Storage interface.

func (*Store) CurrentVersion

func (*Store) CurrentVersion(_ string) (kv.Version, error)

CurrentVersion implements kv.Storage interface.

func (*Store) Describe

func (*Store) Describe() string

Describe implements kv.Storage interface.

func (*Store) GetClient

func (s *Store) GetClient() kv.Client

GetClient implements kv.Storage interface.

func (*Store) GetCodec

func (*Store) GetCodec() tikv.Codec

GetCodec implements kv.Storage interface.

func (*Store) GetLockWaits

func (*Store) GetLockWaits() ([]*deadlockpb.WaitForEntry, error)

GetLockWaits implements kv.Storage interface.

func (*Store) GetMPPClient

func (*Store) GetMPPClient() kv.MPPClient

GetMPPClient implements kv.Storage interface.

func (*Store) GetMemCache

func (*Store) GetMemCache() kv.MemManager

GetMemCache implements kv.Storage interface

func (*Store) GetMinSafeTS

func (*Store) GetMinSafeTS(_ string) uint64

GetMinSafeTS implements kv.Storage interface.

func (*Store) GetOption

func (*Store) GetOption(_ any) (any, bool)

GetOption implements kv.Storage interface.

func (*Store) GetOracle

func (*Store) GetOracle() oracle.Oracle

GetOracle implements kv.Storage interface.

func (*Store) GetSnapshot

func (*Store) GetSnapshot(_ kv.Version) kv.Snapshot

GetSnapshot implements kv.Storage interface.

func (*Store) Name

func (*Store) Name() string

Name implements kv.Storage interface.

func (*Store) SetOption

func (*Store) SetOption(_, _ any)

SetOption implements kv.Storage interface.

func (*Store) ShowStatus

func (*Store) ShowStatus(_ context.Context, _ string) (any, error)

ShowStatus implements kv.Storage interface.

func (*Store) SupportDeleteRange

func (*Store) SupportDeleteRange() bool

SupportDeleteRange implements kv.Storage interface.

func (*Store) UUID

func (*Store) UUID() string

UUID implements kv.Storage interface.

Jump to

Keyboard shortcuts

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