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) (int64, *topodatapb.TabletAlias, error)
- func (sbc *SandboxConn) BeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, query string, ...) (*sqltypes.Result, int64, *topodatapb.TabletAlias, error)
- func (sbc *SandboxConn) BeginExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, ...) ([]sqltypes.Result, int64, *topodatapb.TabletAlias, error)
- 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) ExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, ...) ([]sqltypes.Result, error)
- func (sbc *SandboxConn) ExpectVStreamStartPos(startPos 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(_ *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) ReserveBeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, ...) (*sqltypes.Result, int64, int64, *topodatapb.TabletAlias, error)
- func (sbc *SandboxConn) ReserveExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, ...) (*sqltypes.Result, int64, *topodatapb.TabletAlias, error)
- func (sbc *SandboxConn) ResultsAllFetched() bool
- 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) SetResults(r []*sqltypes.Result)
- func (sbc *SandboxConn) SetRollback(ctx context.Context, target *querypb.Target, dtid string, transactionID int64) (err error)
- 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) VStream(ctx context.Context, target *querypb.Target, startPos string, ...) error
- func (sbc *SandboxConn) VStreamResults(ctx context.Context, target *querypb.Target, query string, ...) error
- func (sbc *SandboxConn) VStreamRows(ctx context.Context, target *querypb.Target, query string, ...) error
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}, {Name: "value", Type: sqltypes.VarChar}, }, 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}, {Name: "value", Type: sqltypes.VarChar}, }, 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 // 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 // These Count vars report how often the corresponding // functions were called. ExecCount sync2.AtomicInt64 BeginCount sync2.AtomicInt64 CommitCount sync2.AtomicInt64 RollbackCount sync2.AtomicInt64 AsTransactionCount sync2.AtomicInt64 PrepareCount sync2.AtomicInt64 CommitPreparedCount sync2.AtomicInt64 RollbackPreparedCount sync2.AtomicInt64 CreateTransactionCount sync2.AtomicInt64 StartCommitCount sync2.AtomicInt64 SetRollbackCount sync2.AtomicInt64 ConcludeTransactionCount sync2.AtomicInt64 ReadTransactionCount sync2.AtomicInt64 ReserveCount sync2.AtomicInt64 ReleaseCount sync2.AtomicInt64 // 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 MessageIDs []*querypb.Value // vstream expectations. StartPos string VStreamEvents [][]*binlogdatapb.VEvent VStreamErrors []error VStreamCh chan *binlogdatapb.VEvent // transaction id generator TransactionID sync2.AtomicInt64 // reserve id generator ReserveID sync2.AtomicInt64 // this error will only happen once EphemeralShardErr error // 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) (int64, *topodatapb.TabletAlias, 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) (*sqltypes.Result, int64, *topodatapb.TabletAlias, error)
BeginExecute is part of the QueryService interface.
func (*SandboxConn) BeginExecuteBatch ¶
func (sbc *SandboxConn) BeginExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, asTransaction bool, options *querypb.ExecuteOptions) ([]sqltypes.Result, int64, *topodatapb.TabletAlias, error)
BeginExecuteBatch is part of the QueryService interface.
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) ExecuteBatch ¶
func (sbc *SandboxConn) ExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, asTransaction bool, transactionID int64, options *querypb.ExecuteOptions) ([]sqltypes.Result, error)
ExecuteBatch 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) 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(_ *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 sepcified 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) ReserveBeginExecute ¶
func (sbc *SandboxConn) ReserveBeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) (*sqltypes.Result, int64, int64, *topodatapb.TabletAlias, error)
ReserveBeginExecute implements 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) (*sqltypes.Result, int64, *topodatapb.TabletAlias, error)
ReserveExecute implements the QueryService interface
func (*SandboxConn) ResultsAllFetched ¶ added in v0.10.0
func (sbc *SandboxConn) ResultsAllFetched() bool
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) 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) 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, 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 is not implemented.
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) VStream ¶
func (sbc *SandboxConn) VStream(ctx context.Context, target *querypb.Target, startPos string, tablePKs []*binlogdatapb.TableLastPK, filter *binlogdatapb.Filter, 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, target *querypb.Target, query string, lastpk *querypb.QueryResult, send func(*binlogdatapb.VStreamRowsResponse) error) error
VStreamRows is part of the QueryService interface.