go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/vttablet/sandboxconn Index | Files

package sandboxconn

import "gopkg.in/src-d/go-vitess.v1/vt/vttablet/sandboxconn"

Package sandboxconn provides a fake QueryService implementation for tests. It can return real results, and simulate error cases.

Index

Package Files

sandboxconn.go

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},
    },
    RowsAffected: 1,
    InsertID:     0,
    Rows: [][]sqltypes.Value{{
        sqltypes.NewInt32(1),
        sqltypes.NewVarChar("foo"),
    }},
}

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},
    },
    RowsAffected: 0,
    InsertID:     0,
    Rows: [][]sqltypes.Value{{
        sqltypes.NewInt32(1),
        sqltypes.NewVarChar("foo"),
    }},
}

StreamRowResult is SingleRowResult with RowsAffected set to 0.

type SandboxConn Uses

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

    // 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

    // transaction id generator
    TransactionID sync2.AtomicInt64
    // contains filtered or unexported fields
}

SandboxConn satisfies the QueryService interface

func NewSandboxConn Uses

func NewSandboxConn(t *topodatapb.Tablet) *SandboxConn

NewSandboxConn returns a new SandboxConn targeted to the provided tablet.

func (*SandboxConn) Begin Uses

func (sbc *SandboxConn) Begin(ctx context.Context, target *querypb.Target, options *querypb.ExecuteOptions) (int64, error)

Begin is part of the QueryService interface.

func (*SandboxConn) BeginExecute Uses

func (sbc *SandboxConn) BeginExecute(ctx context.Context, target *querypb.Target, query string, bindVars map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) (*sqltypes.Result, int64, error)

BeginExecute is part of the QueryService interface.

func (*SandboxConn) BeginExecuteBatch Uses

func (sbc *SandboxConn) BeginExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, asTransaction bool, options *querypb.ExecuteOptions) ([]sqltypes.Result, int64, error)

BeginExecuteBatch is part of the QueryService interface.

func (*SandboxConn) Close Uses

func (sbc *SandboxConn) Close(ctx context.Context) error

Close does not change ExecCount

func (*SandboxConn) Commit Uses

func (sbc *SandboxConn) Commit(ctx context.Context, target *querypb.Target, transactionID int64) error

Commit is part of the QueryService interface.

func (*SandboxConn) CommitPrepared Uses

func (sbc *SandboxConn) CommitPrepared(ctx context.Context, target *querypb.Target, dtid string) (err error)

CommitPrepared commits the prepared transaction.

func (*SandboxConn) ConcludeTransaction Uses

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 Uses

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 Uses

func (sbc *SandboxConn) Execute(ctx context.Context, target *querypb.Target, query string, bindVars map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

Execute is part of the QueryService interface.

func (*SandboxConn) ExecuteBatch Uses

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) HandlePanic Uses

func (sbc *SandboxConn) HandlePanic(err *error)

HandlePanic is part of the QueryService interface.

func (*SandboxConn) MessageAck Uses

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 Uses

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 Uses

func (sbc *SandboxConn) Prepare(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error)

Prepare prepares the specified transaction.

func (*SandboxConn) ReadTransaction Uses

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) Rollback Uses

func (sbc *SandboxConn) Rollback(ctx context.Context, target *querypb.Target, transactionID int64) error

Rollback is part of the QueryService interface.

func (*SandboxConn) RollbackPrepared Uses

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 Uses

func (sbc *SandboxConn) SetResults(r []*sqltypes.Result)

SetResults sets what this con should return next time.

func (*SandboxConn) SetRollback Uses

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) SplitQuery Uses

func (sbc *SandboxConn) SplitQuery(
    ctx context.Context,
    target *querypb.Target,
    query *querypb.BoundQuery,
    splitColumns []string,
    splitCount int64,
    numRowsPerQueryPart int64,
    algorithm querypb.SplitQueryRequest_Algorithm) ([]*querypb.QuerySplit, error)

SplitQuery returns a single QuerySplit whose 'sql' field describes the received arguments.

func (*SandboxConn) StartCommit Uses

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 Uses

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 Uses

func (sbc *SandboxConn) StreamHealth(ctx context.Context, callback func(*querypb.StreamHealthResponse) error) error

StreamHealth is not implemented.

func (*SandboxConn) Tablet Uses

func (sbc *SandboxConn) Tablet() *topodatapb.Tablet

Tablet is part of the QueryService interface.

func (*SandboxConn) UpdateStream Uses

func (sbc *SandboxConn) UpdateStream(ctx context.Context, target *querypb.Target, position string, timestamp int64, callback func(*querypb.StreamEvent) error) error

UpdateStream is part of the QueryService interface.

func (*SandboxConn) VStream Uses

func (sbc *SandboxConn) VStream(ctx context.Context, target *querypb.Target, startPos string, filter *binlogdatapb.Filter, send func([]*binlogdatapb.VEvent) error) error

VStream is part of the QueryService interface.

func (*SandboxConn) VStreamRows Uses

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.

Package sandboxconn imports 10 packages (graph) and is imported by 2 packages. Updated 2019-06-13. Refresh now. Tools for package owners.