本文整理汇总了Golang中github.com/youtube/vitess/go/vt/tabletserver/tabletconn.TabletConn.StreamExecute2方法的典型用法代码示例。如果您正苦于以下问题:Golang TabletConn.StreamExecute2方法的具体用法?Golang TabletConn.StreamExecute2怎么用?Golang TabletConn.StreamExecute2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/tabletserver/tabletconn.TabletConn
的用法示例。
在下文中一共展示了TabletConn.StreamExecute2方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testStreamExecute2Error
func testStreamExecute2Error(t *testing.T, conn tabletconn.TabletConn, fake *FakeQueryService) {
t.Log("testStreamExecute2Error")
ctx := context.Background()
stream, errFunc, err := conn.StreamExecute2(ctx, streamExecuteQuery, streamExecuteBindVars, streamExecuteTransactionID)
if err != nil {
t.Fatalf("StreamExecute2 failed: %v", err)
}
qr, ok := <-stream
if !ok {
t.Fatalf("StreamExecute2 failed: cannot read result1")
}
if len(qr.Rows) == 0 {
qr.Rows = nil
}
if !reflect.DeepEqual(*qr, streamExecuteQueryResult1) {
t.Errorf("Unexpected result1 from StreamExecute2: got %v wanted %v", qr, streamExecuteQueryResult1)
}
// signal to the server that the first result has been received
close(fake.errorWait)
// After 1 result, we expect to get an error (no more results).
qr, ok = <-stream
if ok {
t.Fatalf("StreamExecute2 channel wasn't closed")
}
err = errFunc()
verifyError(t, err, "StreamExecute2")
}
示例2: testStreamExecute2
func testStreamExecute2(t *testing.T, conn tabletconn.TabletConn) {
t.Log("testStreamExecute2")
ctx := context.Background()
stream, errFunc, err := conn.StreamExecute2(ctx, streamExecuteQuery, streamExecuteBindVars, streamExecuteTransactionID)
if err != nil {
t.Fatalf("StreamExecute2 failed: %v", err)
}
qr, ok := <-stream
if !ok {
t.Fatalf("StreamExecute2 failed: cannot read result1")
}
if len(qr.Rows) == 0 {
qr.Rows = nil
}
if !reflect.DeepEqual(*qr, streamExecuteQueryResult1) {
t.Errorf("Unexpected result1 from StreamExecute2: got %v wanted %v", qr, streamExecuteQueryResult1)
}
qr, ok = <-stream
if !ok {
t.Fatalf("StreamExecute2 failed: cannot read result2")
}
if len(qr.Fields) == 0 {
qr.Fields = nil
}
if !reflect.DeepEqual(*qr, streamExecuteQueryResult2) {
t.Errorf("Unexpected result2 from StreamExecute2: got %v wanted %v", qr, streamExecuteQueryResult2)
}
qr, ok = <-stream
if ok {
t.Fatalf("StreamExecute2 channel wasn't closed")
}
if err := errFunc(); err != nil {
t.Fatalf("StreamExecute2 errFunc failed: %v", err)
}
}
示例3: testStreamExecute2Error
func testStreamExecute2Error(t *testing.T, conn tabletconn.TabletConn) {
t.Log("testStreamExecute2Error")
ctx := context.Background()
stream, errFunc, err := conn.StreamExecute2(ctx, streamExecuteQuery, streamExecuteBindVars, streamExecuteTransactionID)
if err != nil {
t.Fatalf("StreamExecute2 failed: %v", err)
}
qr, ok := <-stream
if !ok {
t.Fatalf("StreamExecute2 failed: cannot read result1")
}
if len(qr.Rows) == 0 {
qr.Rows = nil
}
if !reflect.DeepEqual(*qr, streamExecuteQueryResult1) {
t.Errorf("Unexpected result1 from StreamExecute2: got %v wanted %v", qr, streamExecuteQueryResult1)
}
// signal to the server that the first result has been received
close(errorWait)
// After 1 result, we expect to get an error (no more results).
qr, ok = <-stream
if ok {
t.Fatalf("StreamExecute2 channel wasn't closed")
}
err = errFunc()
if err == nil {
t.Fatalf("StreamExecute2 was expecting an error, didn't get one")
}
if !strings.Contains(err.Error(), expectedErrMatch) {
t.Errorf("Unexpected error from StreamExecute2: got %v, wanted err containing %v", err, expectedErrMatch)
}
// reset state for the test
errorWait = make(chan struct{})
}
示例4: testStreamExecute2Panics
func testStreamExecute2Panics(t *testing.T, conn tabletconn.TabletConn, fake *FakeQueryService) {
t.Log("testStreamExecute2Panics")
// early panic is before sending the Fields, that is returned
// by the StreamExecute2 call itself, or as the first error
// by ErrFunc
ctx := context.Background()
fake.streamExecutePanicsEarly = true
stream, errFunc, err := conn.StreamExecute2(ctx, streamExecuteQuery, streamExecuteBindVars, streamExecuteTransactionID)
if err != nil {
if !strings.Contains(err.Error(), "caught test panic") {
t.Fatalf("unexpected panic error: %v", err)
}
} else {
_, ok := <-stream
if ok {
t.Fatalf("StreamExecute early panic should not return anything")
}
err = errFunc()
if err == nil || !strings.Contains(err.Error(), "caught test panic") {
t.Fatalf("unexpected panic error: %v", err)
}
}
// late panic is after sending Fields
fake.streamExecutePanicsEarly = false
stream, errFunc, err = conn.StreamExecute2(ctx, streamExecuteQuery, streamExecuteBindVars, streamExecuteTransactionID)
if err != nil {
t.Fatalf("StreamExecute2 failed: %v", err)
}
qr, ok := <-stream
if !ok {
t.Fatalf("StreamExecute2 failed: cannot read result1")
}
if len(qr.Rows) == 0 {
qr.Rows = nil
}
if !reflect.DeepEqual(*qr, streamExecuteQueryResult1) {
t.Errorf("Unexpected result1 from StreamExecute2: got %v wanted %v", qr, streamExecuteQueryResult1)
}
close(panicWait)
if _, ok := <-stream; ok {
t.Fatalf("StreamExecute2 returned more results")
}
if err := errFunc(); err == nil || !strings.Contains(err.Error(), "caught test panic") {
t.Fatalf("unexpected panic error: %v", err)
}
// Make a new panicWait channel, to reset the state to the beginning of the test
panicWait = make(chan struct{})
}