Skip to content

Commit 1be6374

Browse files
committed
fix comments: dont forget to squash
1 parent 4b9b201 commit 1be6374

13 files changed

+236
-659
lines changed

connection.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
9797
log.Printf("tarantool: last reconnect to %s failed: %s, giving it up",
9898
conn.Addr(), err)
9999
case LogUnexpectedResultId:
100-
resp := v[0].(*ConnResponse)
100+
respHeader := v[0].(header)
101101
log.Printf("tarantool: connection %s got unexpected resultId (%d) in response",
102-
conn.Addr(), resp.requestId)
102+
conn.Addr(), respHeader.requestId)
103103
case LogWatchEventReadFailed:
104104
err := v[0].(error)
105105
log.Printf("tarantool: unable to parse watch event: %s", err)
@@ -808,7 +808,7 @@ func (conn *Connection) reader(r io.Reader, c Conn) {
808808
return
809809
}
810810
resp := &ConnResponse{buf: smallBuf{b: respBytes}}
811-
err = resp.decodeHeader(conn.dec)
811+
respHeader, err := decodeHeader(conn.dec, &resp.buf)
812812
if err != nil {
813813
err = ClientError{
814814
ErrProtocolError,
@@ -818,8 +818,9 @@ func (conn *Connection) reader(r io.Reader, c Conn) {
818818
return
819819
}
820820

821+
resp.respHeader = respHeader
821822
var fut *Future = nil
822-
if iproto.Type(resp.code) == iproto.IPROTO_EVENT {
823+
if iproto.Type(respHeader.code) == iproto.IPROTO_EVENT {
823824
if event, err := readWatchEvent(&resp.buf); err == nil {
824825
events <- event
825826
} else {
@@ -830,19 +831,19 @@ func (conn *Connection) reader(r io.Reader, c Conn) {
830831
conn.opts.Logger.Report(LogWatchEventReadFailed, conn, err)
831832
}
832833
continue
833-
} else if resp.code == PushCode {
834-
if fut = conn.peekFuture(resp.requestId); fut != nil {
834+
} else if respHeader.code == PushCode {
835+
if fut = conn.peekFuture(respHeader.requestId); fut != nil {
835836
fut.AppendPush(resp)
836837
}
837838
} else {
838-
if fut = conn.fetchFuture(resp.requestId); fut != nil {
839+
if fut = conn.fetchFuture(respHeader.requestId); fut != nil {
839840
fut.SetResponse(resp)
840841
conn.markDone(fut)
841842
}
842843
}
843844

844845
if fut == nil {
845-
conn.opts.Logger.Report(LogUnexpectedResultId, conn, resp)
846+
conn.opts.Logger.Report(LogUnexpectedResultId, conn, respHeader)
846847
}
847848
}
848849
}
@@ -1052,10 +1053,7 @@ func (conn *Connection) putFuture(fut *Future, req Request, streamId uint64) {
10521053

10531054
if req.Async() {
10541055
if fut = conn.fetchFuture(reqid); fut != nil {
1055-
resp := &ConnResponse{
1056-
requestId: reqid,
1057-
code: OkCode,
1058-
}
1056+
resp := &ConnResponse{}
10591057
fut.SetResponse(resp)
10601058
conn.markDone(fut)
10611059
}

crud/tarantool_test.go

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -527,22 +527,13 @@ func testSelectGeneratedData(t *testing.T, conn tarantool.Connector,
527527
}
528528

529529
func testCrudRequestCheck(t *testing.T, req tarantool.Request,
530-
resp tarantool.Response, err error, expectedLen int) {
530+
data []interface{}, err error, expectedLen int) {
531531
t.Helper()
532532

533533
if err != nil {
534534
t.Fatalf("Failed to Do CRUD request: %s", err.Error())
535535
}
536536

537-
if resp == nil {
538-
t.Fatalf("Response is nil after Do CRUD request")
539-
}
540-
541-
data, err := resp.Decode()
542-
if err != nil {
543-
t.Fatalf("Failed to Decode: %s", err.Error())
544-
}
545-
546537
if len(data) < expectedLen {
547538
t.Fatalf("Response Body len < %#v, actual len %#v",
548539
expectedLen, len(data))
@@ -571,8 +562,8 @@ func TestCrudGenerateData(t *testing.T) {
571562
conn.Do(req).Get()
572563
}
573564

574-
resp, err := conn.Do(testCase.req).GetResponse()
575-
testCrudRequestCheck(t, testCase.req, resp,
565+
data, err := conn.Do(testCase.req).Get()
566+
testCrudRequestCheck(t, testCase.req, data,
576567
err, testCase.expectedRespLen)
577568

578569
testSelectGeneratedData(t, conn, testCase.expectedTuplesCount)
@@ -593,8 +584,8 @@ func TestCrudProcessData(t *testing.T) {
593584
for _, testCase := range testProcessDataCases {
594585
t.Run(testCase.name, func(t *testing.T) {
595586
testCrudRequestPrepareData(t, conn)
596-
resp, err := conn.Do(testCase.req).GetResponse()
597-
testCrudRequestCheck(t, testCase.req, resp,
587+
data, err := conn.Do(testCase.req).Get()
588+
testCrudRequestCheck(t, testCase.req, data,
598589
err, testCase.expectedRespLen)
599590
for i := 1010; i < 1020; i++ {
600591
req := tarantool.NewDeleteRequest(spaceName).
@@ -625,8 +616,8 @@ func TestCrudUpdateSplice(t *testing.T) {
625616
Opts(simpleOperationOpts)
626617

627618
testCrudRequestPrepareData(t, conn)
628-
resp, err := conn.Do(req).GetResponse()
629-
testCrudRequestCheck(t, req, resp,
619+
data, err := conn.Do(req).Get()
620+
testCrudRequestCheck(t, req, data,
630621
err, 2)
631622
}
632623

@@ -650,8 +641,8 @@ func TestCrudUpsertSplice(t *testing.T) {
650641
Opts(simpleOperationOpts)
651642

652643
testCrudRequestPrepareData(t, conn)
653-
resp, err := conn.Do(req).GetResponse()
654-
testCrudRequestCheck(t, req, resp,
644+
data, err := conn.Do(req).Get()
645+
testCrudRequestCheck(t, req, data,
655646
err, 2)
656647
}
657648

@@ -675,8 +666,8 @@ func TestCrudUpsertObjectSplice(t *testing.T) {
675666
Opts(simpleOperationOpts)
676667

677668
testCrudRequestPrepareData(t, conn)
678-
resp, err := conn.Do(req).GetResponse()
679-
testCrudRequestCheck(t, req, resp,
669+
data, err := conn.Do(req).Get()
670+
testCrudRequestCheck(t, req, data,
680671
err, 2)
681672
}
682673

@@ -721,13 +712,8 @@ func TestUnflattenRows(t *testing.T) {
721712
req := crud.MakeReplaceRequest(spaceName).
722713
Tuple(tuple).
723714
Opts(simpleOperationOpts)
724-
resp, err := conn.Do(req).GetResponse()
725-
testCrudRequestCheck(t, req, resp, err, 2)
726-
727-
data, err := resp.Decode()
728-
if err != nil {
729-
t.Fatalf("Failed to Decode: %s", err.Error())
730-
}
715+
data, err := conn.Do(req).Get()
716+
testCrudRequestCheck(t, req, data, err, 2)
731717

732718
if res, ok = data[0].(map[interface{}]interface{}); !ok {
733719
t.Fatalf("Unexpected CRUD result: %#v", data[0])

dial.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,10 @@ func readResponse(r io.Reader) (Response, error) {
515515
}
516516

517517
resp := &ConnResponse{buf: smallBuf{b: respBytes}}
518-
err = resp.decodeHeader(msgpack.NewDecoder(&smallBuf{}))
518+
respHeader, err := decodeHeader(msgpack.NewDecoder(&smallBuf{}), &resp.buf)
519519
if err != nil {
520520
return resp, fmt.Errorf("decode response header error: %w", err)
521521
}
522+
resp.respHeader = respHeader
522523
return resp, nil
523524
}

dial_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,8 @@ func TestConn_ReadWrite(t *testing.T) {
303303
0x80, // Empty map.
304304
}, dialer.conn.writebuf.Bytes())
305305

306-
resp, err := fut.GetResponse()
306+
_, err := fut.Get()
307307
assert.Nil(t, err)
308-
assert.NotNil(t, resp)
309308
}
310309

311310
func TestConn_ContextCancel(t *testing.T) {

example_test.go

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ func ExamplePingRequest_Context() {
179179
req := tarantool.NewPingRequest().Context(ctx)
180180

181181
// Ping a Tarantool instance to check connection.
182-
resp, err := conn.Do(req).GetResponse()
183-
fmt.Println("Ping Resp", resp)
182+
data, err := conn.Do(req).Get()
183+
fmt.Println("Ping Resp data", data)
184184
fmt.Println("Ping Error", err)
185185
// Output:
186-
// Ping Resp <nil>
186+
// Ping Resp data []
187187
// Ping Error context is done
188188
}
189189

@@ -701,7 +701,6 @@ func getTestTxnDialer() tarantool.Dialer {
701701

702702
func ExampleCommitRequest() {
703703
var req tarantool.Request
704-
var resp tarantool.Response
705704
var err error
706705

707706
// Tarantool supports streams and interactive transactions since version 2.10.0
@@ -718,22 +717,22 @@ func ExampleCommitRequest() {
718717

719718
// Begin transaction
720719
req = tarantool.NewBeginRequest()
721-
resp, err = stream.Do(req).GetResponse()
720+
data, err := stream.Do(req).Get()
722721
if err != nil {
723722
fmt.Printf("Failed to Begin: %s", err.Error())
724723
return
725724
}
726-
fmt.Printf("Begin transaction: response is %#v\n", resp)
725+
fmt.Printf("Begin transaction: response is %#v\n", data)
727726

728727
// Insert in stream
729728
req = tarantool.NewInsertRequest(spaceName).
730729
Tuple([]interface{}{uint(1001), "commit_hello", "commit_world"})
731-
resp, err = stream.Do(req).GetResponse()
730+
data, err = stream.Do(req).Get()
732731
if err != nil {
733732
fmt.Printf("Failed to Insert: %s", err.Error())
734733
return
735734
}
736-
fmt.Printf("Insert in stream: response is %#v\n", resp)
735+
fmt.Printf("Insert in stream: response is %#v\n", data)
737736

738737
// Select not related to the transaction
739738
// while transaction is not committed
@@ -743,7 +742,7 @@ func ExampleCommitRequest() {
743742
Limit(1).
744743
Iterator(tarantool.IterEq).
745744
Key([]interface{}{uint(1001)})
746-
data, err := conn.Do(selectReq).Get()
745+
data, err = conn.Do(selectReq).Get()
747746
if err != nil {
748747
fmt.Printf("Failed to Select: %s", err.Error())
749748
return
@@ -760,12 +759,12 @@ func ExampleCommitRequest() {
760759

761760
// Commit transaction
762761
req = tarantool.NewCommitRequest()
763-
resp, err = stream.Do(req).GetResponse()
762+
data, err = stream.Do(req).Get()
764763
if err != nil {
765764
fmt.Printf("Failed to Commit: %s", err.Error())
766765
return
767766
}
768-
fmt.Printf("Commit transaction: response is %#v\n", resp)
767+
fmt.Printf("Commit transaction: response is %#v\n", data)
769768

770769
// Select outside of transaction
771770
data, err = conn.Do(selectReq).Get()
@@ -778,7 +777,6 @@ func ExampleCommitRequest() {
778777

779778
func ExampleRollbackRequest() {
780779
var req tarantool.Request
781-
var resp tarantool.Response
782780
var err error
783781

784782
// Tarantool supports streams and interactive transactions since version 2.10.0
@@ -795,22 +793,22 @@ func ExampleRollbackRequest() {
795793

796794
// Begin transaction
797795
req = tarantool.NewBeginRequest()
798-
resp, err = stream.Do(req).GetResponse()
796+
data, err := stream.Do(req).Get()
799797
if err != nil {
800798
fmt.Printf("Failed to Begin: %s", err.Error())
801799
return
802800
}
803-
fmt.Printf("Begin transaction: response is %#v\n", resp)
801+
fmt.Printf("Begin transaction: response is %#v\n", data)
804802

805803
// Insert in stream
806804
req = tarantool.NewInsertRequest(spaceName).
807805
Tuple([]interface{}{uint(2001), "rollback_hello", "rollback_world"})
808-
resp, err = stream.Do(req).GetResponse()
806+
data, err = stream.Do(req).Get()
809807
if err != nil {
810808
fmt.Printf("Failed to Insert: %s", err.Error())
811809
return
812810
}
813-
fmt.Printf("Insert in stream: response is %#v\n", resp)
811+
fmt.Printf("Insert in stream: response is %#v\n", data)
814812

815813
// Select not related to the transaction
816814
// while transaction is not committed
@@ -820,7 +818,7 @@ func ExampleRollbackRequest() {
820818
Limit(1).
821819
Iterator(tarantool.IterEq).
822820
Key([]interface{}{uint(2001)})
823-
data, err := conn.Do(selectReq).Get()
821+
data, err = conn.Do(selectReq).Get()
824822
if err != nil {
825823
fmt.Printf("Failed to Select: %s", err.Error())
826824
return
@@ -837,12 +835,12 @@ func ExampleRollbackRequest() {
837835

838836
// Rollback transaction
839837
req = tarantool.NewRollbackRequest()
840-
resp, err = stream.Do(req).GetResponse()
838+
data, err = stream.Do(req).Get()
841839
if err != nil {
842840
fmt.Printf("Failed to Rollback: %s", err.Error())
843841
return
844842
}
845-
fmt.Printf("Rollback transaction: response is %#v\n", resp)
843+
fmt.Printf("Rollback transaction: response is %#v\n", data)
846844

847845
// Select outside of transaction
848846
data, err = conn.Do(selectReq).Get()
@@ -855,7 +853,6 @@ func ExampleRollbackRequest() {
855853

856854
func ExampleBeginRequest_TxnIsolation() {
857855
var req tarantool.Request
858-
var resp tarantool.Response
859856
var err error
860857

861858
// Tarantool supports streams and interactive transactions since version 2.10.0
@@ -874,22 +871,22 @@ func ExampleBeginRequest_TxnIsolation() {
874871
req = tarantool.NewBeginRequest().
875872
TxnIsolation(tarantool.ReadConfirmedLevel).
876873
Timeout(500 * time.Millisecond)
877-
resp, err = stream.Do(req).GetResponse()
874+
data, err := stream.Do(req).Get()
878875
if err != nil {
879876
fmt.Printf("Failed to Begin: %s", err.Error())
880877
return
881878
}
882-
fmt.Printf("Begin transaction: response is %#v\n", resp)
879+
fmt.Printf("Begin transaction: response is %#v\n", data)
883880

884881
// Insert in stream
885882
req = tarantool.NewInsertRequest(spaceName).
886883
Tuple([]interface{}{uint(2001), "rollback_hello", "rollback_world"})
887-
resp, err = stream.Do(req).GetResponse()
884+
data, err = stream.Do(req).Get()
888885
if err != nil {
889886
fmt.Printf("Failed to Insert: %s", err.Error())
890887
return
891888
}
892-
fmt.Printf("Insert in stream: response is %#v\n", resp)
889+
fmt.Printf("Insert in stream: response is %#v\n", data)
893890

894891
// Select not related to the transaction
895892
// while transaction is not committed
@@ -899,7 +896,7 @@ func ExampleBeginRequest_TxnIsolation() {
899896
Limit(1).
900897
Iterator(tarantool.IterEq).
901898
Key([]interface{}{uint(2001)})
902-
data, err := conn.Do(selectReq).Get()
899+
data, err = conn.Do(selectReq).Get()
903900
if err != nil {
904901
fmt.Printf("Failed to Select: %s", err.Error())
905902
return
@@ -916,12 +913,12 @@ func ExampleBeginRequest_TxnIsolation() {
916913

917914
// Rollback transaction
918915
req = tarantool.NewRollbackRequest()
919-
resp, err = stream.Do(req).GetResponse()
916+
data, err = stream.Do(req).Get()
920917
if err != nil {
921918
fmt.Printf("Failed to Rollback: %s", err.Error())
922919
return
923920
}
924-
fmt.Printf("Rollback transaction: response is %#v\n", resp)
921+
fmt.Printf("Rollback transaction: response is %#v\n", data)
925922

926923
// Select outside of transaction
927924
data, err = conn.Do(selectReq).Get()
@@ -1257,12 +1254,12 @@ func ExampleConnection_CloseGraceful_force() {
12571254
<-done
12581255

12591256
fmt.Println("Result:")
1260-
fmt.Println(fut.GetResponse())
1257+
fmt.Println(fut.Get())
12611258
// Output:
12621259
// Force Connection.Close()!
12631260
// Connection.CloseGraceful() done!
12641261
// Result:
1265-
// <nil> connection closed by client (0x4001)
1262+
// [] connection closed by client (0x4001)
12661263
}
12671264

12681265
func ExampleWatchOnceRequest() {

0 commit comments

Comments
 (0)