sandboxconn

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2017 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var SandboxSQRowCount = int64(10)

SandboxSQRowCount is the default number of fake splits returned.

View Source
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.MakeTrusted(sqltypes.Int32, []byte("1")),
		sqltypes.MakeTrusted(sqltypes.VarChar, []byte("foo")),
	}},
}

SingleRowResult is returned when there is no pre-stored result.

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

	// Queries stores the non-batch requests received.
	Queries []querytypes.BoundQuery

	// BatchQueries stores the batch requests received
	// Each batch request is inlined as a slice of Queries.
	BatchQueries [][]querytypes.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

func NewSandboxConn(t *topodatapb.Tablet) *SandboxConn

NewSandboxConn returns a new SandboxConn targeted to the provided tablet.

func (*SandboxConn) Begin

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

Begin is part of the QueryService interface.

func (*SandboxConn) BeginExecute

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

BeginExecute is part of the QueryService interface.

func (*SandboxConn) BeginExecuteBatch

func (sbc *SandboxConn) BeginExecuteBatch(ctx context.Context, target *querypb.Target, queries []querytypes.BoundQuery, asTransaction bool, options *querypb.ExecuteOptions) ([]sqltypes.Result, int64, 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) 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]interface{}, transactionID 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 []querytypes.BoundQuery, asTransaction bool, transactionID int64, options *querypb.ExecuteOptions) ([]sqltypes.Result, error)

ExecuteBatch is part of the QueryService interface.

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

func (sbc *SandboxConn) Rollback(ctx context.Context, target *querypb.Target, transactionID 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) SplitQuery

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

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

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]interface{}, 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) Tablet

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

Tablet is part of the QueryService interface.

func (*SandboxConn) UpdateStream

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.

Jump to

Keyboard shortcuts

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