tabletconntest

package
v0.20.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: Apache-2.0 Imports: 23 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 Dtid string = "aa"

Dtid is a test dtid

View Source
const ExecuteBatchTransactionID int64 = 678

ExecuteBatchTransactionID is a test transaction id for batch.

View Source
const ExecuteQuery = "executeQuery"

ExecuteQuery is a fake test query.

View Source
const ExecuteTransactionID int64 = 678

ExecuteTransactionID is a test transaction id.

View Source
const ReserveConnectionID int64 = 933

ReserveConnectionID is a test reserved connection id.

View Source
const StreamExecuteQuery = "streamExecuteQuery"

StreamExecuteQuery is a fake test query for streaming.

View Source
const TestAsTransaction bool = true

TestAsTransaction is a test 'asTransaction' flag.

Variables

View Source
var (
	// MessageName is a test message name.
	MessageName = "vitess_message"

	// MessageStreamResult is a test stream result.
	MessageStreamResult = &sqltypes.Result{
		Fields: []*querypb.Field{{
			Name: "id",
			Type: sqltypes.VarBinary,
		}, {
			Name: "message",
			Type: sqltypes.VarBinary,
		}},
		Rows: [][]sqltypes.Value{{
			sqltypes.NewVarBinary("1"),
			sqltypes.NewVarBinary("row1 value2"),
		}, {
			sqltypes.NewVarBinary("2"),
			sqltypes.NewVarBinary("row2 value2"),
		}},
	}

	// MessageIDs is a test list of message ids.
	MessageIDs = []*querypb.Value{{
		Type:  sqltypes.VarChar,
		Value: []byte("1"),
	}}
)
View Source
var ExecuteBatchQueries = []*querypb.BoundQuery{
	{
		Sql: "executeBatchQueries1",
		BindVariables: map[string]*querypb.BindVariable{
			"bind1": sqltypes.Int64BindVariable(43),
		},
	},
	{
		Sql: "executeBatchQueries2",
		BindVariables: map[string]*querypb.BindVariable{
			"bind2": sqltypes.Int64BindVariable(72),
		},
	},
}

ExecuteBatchQueries are test queries for batch.

View Source
var ExecuteBatchQueryResultList = []sqltypes.Result{
	{
		Fields: []*querypb.Field{
			{
				Name: "field1",
				Type: sqltypes.Int8,
			},
		},
		RowsAffected: 1232,
		InsertID:     712,
		Rows: [][]sqltypes.Value{
			{
				sqltypes.TestValue(sqltypes.Int8, "1"),
			},
			{
				sqltypes.TestValue(sqltypes.Int8, "2"),
			},
		},
	},
	{
		Fields: []*querypb.Field{
			{
				Name: "field1",
				Type: sqltypes.VarBinary,
			},
		},
		RowsAffected: 12333,
		InsertID:     74442,
		Rows: [][]sqltypes.Value{
			{
				sqltypes.NewVarBinary("row1 value1"),
			},
			{
				sqltypes.NewVarBinary("row1 value2"),
			},
		},
	},
}

ExecuteBatchQueryResultList is a list of test query results.

View Source
var ExecuteBindVars = map[string]*querypb.BindVariable{
	"bind1": sqltypes.Int64BindVariable(1114444),
}

ExecuteBindVars is a test bind var.

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.TestValue(sqltypes.Int8, "1"),
			sqltypes.NULL,
		},
		{
			sqltypes.TestValue(sqltypes.Int8, "2"),
			sqltypes.TestValue(sqltypes.Char, "row2 value2"),
		},
	},
}

ExecuteQueryResult is a test query result.

Metadata is a test metadata for 2pc transactions.

View Source
var Participants = []*querypb.Target{{
	Keyspace: "ks0",
	Shard:    "0",
}, {
	Keyspace: "ks1",
	Shard:    "1",
}}

Participants is a test list of 2pc participants.

View Source
var StreamExecuteBindVars = map[string]*querypb.BindVariable{
	"bind1": sqltypes.Int64BindVariable(93848000),
}

StreamExecuteBindVars is a test bind var for streaming.

View Source
var StreamExecuteQueryResult1 = sqltypes.Result{
	Fields: []*querypb.Field{
		{
			Name: "field1",
			Type: sqltypes.Int8,
		},
		{
			Name: "field2",
			Type: sqltypes.Char,
		},
	},
}

StreamExecuteQueryResult1 is the first packet of a streaming result.

View Source
var StreamExecuteQueryResult2 = sqltypes.Result{
	Rows: [][]sqltypes.Value{
		{
			sqltypes.TestValue(sqltypes.Int8, "1"),
			sqltypes.TestValue(sqltypes.Char, "row1 value2"),
		},
		{
			sqltypes.TestValue(sqltypes.Int8, "2"),
			sqltypes.TestValue(sqltypes.Char, "row2 value2"),
		},
	},
}

StreamExecuteQueryResult2 is the second packet of a streaming result.

View Source
var TestAlias = &topodatapb.TabletAlias{
	Cell: TestCell,
	Uid:  1,
}

TestAlias is the tablet alias we use for this test (and TestGRPCDiscovery)

View Source
var TestCallerID = &vtrpcpb.CallerID{
	Principal:    "test_principal",
	Component:    "test_component",
	Subcomponent: "test_subcomponent",
}

TestCallerID is a test caller id.

View Source
var TestCell = "aa"

TestCell is the cell we use for this test (and TestGRPCDiscovery)

View Source
var TestExecuteOptions = &querypb.ExecuteOptions{
	IncludedFields:  querypb.ExecuteOptions_TYPE_ONLY,
	ClientFoundRows: true,
}

TestExecuteOptions is a test execute options.

View Source
var TestStreamHealthErrorMsg = "to trigger a server error"

TestStreamHealthErrorMsg is a test error message for health streaming.

View Source
var TestStreamHealthStreamHealthResponse = &querypb.StreamHealthResponse{
	Target: &querypb.Target{
		Keyspace:   "test_keyspace",
		Shard:      "test_shard",
		TabletType: topodatapb.TabletType_RDONLY,
	},
	Serving: true,

	PrimaryTermStartTimestamp: 1234589,

	RealtimeStats: &querypb.RealtimeStats{
		CpuUsage:                      1.0,
		HealthError:                   "random error",
		ReplicationLagSeconds:         234,
		BinlogPlayersCount:            1,
		FilteredReplicationLagSeconds: 2,
	},
}

TestStreamHealthStreamHealthResponse is a test stream health response.

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",
}

TestVTGateCallerID is a test vtgate caller id.

Functions

func SetProtocol added in v0.15.0

func SetProtocol(name string, protocol string)

SetProtocol is a helper function to set the tabletconn --tablet_protocol flag value for tests.

Note that because this variable is bound to a flag, the effects of this function are global, not scoped to the calling test-case. Therefore it should not be used in conjunction with t.Parallel.

func TargetsEqual

func TargetsEqual(t1, t2 []*querypb.Target) bool

TargetsEqual returns true if the targets are equal.

func TestSuite

func TestSuite(ctx context.Context, t *testing.T, protocol string, tablet *topodatapb.Tablet, fake *FakeQueryService, clientCreds *os.File)

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
	HasReserveError bool
	TabletError     error
	ErrorWait       chan struct{}

	// these fields are used to simulate and synchronize on panics
	Panics                   bool
	StreamExecutePanicsEarly 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.TB) *FakeQueryService

CreateFakeServer returns the fake server for the tests

func (*FakeQueryService) Begin

Begin is part of the queryservice.QueryService interface

func (*FakeQueryService) BeginExecute

func (f *FakeQueryService) BeginExecute(ctx context.Context, target *querypb.Target, _ []string, sql string, bindVariables map[string]*querypb.BindVariable, reservedID int64, options *querypb.ExecuteOptions) (queryservice.TransactionState, *sqltypes.Result, error)

BeginExecute combines Begin and Execute.

func (*FakeQueryService) BeginStreamExecute added in v0.13.0

func (f *FakeQueryService) BeginStreamExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, reservedID int64, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) (queryservice.TransactionState, error)

BeginStreamExecute combines Begin and StreamExecute.

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) (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]*querypb.BindVariable, transactionID, reservedID int64, options *querypb.ExecuteOptions) (*sqltypes.Result, error)

Execute is part of the queryservice.QueryService interface

func (*FakeQueryService) GetSchema added in v0.16.0

func (f *FakeQueryService) GetSchema(ctx context.Context, target *querypb.Target, tableType querypb.SchemaTableType, tableNames []string, callback func(schemaRes *querypb.GetSchemaResponse) error) error

GetSchema implements the QueryService interface

func (*FakeQueryService) GetServingKeyspaces added in v0.18.0

func (f *FakeQueryService) GetServingKeyspaces() []string

GetServingKeyspaces returns list of serving keyspaces.

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

QueryServiceByAlias satisfies the Gateway 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) Release

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

Release implements the QueryService interface

func (*FakeQueryService) ReserveBeginExecute

func (f *FakeQueryService) ReserveBeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, postBeginQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, options *querypb.ExecuteOptions) (queryservice.ReservedTransactionState, *sqltypes.Result, error)

ReserveBeginExecute satisfies the Gateway interface

func (*FakeQueryService) ReserveBeginStreamExecute added in v0.13.0

func (f *FakeQueryService) ReserveBeginStreamExecute(ctx context.Context, target *querypb.Target, preQueries []string, postBeginQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) (queryservice.ReservedTransactionState, error)

ReserveBeginStreamExecute satisfies the Gateway interface

func (*FakeQueryService) ReserveExecute

func (f *FakeQueryService) ReserveExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions) (queryservice.ReservedState, *sqltypes.Result, error)

ReserveExecute implements the QueryService interface

func (*FakeQueryService) ReserveStreamExecute added in v0.13.0

func (f *FakeQueryService) ReserveStreamExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, bindVariables map[string]*querypb.BindVariable, transactionID int64, options *querypb.ExecuteOptions, callback func(*sqltypes.Result) error) (queryservice.ReservedState, error)

ReserveStreamExecute satisfies the Gateway interface

func (*FakeQueryService) Rollback

func (f *FakeQueryService) Rollback(ctx context.Context, target *querypb.Target, transactionID int64) (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) 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]*querypb.BindVariable, transactionID int64, reservedID int64, 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) VStream

func (f *FakeQueryService) VStream(ctx context.Context, request *binlogdatapb.VStreamRequest, send func([]*binlogdatapb.VEvent) error) error

VStream is part of the queryservice.QueryService interface

func (*FakeQueryService) VStreamResults

func (f *FakeQueryService) VStreamResults(ctx context.Context, target *querypb.Target, query string, send func(*binlogdatapb.VStreamResultsResponse) error) error

VStreamResults is part of the QueryService interface.

func (*FakeQueryService) VStreamRows

VStreamRows is part of the QueryService interface.

func (*FakeQueryService) VStreamTables added in v0.18.0

VStreamTables is part of the QueryService interface.

Jump to

Keyboard shortcuts

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