本文整理汇总了Golang中github.com/youtube/vitess/go/vt/tabletserver/proto.Query.TransactionId方法的典型用法代码示例。如果您正苦于以下问题:Golang Query.TransactionId方法的具体用法?Golang Query.TransactionId怎么用?Golang Query.TransactionId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/tabletserver/proto.Query
的用法示例。
在下文中一共展示了Query.TransactionId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestTabletServerStreamExecute
func TestTabletServerStreamExecute(t *testing.T) {
db := setUpTabletServerTest()
testUtils := newTestUtils()
// sql that will be executed in this test
executeSQL := "select * from test_table limit 1000"
executeSQLResult := &sqltypes.Result{
RowsAffected: 1,
Rows: [][]sqltypes.Value{
[]sqltypes.Value{sqltypes.MakeString([]byte("row01"))},
},
}
db.AddQuery(executeSQL, executeSQLResult)
config := testUtils.newQueryServiceConfig()
tsv := NewTabletServer(config)
dbconfigs := testUtils.newDBConfigs(db)
target := querypb.Target{TabletType: topodatapb.TabletType_MASTER}
err := tsv.StartService(target, dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
if err != nil {
t.Fatalf("StartService failed: %v", err)
}
defer tsv.StopService()
ctx := context.Background()
session := proto.Session{
SessionId: tsv.sessionID,
TransactionId: 0,
}
txInfo := proto.TransactionInfo{TransactionId: 0}
if err = tsv.Begin(ctx, nil, &session, &txInfo); err != nil {
t.Fatalf("call TabletServer.Begin failed")
}
session.TransactionId = txInfo.TransactionId
query := proto.Query{
Sql: executeSQL,
BindVariables: nil,
SessionId: session.SessionId,
TransactionId: session.TransactionId,
}
sendReply := func(*sqltypes.Result) error { return nil }
if err := tsv.StreamExecute(ctx, nil, &query, sendReply); err == nil {
t.Fatalf("TabletServer.StreamExecute should fail: %s", query.Sql)
}
if err := tsv.Rollback(ctx, nil, &session); err != nil {
t.Fatalf("call TabletServer.Rollback failed")
}
query.TransactionId = 0
if err := tsv.StreamExecute(ctx, nil, &query, sendReply); err != nil {
t.Fatalf("TabletServer.StreamExecute should success: %s, but get error: %v",
query.Sql, err)
}
}
示例2: TestSqlQueryStreamExecute
func TestSqlQueryStreamExecute(t *testing.T) {
db := setUpSQLQueryTest()
testUtils := newTestUtils()
// sql that will be executed in this test
executeSQL := "select * from test_table limit 1000"
executeSQLResult := &mproto.QueryResult{
RowsAffected: 1,
Rows: [][]sqltypes.Value{
[]sqltypes.Value{sqltypes.MakeString([]byte("row01"))},
},
}
db.AddQuery(executeSQL, executeSQLResult)
config := testUtils.newQueryServiceConfig()
sqlQuery := NewSqlQuery(config)
dbconfigs := testUtils.newDBConfigs()
err := sqlQuery.allowQueries(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
if err != nil {
t.Fatalf("allowQueries failed: %v", err)
}
defer sqlQuery.disallowQueries()
ctx := context.Background()
session := proto.Session{
SessionId: sqlQuery.sessionID,
TransactionId: 0,
}
txInfo := proto.TransactionInfo{TransactionId: 0}
if err = sqlQuery.Begin(ctx, nil, &session, &txInfo); err != nil {
t.Fatalf("call SqlQuery.Begin failed")
}
session.TransactionId = txInfo.TransactionId
query := proto.Query{
Sql: executeSQL,
BindVariables: nil,
SessionId: session.SessionId,
TransactionId: session.TransactionId,
}
sendReply := func(*mproto.QueryResult) error { return nil }
if err := sqlQuery.StreamExecute(ctx, nil, &query, sendReply); err == nil {
t.Fatalf("SqlQuery.StreamExecute should fail: %s", query.Sql)
}
if err := sqlQuery.Rollback(ctx, nil, &session); err != nil {
t.Fatalf("call SqlQuery.Rollback failed")
}
query.TransactionId = 0
if err := sqlQuery.StreamExecute(ctx, nil, &query, sendReply); err != nil {
t.Fatalf("SqlQuery.StreamExecute should success: %s, but get error: %v",
query.Sql, err)
}
}