Documentation ¶
Overview ¶
Package sandboxconn provides a fake QueryService implementation for tests. It can return real results, and simulate error cases.
Index ¶
- Variables
- type SandboxConn
- func (sbc *SandboxConn) AddVStreamEvents(events []*binlogdatapb.VEvent, err error)
- func (sbc *SandboxConn) Begin(ctx context.Context, target *querypb.Target, options *querypb.ExecuteOptions) (queryservice.TransactionState, error)
- func (sbc *SandboxConn) BeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, query string, ...) (queryservice.TransactionState, *sqltypes.Result, error)
- func (sbc *SandboxConn) BeginStreamExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, ...) (queryservice.TransactionState, error)
- func (sbc *SandboxConn) ChangeTabletType(typ topodatapb.TabletType)
- func (sbc *SandboxConn) ClearQueries()
- func (sbc *SandboxConn) Close(ctx context.Context) error
- func (sbc *SandboxConn) Commit(ctx context.Context, target *querypb.Target, transactionID int64) (int64, error)
- func (sbc *SandboxConn) CommitPrepared(ctx context.Context, target *querypb.Target, dtid string) (err error)
- func (sbc *SandboxConn) ConcludeTransaction(ctx context.Context, target *querypb.Target, dtid string) (err error)
- func (sbc *SandboxConn) CreateTransaction(ctx context.Context, target *querypb.Target, dtid string, ...) (err error)
- func (sbc *SandboxConn) Execute(ctx context.Context, target *querypb.Target, query string, ...) (*sqltypes.Result, error)
- func (sbc *SandboxConn) ExpectVStreamStartPos(startPos string)
- func (sbc *SandboxConn) GetQueries() []*querypb.BoundQuery
- func (sbc *SandboxConn) GetSchema(ctx context.Context, target *querypb.Target, tableType querypb.SchemaTableType, ...) error
- func (sbc *SandboxConn) GetServingKeyspaces() []string
- func (sbc *SandboxConn) HandlePanic(err *error)
- func (sbc *SandboxConn) MessageAck(ctx context.Context, target *querypb.Target, name string, ids []*querypb.Value) (count int64, err error)
- func (sbc *SandboxConn) MessageStream(ctx context.Context, target *querypb.Target, name string, ...) (err error)
- func (sbc *SandboxConn) Prepare(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error)
- func (sbc *SandboxConn) QueryServiceByAlias(_ context.Context, _ *topodatapb.TabletAlias, _ *querypb.Target) (queryservice.QueryService, error)
- func (sbc *SandboxConn) ReadTransaction(ctx context.Context, target *querypb.Target, dtid string) (metadata *querypb.TransactionMetadata, err error)
- func (sbc *SandboxConn) Release(ctx context.Context, target *querypb.Target, transactionID, reservedID int64) error
- func (sbc *SandboxConn) RequireQueriesLocking()
- func (sbc *SandboxConn) ReserveBeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, ...) (queryservice.ReservedTransactionState, *sqltypes.Result, error)
- func (sbc *SandboxConn) ReserveBeginStreamExecute(ctx context.Context, target *querypb.Target, preQueries []string, ...) (queryservice.ReservedTransactionState, error)
- func (sbc *SandboxConn) ReserveExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, ...) (queryservice.ReservedState, *sqltypes.Result, error)
- func (sbc *SandboxConn) ReserveStreamExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, ...) (queryservice.ReservedState, error)
- func (sbc *SandboxConn) Rollback(ctx context.Context, target *querypb.Target, transactionID int64) (int64, error)
- func (sbc *SandboxConn) RollbackPrepared(ctx context.Context, target *querypb.Target, dtid string, originalID int64) (err error)
- func (sbc *SandboxConn) SetPanic(i interface{})
- func (sbc *SandboxConn) SetResults(r []*sqltypes.Result)
- func (sbc *SandboxConn) SetRollback(ctx context.Context, target *querypb.Target, dtid string, transactionID int64) (err error)
- func (sbc *SandboxConn) SetSchemaResult(r []SchemaResult)
- func (sbc *SandboxConn) SetStreamHealthResponse(res *querypb.StreamHealthResponse)
- func (sbc *SandboxConn) StartCommit(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error)
- func (sbc *SandboxConn) StreamExecute(ctx context.Context, target *querypb.Target, query string, ...) error
- func (sbc *SandboxConn) StreamHealth(ctx context.Context, callback func(*querypb.StreamHealthResponse) error) error
- func (sbc *SandboxConn) StringQueries() []string
- func (sbc *SandboxConn) Tablet() *topodatapb.Tablet
- func (sbc *SandboxConn) UnresolvedTransactions(context.Context, *querypb.Target, int64) ([]*querypb.TransactionMetadata, error)
- func (sbc *SandboxConn) VStream(ctx context.Context, request *binlogdatapb.VStreamRequest, ...) error
- func (sbc *SandboxConn) VStreamResults(ctx context.Context, target *querypb.Target, query string, ...) error
- func (sbc *SandboxConn) VStreamRows(ctx context.Context, request *binlogdatapb.VStreamRowsRequest, ...) error
- func (sbc *SandboxConn) VStreamTables(ctx context.Context, request *binlogdatapb.VStreamTablesRequest, ...) error
- type SchemaResult
Constants ¶
This section is empty.
Variables ¶
var SandboxSQRowCount = int64(10)
SandboxSQRowCount is the default number of fake splits returned.
var SingleRowResult = &sqltypes.Result{ Fields: []*querypb.Field{ {Name: "id", Type: sqltypes.Int32, Charset: collations.CollationBinaryID, Flags: uint32(querypb.MySqlFlag_NUM_FLAG)}, {Name: "value", Type: sqltypes.VarChar, Charset: collations.CollationUtf8mb4ID}, }, InsertID: 0, Rows: [][]sqltypes.Value{{ sqltypes.NewInt32(1), sqltypes.NewVarChar("foo"), }}, StatusFlags: sqltypes.ServerStatusAutocommit, }
SingleRowResult is returned when there is no pre-stored result.
var StreamRowResult = &sqltypes.Result{ Fields: []*querypb.Field{ {Name: "id", Type: sqltypes.Int32, Charset: collations.CollationBinaryID, Flags: uint32(querypb.MySqlFlag_NUM_FLAG)}, {Name: "value", Type: sqltypes.VarChar, Charset: collations.CollationUtf8mb4ID}, }, Rows: [][]sqltypes.Value{{ sqltypes.NewInt32(1), sqltypes.NewVarChar("foo"), }}, }
StreamRowResult is SingleRowResult with RowsAffected set to 0.
Functions ¶
This section is empty.
Types ¶
type SandboxConn ¶
type SandboxConn struct { // These errors work for all functions. MustFailCodes map[vtrpcpb.Code]int // ServingKeyspaces is a list of serving keyspaces ServingKeyspaces []string // These errors are triggered only for specific functions. // For now these are just for the 2PC functions. MustFailPrepare int MustFailCommitPrepared int MustFailRollbackPrepared int MustFailCreateTransaction int MustFailStartCommit int MustFailSetRollback int MustFailConcludeTransaction int // MustFailExecute is keyed by the statement type and stores the number // of times to fail when it sees that statement type. // Once, exhausted it will start returning non-error response. MustFailExecute map[sqlparser.StatementType]int // These Count vars report how often the corresponding // functions were called. ExecCount atomic.Int64 BeginCount atomic.Int64 CommitCount atomic.Int64 RollbackCount atomic.Int64 AsTransactionCount atomic.Int64 PrepareCount atomic.Int64 CommitPreparedCount atomic.Int64 RollbackPreparedCount atomic.Int64 CreateTransactionCount atomic.Int64 StartCommitCount atomic.Int64 SetRollbackCount atomic.Int64 ConcludeTransactionCount atomic.Int64 ReadTransactionCount atomic.Int64 UnresolvedTransactionsCount atomic.Int64 ReserveCount atomic.Int64 ReleaseCount atomic.Int64 GetSchemaCount atomic.Int64 // Queries stores the non-batch requests received. Queries []*querypb.BoundQuery // BatchQueries stores the batch requests received // Each batch request is inlined as a slice of Queries. BatchQueries [][]*querypb.BoundQuery // Options stores the options received by all calls. Options []*querypb.ExecuteOptions // ReadTransactionResults is used for returning results for ReadTransaction. ReadTransactionResults []*querypb.TransactionMetadata // UnresolvedTransactionsResult is used for returning results for UnresolvedTransactions. UnresolvedTransactionsResult []*querypb.TransactionMetadata MessageIDs []*querypb.Value // vstream expectations. StartPos string VStreamEvents [][]*binlogdatapb.VEvent VStreamErrors []error VStreamCh chan *binlogdatapb.VEvent // transaction id generator TransactionID atomic.Int64 // reserve id generator ReserveID atomic.Int64 // this error will only happen once EphemeralShardErr error NotServing bool // contains filtered or unexported fields }
SandboxConn satisfies the QueryService interface
func NewSandboxConn ¶
func NewSandboxConn(t *topodatapb.Tablet) *SandboxConn
NewSandboxConn returns a new SandboxConn targeted to the provided tablet.
func (*SandboxConn) AddVStreamEvents ¶
func (sbc *SandboxConn) AddVStreamEvents(events []*binlogdatapb.VEvent, err error)
AddVStreamEvents adds a set of VStream events to be returned.
func (*SandboxConn) Begin ¶
func (sbc *SandboxConn) Begin(ctx context.Context, target *querypb.Target, options *querypb.ExecuteOptions) (queryservice.TransactionState, error)
Begin is part of the QueryService interface.
func (*SandboxConn) BeginExecute ¶
func (sbc *SandboxConn) BeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, query string, bindVars map[string]*querypb.BindVariable, reservedID int64, options *querypb.ExecuteOptions) (queryservice.TransactionState, *sqltypes.Result, error)
BeginExecute is part of the QueryService interface.
func (*SandboxConn) BeginStreamExecute ¶ added in v0.13.0
func (sbc *SandboxConn) BeginStreamExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, reservedID int64, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) (queryservice.TransactionState, error)
BeginStreamExecute is part of the QueryService interface.
func (*SandboxConn) ChangeTabletType ¶ added in v0.10.2
func (sbc *SandboxConn) ChangeTabletType(typ topodatapb.TabletType)
ChangeTabletType changes the tablet type.
func (*SandboxConn) ClearQueries ¶ added in v0.19.0
func (sbc *SandboxConn) ClearQueries()
ClearQueries clears the Queries in sandboxconn.
func (*SandboxConn) Close ¶
func (sbc *SandboxConn) Close(ctx context.Context) error
Close does not change ExecCount
func (*SandboxConn) Commit ¶
func (sbc *SandboxConn) Commit(ctx context.Context, target *querypb.Target, transactionID int64) (int64, error)
Commit is part of the QueryService interface.
func (*SandboxConn) CommitPrepared ¶
func (sbc *SandboxConn) CommitPrepared(ctx context.Context, target *querypb.Target, dtid string) (err error)
CommitPrepared commits the prepared transaction.
func (*SandboxConn) ConcludeTransaction ¶
func (sbc *SandboxConn) ConcludeTransaction(ctx context.Context, target *querypb.Target, dtid string) (err error)
ConcludeTransaction deletes the 2pc transaction metadata essentially resolving it.
func (*SandboxConn) CreateTransaction ¶
func (sbc *SandboxConn) CreateTransaction(ctx context.Context, target *querypb.Target, dtid string, participants []*querypb.Target) (err error)
CreateTransaction creates the metadata for a 2PC transaction.
func (*SandboxConn) Execute ¶
func (sbc *SandboxConn) Execute(ctx context.Context, target *querypb.Target, query string, bindVars map[string]*querypb.BindVariable, transactionID, reservedID int64, options *querypb.ExecuteOptions) (*sqltypes.Result, error)
Execute is part of the QueryService interface.
func (*SandboxConn) ExpectVStreamStartPos ¶
func (sbc *SandboxConn) ExpectVStreamStartPos(startPos string)
ExpectVStreamStartPos makes the conn verify that that the next vstream request has the right startPos.
func (*SandboxConn) GetQueries ¶ added in v0.19.0
func (sbc *SandboxConn) GetQueries() []*querypb.BoundQuery
GetQueries gets the Queries from sandboxconn.
func (*SandboxConn) GetSchema ¶ added in v0.16.0
func (sbc *SandboxConn) GetSchema(ctx context.Context, target *querypb.Target, tableType querypb.SchemaTableType, tableNames []string, callback func(schemaRes *querypb.GetSchemaResponse) error) error
GetSchema implements the QueryService interface
func (*SandboxConn) GetServingKeyspaces ¶ added in v0.18.0
func (sbc *SandboxConn) GetServingKeyspaces() []string
GetServingKeyspaces returns list of serving keyspaces.
func (*SandboxConn) HandlePanic ¶
func (sbc *SandboxConn) HandlePanic(err *error)
HandlePanic is part of the QueryService interface.
func (*SandboxConn) MessageAck ¶
func (sbc *SandboxConn) MessageAck(ctx context.Context, target *querypb.Target, name string, ids []*querypb.Value) (count int64, err error)
MessageAck is part of the QueryService interface.
func (*SandboxConn) MessageStream ¶
func (sbc *SandboxConn) MessageStream(ctx context.Context, target *querypb.Target, name string, callback func(*sqltypes.Result) error) (err error)
MessageStream is part of the QueryService interface.
func (*SandboxConn) Prepare ¶
func (sbc *SandboxConn) Prepare(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error)
Prepare prepares the specified transaction.
func (*SandboxConn) QueryServiceByAlias ¶
func (sbc *SandboxConn) QueryServiceByAlias(_ context.Context, _ *topodatapb.TabletAlias, _ *querypb.Target) (queryservice.QueryService, error)
QueryServiceByAlias is part of the Gateway interface.
func (*SandboxConn) ReadTransaction ¶
func (sbc *SandboxConn) ReadTransaction(ctx context.Context, target *querypb.Target, dtid string) (metadata *querypb.TransactionMetadata, err error)
ReadTransaction returns the metadata for the specified dtid.
func (*SandboxConn) Release ¶
func (sbc *SandboxConn) Release(ctx context.Context, target *querypb.Target, transactionID, reservedID int64) error
Release implements the QueryService interface
func (*SandboxConn) RequireQueriesLocking ¶ added in v0.19.0
func (sbc *SandboxConn) RequireQueriesLocking()
RequireQueriesLocking sets the sandboxconn to require locking the access of Queries field.
func (*SandboxConn) ReserveBeginExecute ¶
func (sbc *SandboxConn) ReserveBeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, postBeginQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) (queryservice.ReservedTransactionState, *sqltypes.Result, error)
ReserveBeginExecute implements the QueryService interface
func (*SandboxConn) ReserveBeginStreamExecute ¶ added in v0.13.0
func (sbc *SandboxConn) ReserveBeginStreamExecute(ctx context.Context, target *querypb.Target, preQueries []string, postBeginQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) (queryservice.ReservedTransactionState, error)
ReserveBeginStreamExecute is part of the QueryService interface.
func (*SandboxConn) ReserveExecute ¶
func (sbc *SandboxConn) ReserveExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions) (queryservice.ReservedState, *sqltypes.Result, error)
ReserveExecute implements the QueryService interface
func (*SandboxConn) ReserveStreamExecute ¶ added in v0.13.0
func (sbc *SandboxConn) ReserveStreamExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) (queryservice.ReservedState, error)
ReserveStreamExecute is part of the QueryService interface.
func (*SandboxConn) Rollback ¶
func (sbc *SandboxConn) Rollback(ctx context.Context, target *querypb.Target, transactionID int64) (int64, error)
Rollback is part of the QueryService interface.
func (*SandboxConn) RollbackPrepared ¶
func (sbc *SandboxConn) RollbackPrepared(ctx context.Context, target *querypb.Target, dtid string, originalID int64) (err error)
RollbackPrepared rolls back the prepared transaction.
func (*SandboxConn) SetPanic ¶ added in v0.20.0
func (sbc *SandboxConn) SetPanic(i interface{})
func (*SandboxConn) SetResults ¶
func (sbc *SandboxConn) SetResults(r []*sqltypes.Result)
SetResults sets what this con should return next time.
func (*SandboxConn) SetRollback ¶
func (sbc *SandboxConn) SetRollback(ctx context.Context, target *querypb.Target, dtid string, transactionID int64) (err error)
SetRollback transitions the 2pc transaction to the Rollback state. If a transaction id is provided, that transaction is also rolled back.
func (*SandboxConn) SetSchemaResult ¶ added in v0.16.0
func (sbc *SandboxConn) SetSchemaResult(r []SchemaResult)
SetSchemaResult sets what GetSchema should return on each call.
func (*SandboxConn) SetStreamHealthResponse ¶ added in v0.17.7
func (sbc *SandboxConn) SetStreamHealthResponse(res *querypb.StreamHealthResponse)
SetStreamHealthResponse sets the StreamHealthResponse to be returned in StreamHealth.
func (*SandboxConn) StartCommit ¶
func (sbc *SandboxConn) StartCommit(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error)
StartCommit atomically commits the transaction along with the decision to commit the associated 2pc transaction.
func (*SandboxConn) StreamExecute ¶
func (sbc *SandboxConn) StreamExecute(ctx context.Context, target *querypb.Target, query string, bindVars map[string]*querypb.BindVariable, transactionID int64, reservedID int64, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) error
StreamExecute is part of the QueryService interface.
func (*SandboxConn) StreamHealth ¶
func (sbc *SandboxConn) StreamHealth(ctx context.Context, callback func(*querypb.StreamHealthResponse) error) error
StreamHealth always mocks a "healthy" result by default. If you want to override this behavior you can call SetStreamHealthResponse.
func (*SandboxConn) StringQueries ¶
func (sbc *SandboxConn) StringQueries() []string
StringQueries returns the queries executed as a slice of strings
func (*SandboxConn) Tablet ¶
func (sbc *SandboxConn) Tablet() *topodatapb.Tablet
Tablet is part of the QueryService interface.
func (*SandboxConn) UnresolvedTransactions ¶ added in v0.21.0
func (sbc *SandboxConn) UnresolvedTransactions(context.Context, *querypb.Target, int64) ([]*querypb.TransactionMetadata, error)
UnresolvedTransactions is part of the QueryService interface.
func (*SandboxConn) VStream ¶
func (sbc *SandboxConn) VStream(ctx context.Context, request *binlogdatapb.VStreamRequest, send func([]*binlogdatapb.VEvent) error) error
VStream is part of the QueryService interface.
func (*SandboxConn) VStreamResults ¶
func (sbc *SandboxConn) VStreamResults(ctx context.Context, target *querypb.Target, query string, send func(*binlogdatapb.VStreamResultsResponse) error) error
VStreamResults is part of the QueryService interface.
func (*SandboxConn) VStreamRows ¶
func (sbc *SandboxConn) VStreamRows(ctx context.Context, request *binlogdatapb.VStreamRowsRequest, send func(*binlogdatapb.VStreamRowsResponse) error) error
VStreamRows is part of the QueryService interface.
func (*SandboxConn) VStreamTables ¶ added in v0.18.0
func (sbc *SandboxConn) VStreamTables(ctx context.Context, request *binlogdatapb.VStreamTablesRequest, send func(response *binlogdatapb.VStreamTablesResponse) error) error
VStreamTables is part of the QueryService interface.