tabletconntest

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: 18 Imported by: 2

Documentation

Overview

Package tabletconntest provides the test methods to make sure a tabletconn/queryservice pair over RPC works correctly.

Index

Constants

View Source
const BeginTransactionID int64 = 9990
View Source
const CommitTransactionID int64 = 999044
View Source
const Dtid string = "aa"
View Source
const ExecuteBatchTransactionID int64 = 678
View Source
const ExecuteQuery = "executeQuery"
View Source
const ExecuteTransactionID int64 = 678
View Source
const RollbackTransactionID int64 = 999044
View Source
const SplitQueryAlgorithm = querypb.SplitQueryRequest_FULL_SCAN
View Source
const SplitQueryNumRowsPerQueryPart = 123
View Source
const SplitQuerySplitCount = 372
View Source
const StreamExecuteQuery = "streamExecuteQuery"
View Source
const TestAsTransaction bool = true
View Source
const UpdateStreamPosition = "update stream position"
View Source
const UpdateStreamTimestamp = 123654

Variables

View Source
var (
	MessageName         = "vitess_message"
	MessageStreamResult = &sqltypes.Result{
		Fields: []*querypb.Field{{
			Name: "id",
			Type: sqltypes.VarBinary,
		}, {
			Name: "message",
			Type: sqltypes.VarBinary,
		}},
		Rows: [][]sqltypes.Value{{
			sqltypes.MakeTrusted(sqltypes.VarBinary, []byte("1")),
			sqltypes.MakeTrusted(sqltypes.VarBinary, []byte("row1 value2")),
		}, {
			sqltypes.MakeTrusted(sqltypes.VarBinary, []byte("2")),
			sqltypes.MakeTrusted(sqltypes.VarBinary, []byte("row2 value2")),
		}},
	}
	MessageIDs = []*querypb.Value{{
		Type:  sqltypes.VarChar,
		Value: []byte("1"),
	}}
)
View Source
var ExecuteBatchQueries = []querytypes.BoundQuery{
	{
		Sql: "executeBatchQueries1",
		BindVariables: map[string]interface{}{
			"bind1": &querypb.BindVariable{
				Type:  querypb.Type_INT64,
				Value: []byte("43"),
			},
		},
	},
	{
		Sql: "executeBatchQueries2",
		BindVariables: map[string]interface{}{
			"bind2": &querypb.BindVariable{
				Type:  querypb.Type_INT64,
				Value: []byte("72"),
			},
		},
	},
}
View Source
var ExecuteBatchQueryResultList = []sqltypes.Result{
	{
		Fields: []*querypb.Field{
			{
				Name: "field1",
				Type: sqltypes.Int8,
			},
		},
		RowsAffected: 1232,
		InsertID:     712,
		Rows: [][]sqltypes.Value{
			{
				sqltypes.MakeTrusted(sqltypes.Int8, []byte("1")),
			},
			{
				sqltypes.MakeTrusted(sqltypes.Int8, []byte("2")),
			},
		},
		Extras: &querypb.ResultExtras{
			EventToken: &querypb.EventToken{
				Timestamp: 456322,
				Shard:     "test_shard2",
				Position:  "test_position2",
			},
			Fresher: true,
		},
	},
	{
		Fields: []*querypb.Field{
			{
				Name: "field1",
				Type: sqltypes.VarBinary,
			},
		},
		RowsAffected: 12333,
		InsertID:     74442,
		Rows: [][]sqltypes.Value{
			{
				sqltypes.MakeString([]byte("row1 value1")),
			},
			{
				sqltypes.MakeString([]byte("row1 value2")),
			},
		},
	},
}
View Source
var ExecuteBindVars = map[string]interface{}{
	"bind1": &querypb.BindVariable{
		Type:  querypb.Type_INT64,
		Value: []byte("1114444"),
	},
}
View Source
var ExecuteQueryResult = sqltypes.Result{
	Fields: []*querypb.Field{
		{
			Name: "field1",
			Type: sqltypes.Int8,
		},
		{
			Name: "field2",
			Type: sqltypes.Char,
		},
	},
	RowsAffected: 123,
	InsertID:     72,
	Rows: [][]sqltypes.Value{
		{
			sqltypes.MakeTrusted(sqltypes.Int8, []byte("1")),
			sqltypes.NULL,
		},
		{
			sqltypes.MakeTrusted(sqltypes.Int8, []byte("2")),
			sqltypes.MakeTrusted(sqltypes.Char, []byte("row2 value2")),
		},
	},
	Extras: &querypb.ResultExtras{
		EventToken: &querypb.EventToken{
			Timestamp: 456321,
			Shard:     "test_shard",
			Position:  "test_position",
		},
		Fresher: true,
	},
}
View Source
var Participants = []*querypb.Target{{
	Keyspace: "ks0",
	Shard:    "0",
}, {
	Keyspace: "ks1",
	Shard:    "1",
}}
View Source
var SplitQueryBoundQuery = querytypes.BoundQuery{
	Sql: "splitQuery",
	BindVariables: map[string]interface{}{
		"bind1": &querypb.BindVariable{
			Type:  querypb.Type_INT64,
			Value: []byte("43"),
		},
	},
}
View Source
var SplitQueryQuerySplitList = []querytypes.QuerySplit{
	{
		Sql: "splitQuery",
		BindVariables: map[string]interface{}{
			"bind1": &querypb.BindVariable{
				Type:  querypb.Type_INT64,
				Value: []byte("43"),
			},
			"keyspace_id": &querypb.BindVariable{
				Type:  querypb.Type_INT64,
				Value: []byte("3333"),
			},
		},
		RowCount: 4456,
	},
}
View Source
var SplitQuerySplitColumns = []string{"nice_column_to_split"}
View Source
var StreamExecuteBindVars = map[string]interface{}{
	"bind1": &querypb.BindVariable{
		Type:  querypb.Type_INT64,
		Value: []byte("93848000"),
	},
}
View Source
var StreamExecuteQueryResult1 = sqltypes.Result{
	Fields: []*querypb.Field{
		{
			Name: "field1",
			Type: sqltypes.Int8,
		},
		{
			Name: "field2",
			Type: sqltypes.Char,
		},
	},
}
View Source
var StreamExecuteQueryResult2 = sqltypes.Result{
	Rows: [][]sqltypes.Value{
		{
			sqltypes.MakeTrusted(sqltypes.Int8, []byte("1")),
			sqltypes.MakeTrusted(sqltypes.Char, []byte("row1 value2")),
		},
		{
			sqltypes.MakeTrusted(sqltypes.Int8, []byte("2")),
			sqltypes.MakeTrusted(sqltypes.Char, []byte("row2 value2")),
		},
	},
}
View Source
var TestCallerID = &vtrpcpb.CallerID{
	Principal:    "test_principal",
	Component:    "test_component",
	Subcomponent: "test_subcomponent",
}
View Source
var TestExecuteOptions = &querypb.ExecuteOptions{
	IncludedFields:    querypb.ExecuteOptions_TYPE_ONLY,
	IncludeEventToken: true,
	CompareEventToken: &querypb.EventToken{
		Timestamp: 9876,
		Shard:     "ssss",
		Position:  "pppp",
	},
}
View Source
var TestStreamHealthErrorMsg = "to trigger a server error"
View Source
var TestStreamHealthStreamHealthResponse = &querypb.StreamHealthResponse{
	Target: &querypb.Target{
		Keyspace:   "test_keyspace",
		Shard:      "test_shard",
		TabletType: topodatapb.TabletType_RDONLY,
	},
	Serving:                             true,
	TabletExternallyReparentedTimestamp: 1234589,
	RealtimeStats: &querypb.RealtimeStats{
		HealthError:                            "random error",
		SecondsBehindMaster:                    234,
		BinlogPlayersCount:                     1,
		SecondsBehindMasterFilteredReplication: 2,
		CpuUsage:                               1.0,
	},
}
View Source
var TestTarget = &querypb.Target{
	Keyspace:   "test_keyspace",
	Shard:      "test_shard",
	TabletType: topodatapb.TabletType_REPLICA,
}

TestTarget is the target we use for this test

View Source
var TestVTGateCallerID = &querypb.VTGateCallerID{
	Username: "test_username",
}
View Source
var UpdateStreamStreamEvent1 = querypb.StreamEvent{
	Statements: []*querypb.StreamEvent_Statement{
		{
			Category:  querypb.StreamEvent_Statement_DML,
			TableName: "table1",
		},
	},
	EventToken: &querypb.EventToken{
		Timestamp: 789654,
		Shard:     "shard1",
		Position:  "streaming position 1",
	},
}
View Source
var UpdateStreamStreamEvent2 = querypb.StreamEvent{
	Statements: []*querypb.StreamEvent_Statement{
		{
			Category:  querypb.StreamEvent_Statement_DML,
			TableName: "table2",
		},
	},
	EventToken: &querypb.EventToken{
		Timestamp: 789655,
		Shard:     "shard1",
		Position:  "streaming position 2",
	},
}

Functions

func TestSuite

func TestSuite(t *testing.T, protocol string, tablet *topodatapb.Tablet, fake *FakeQueryService)

TestSuite runs all the tests. If fake.TestingGateway is set, we only test the calls that can go through a gateway.

Types

type FakeQueryService

type FakeQueryService struct {
	TestingGateway bool

	// these fields are used to simulate and synchronize on errors
	HasError      bool
	HasBeginError bool
	TabletError   error
	ErrorWait     chan struct{}

	// these fields are used to simulate and synchronize on panics
	Panics                   bool
	StreamExecutePanicsEarly bool
	UpdateStreamPanicsEarly  bool
	PanicWait                chan struct{}

	// ExpectedTransactionID is what transactionID to expect for Execute
	ExpectedTransactionID int64

	// StreamHealthResponse is what we return for StreamHealth.
	// If not set, return TestStreamHealthStreamHealthResponse
	StreamHealthResponse *querypb.StreamHealthResponse
	// contains filtered or unexported fields
}

FakeQueryService implements a programmable fake for the query service server side.

func CreateFakeServer

func CreateFakeServer(t *testing.T) *FakeQueryService

CreateFakeServer returns the fake server for the tests

func (*FakeQueryService) Begin

func (f *FakeQueryService) Begin(ctx context.Context, target *querypb.Target) (int64, error)

Begin is part of the queryservice.QueryService interface

func (*FakeQueryService) BeginExecute

func (f *FakeQueryService) BeginExecute(ctx context.Context, target *querypb.Target, sql string, bindVariables map[string]interface{}, options *querypb.ExecuteOptions) (*sqltypes.Result, int64, error)

BeginExecute combines Begin and Execute.

func (*FakeQueryService) BeginExecuteBatch

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

BeginExecuteBatch combines Begin and ExecuteBatch.

func (*FakeQueryService) Close

func (f *FakeQueryService) Close(ctx context.Context) error

Close is a no-op.

func (*FakeQueryService) Commit

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

Commit is part of the queryservice.QueryService interface

func (*FakeQueryService) CommitPrepared

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

CommitPrepared is part of the queryservice.QueryService interface

func (*FakeQueryService) ConcludeTransaction

func (f *FakeQueryService) ConcludeTransaction(ctx context.Context, target *querypb.Target, dtid string) (err error)

ConcludeTransaction is part of the queryservice.QueryService interface

func (*FakeQueryService) CreateTransaction

func (f *FakeQueryService) CreateTransaction(ctx context.Context, target *querypb.Target, dtid string, participants []*querypb.Target) (err error)

CreateTransaction is part of the queryservice.QueryService interface

func (*FakeQueryService) Execute

func (f *FakeQueryService) Execute(ctx context.Context, target *querypb.Target, sql string, bindVariables map[string]interface{}, transactionID int64, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

Execute is part of the queryservice.QueryService interface

func (*FakeQueryService) ExecuteBatch

func (f *FakeQueryService) 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.QueryService interface

func (*FakeQueryService) HandlePanic

func (f *FakeQueryService) HandlePanic(err *error)

HandlePanic is part of the queryservice.QueryService interface

func (*FakeQueryService) MessageAck

func (f *FakeQueryService) MessageAck(ctx context.Context, target *querypb.Target, name string, ids []*querypb.Value) (count int64, err error)

MessageAck is part of the queryservice.QueryService interface

func (*FakeQueryService) MessageStream

func (f *FakeQueryService) MessageStream(ctx context.Context, target *querypb.Target, name string, callback func(*sqltypes.Result) error) (err error)

MessageStream is part of the queryservice.QueryService interface

func (*FakeQueryService) Prepare

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

Prepare is part of the queryservice.QueryService interface

func (*FakeQueryService) ReadTransaction

func (f *FakeQueryService) ReadTransaction(ctx context.Context, target *querypb.Target, dtid string) (metadata *querypb.TransactionMetadata, err error)

ReadTransaction is part of the queryservice.QueryService interface

func (*FakeQueryService) Rollback

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

Rollback is part of the queryservice.QueryService interface

func (*FakeQueryService) RollbackPrepared

func (f *FakeQueryService) RollbackPrepared(ctx context.Context, target *querypb.Target, dtid string, originalID int64) (err error)

RollbackPrepared is part of the queryservice.QueryService interface

func (*FakeQueryService) SetRollback

func (f *FakeQueryService) SetRollback(ctx context.Context, target *querypb.Target, dtid string, transactionID int64) (err error)

SetRollback is part of the queryservice.QueryService interface

func (*FakeQueryService) SplitQuery

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

SplitQuery is part of the queryservice.QueryService interface

func (*FakeQueryService) StartCommit

func (f *FakeQueryService) StartCommit(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error)

StartCommit is part of the queryservice.QueryService interface

func (*FakeQueryService) StreamExecute

func (f *FakeQueryService) StreamExecute(ctx context.Context, target *querypb.Target, sql string, bindVariables map[string]interface{}, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) error

StreamExecute is part of the queryservice.QueryService interface

func (*FakeQueryService) StreamHealth

func (f *FakeQueryService) StreamHealth(ctx context.Context, callback func(*querypb.StreamHealthResponse) error) error

StreamHealth is part of the queryservice.QueryService interface

func (*FakeQueryService) UpdateStream

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

UpdateStream is part of the queryservice.QueryService interface

Jump to

Keyboard shortcuts

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