sandboxconn

package
Version: v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2016 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package sandboxconn provides a fake TabletConn 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{
		{"id", sqltypes.Int32},
		{"value", 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 {
	MustFailRetry  int
	MustFailFatal  int
	MustFailServer int
	MustFailConn   int
	MustFailTxPool int
	MustFailNotTx  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

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

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

SandboxConn satisfies the TabletConn 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) (int64, error)

Begin is part of the TabletConn interface.

func (*SandboxConn) BeginExecute

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

BeginExecute is part of the TabletConn interface.

func (*SandboxConn) BeginExecuteBatch

func (sbc *SandboxConn) BeginExecuteBatch(ctx context.Context, queries []querytypes.BoundQuery, asTransaction bool) ([]sqltypes.Result, int64, error)

BeginExecuteBatch is part of the TabletConn interface.

func (*SandboxConn) Close

func (sbc *SandboxConn) Close()

Close does not change ExecCount

func (*SandboxConn) Commit

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

Commit is part of the TabletConn interface.

func (*SandboxConn) Execute

func (sbc *SandboxConn) Execute(ctx context.Context, query string, bindVars map[string]interface{}, transactionID int64) (*sqltypes.Result, error)

Execute is part of the TabletConn interface.

func (*SandboxConn) ExecuteBatch

func (sbc *SandboxConn) ExecuteBatch(ctx context.Context, queries []querytypes.BoundQuery, asTransaction bool, transactionID int64) ([]sqltypes.Result, error)

ExecuteBatch is part of the TabletConn interface.

func (*SandboxConn) Rollback

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

Rollback is part of the TabletConn interface.

func (*SandboxConn) SetResults

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

SetResults sets what this con should return next time.

func (*SandboxConn) SetTarget

func (sbc *SandboxConn) SetTarget(keyspace, shard string, tabletType topodatapb.TabletType) error

SetTarget is part of the TabletConn interface.

func (*SandboxConn) SplitQuery

func (sbc *SandboxConn) SplitQuery(ctx context.Context, query querytypes.BoundQuery, splitColumn string, splitCount int64) ([]querytypes.QuerySplit, error)

SplitQuery creates splits from the original query by appending the split index as a comment to the SQL. RowCount is always SandboxSQRowCount

func (*SandboxConn) SplitQueryV2

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

SplitQueryV2 returns a single QuerySplit whose 'sql' field describes the received arguments. TODO(erez): Rename to SplitQuery after the migration to SplitQuery V2 is done.

func (*SandboxConn) StreamExecute

func (sbc *SandboxConn) StreamExecute(ctx context.Context, query string, bindVars map[string]interface{}) (sqltypes.ResultStream, error)

StreamExecute is part of the TabletConn interface.

func (*SandboxConn) StreamHealth

func (sbc *SandboxConn) StreamHealth(ctx context.Context) (tabletconn.StreamHealthReader, error)

StreamHealth is not implemented.

func (*SandboxConn) Tablet

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

Tablet is part of the TabletConn interface.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL