Documentation ¶
Overview ¶
Package tabletconntest provides the test methods to make sure a tabletconn/queryservice pair over RPC works correctly.
Index ¶
- Constants
- Variables
- func TargetsEqual(t1, t2 []*querypb.Target) bool
- func TestSuite(t *testing.T, protocol string, tablet *topodatapb.Tablet, ...)
- type FakeQueryService
- func (f *FakeQueryService) Begin(ctx context.Context, target *querypb.Target, options *querypb.ExecuteOptions) (int64, *topodatapb.TabletAlias, error)
- func (f *FakeQueryService) BeginExecute(ctx context.Context, target *querypb.Target, _ []string, sql string, ...) (*sqltypes.Result, int64, *topodatapb.TabletAlias, error)
- func (f *FakeQueryService) BeginExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, ...) ([]sqltypes.Result, int64, *topodatapb.TabletAlias, error)
- func (f *FakeQueryService) Close(ctx context.Context) error
- func (f *FakeQueryService) Commit(ctx context.Context, target *querypb.Target, transactionID int64) (int64, error)
- func (f *FakeQueryService) CommitPrepared(ctx context.Context, target *querypb.Target, dtid string) (err error)
- func (f *FakeQueryService) ConcludeTransaction(ctx context.Context, target *querypb.Target, dtid string) (err error)
- func (f *FakeQueryService) CreateTransaction(ctx context.Context, target *querypb.Target, dtid string, ...) (err error)
- func (f *FakeQueryService) Execute(ctx context.Context, target *querypb.Target, sql string, ...) (*sqltypes.Result, error)
- func (f *FakeQueryService) ExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, ...) ([]sqltypes.Result, error)
- func (f *FakeQueryService) HandlePanic(err *error)
- func (f *FakeQueryService) MessageAck(ctx context.Context, target *querypb.Target, name string, ids []*querypb.Value) (count int64, err error)
- func (f *FakeQueryService) MessageStream(ctx context.Context, target *querypb.Target, name string, ...) (err error)
- func (f *FakeQueryService) Prepare(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error)
- func (f *FakeQueryService) QueryServiceByAlias(_ *topodatapb.TabletAlias, _ *querypb.Target) (queryservice.QueryService, error)
- func (f *FakeQueryService) ReadTransaction(ctx context.Context, target *querypb.Target, dtid string) (metadata *querypb.TransactionMetadata, err error)
- func (f *FakeQueryService) Release(ctx context.Context, target *querypb.Target, transactionID, reservedID int64) error
- func (f *FakeQueryService) ReserveBeginExecute(ctx context.Context, target *querypb.Target, preQueries []string, ...) (*sqltypes.Result, int64, int64, *topodatapb.TabletAlias, error)
- func (f *FakeQueryService) ReserveExecute(ctx context.Context, target *querypb.Target, preQueries []string, sql string, ...) (*sqltypes.Result, int64, *topodatapb.TabletAlias, error)
- func (f *FakeQueryService) Rollback(ctx context.Context, target *querypb.Target, transactionID int64) (int64, error)
- func (f *FakeQueryService) RollbackPrepared(ctx context.Context, target *querypb.Target, dtid string, originalID int64) (err error)
- func (f *FakeQueryService) SetRollback(ctx context.Context, target *querypb.Target, dtid string, transactionID int64) (err error)
- func (f *FakeQueryService) StartCommit(ctx context.Context, target *querypb.Target, transactionID int64, dtid string) (err error)
- func (f *FakeQueryService) StreamExecute(ctx context.Context, target *querypb.Target, sql string, ...) error
- func (f *FakeQueryService) StreamHealth(ctx context.Context, callback func(*querypb.StreamHealthResponse) error) error
- func (f *FakeQueryService) VStream(ctx context.Context, target *querypb.Target, position string, ...) error
- func (f *FakeQueryService) VStreamResults(ctx context.Context, target *querypb.Target, query string, ...) error
- func (f *FakeQueryService) VStreamRows(ctx context.Context, target *querypb.Target, query string, ...) error
Constants ¶
const Dtid string = "aa"
Dtid is a test dtid
const ExecuteBatchTransactionID int64 = 678
ExecuteBatchTransactionID is a test transaction id for batch.
const ExecuteQuery = "executeQuery"
ExecuteQuery is a fake test query.
const ExecuteTransactionID int64 = 678
ExecuteTransactionID is a test transaction id.
const ReserveConnectionID int64 = 933
ReserveConnectionID is a test reserved connection id.
const StreamExecuteQuery = "streamExecuteQuery"
StreamExecuteQuery is a fake test query for streaming.
const TestAsTransaction bool = true
TestAsTransaction is a test 'asTransaction' flag.
Variables ¶
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"), }} )
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.
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.
var ExecuteBindVars = map[string]*querypb.BindVariable{ "bind1": sqltypes.Int64BindVariable(1114444), }
ExecuteBindVars is a test bind var.
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.
var Metadata = &querypb.TransactionMetadata{ Dtid: "aa", State: querypb.TransactionState_PREPARE, TimeCreated: 1, Participants: Participants, }
Metadata is a test metadata for 2pc transactions.
var Participants = []*querypb.Target{{
Keyspace: "ks0",
Shard: "0",
}, {
Keyspace: "ks1",
Shard: "1",
}}
Participants is a test list of 2pc participants.
var StreamExecuteBindVars = map[string]*querypb.BindVariable{ "bind1": sqltypes.Int64BindVariable(93848000), }
StreamExecuteBindVars is a test bind var for streaming.
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.
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.
var TestAlias = &topodatapb.TabletAlias{ Cell: TestCell, Uid: 1, }
TestAlias is the tablet alias we use for this test (and TestGRPCDiscovery)
var TestCallerID = &vtrpcpb.CallerID{
Principal: "test_principal",
Component: "test_component",
Subcomponent: "test_subcomponent",
}
TestCallerID is a test caller id.
var TestCell = "aa"
TestCell is the cell we use for this test (and TestGRPCDiscovery)
var TestExecuteOptions = &querypb.ExecuteOptions{ IncludedFields: querypb.ExecuteOptions_TYPE_ONLY, ClientFoundRows: true, }
TestExecuteOptions is a test execute options.
var TestStreamHealthErrorMsg = "to trigger a server error"
TestStreamHealthErrorMsg is a test error message for health streaming.
var TestStreamHealthStreamHealthResponse = &querypb.StreamHealthResponse{ Target: &querypb.Target{ Keyspace: "test_keyspace", Shard: "test_shard", TabletType: topodatapb.TabletType_RDONLY, }, Serving: true, TabletExternallyReparentedTimestamp: 1234589, RealtimeStats: &querypb.RealtimeStats{ CpuUsage: 1.0, HealthError: "random error", ReplicationLagSeconds: 234, BinlogPlayersCount: 1, FilteredReplicationLagSeconds: 2, }, }
TestStreamHealthStreamHealthResponse is a test stream health response.
var TestTarget = &querypb.Target{ Keyspace: "test_keyspace", Shard: "test_shard", TabletType: topodatapb.TabletType_REPLICA, }
TestTarget is the target we use for this test
var TestVTGateCallerID = &querypb.VTGateCallerID{
Username: "test_username",
}
TestVTGateCallerID is a test vtgate caller id.
Functions ¶
func TargetsEqual ¶
TargetsEqual returns true if the targets are equal.
func TestSuite ¶
func TestSuite(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 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 ¶
func (f *FakeQueryService) Begin(ctx context.Context, target *querypb.Target, options *querypb.ExecuteOptions) (int64, *topodatapb.TabletAlias, error)
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) (*sqltypes.Result, int64, *topodatapb.TabletAlias, error)
BeginExecute combines Begin and Execute.
func (*FakeQueryService) BeginExecuteBatch ¶
func (f *FakeQueryService) BeginExecuteBatch(ctx context.Context, target *querypb.Target, queries []*querypb.BoundQuery, asTransaction bool, options *querypb.ExecuteOptions) ([]sqltypes.Result, int64, *topodatapb.TabletAlias, 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) (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) ExecuteBatch ¶
func (f *FakeQueryService) 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.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) QueryServiceByAlias ¶
func (f *FakeQueryService) QueryServiceByAlias(_ *topodatapb.TabletAlias, _ *querypb.Target) (queryservice.QueryService, error)
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) (*sqltypes.Result, int64, int64, *topodatapb.TabletAlias, error)
ReserveBeginExecute 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) (*sqltypes.Result, int64, *topodatapb.TabletAlias, error)
ReserveExecute implements the QueryService 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, 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, target *querypb.Target, position string, tablePKs []*binlogdatapb.TableLastPK, filter *binlogdatapb.Filter, 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 ¶
func (f *FakeQueryService) 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.