Skip to content

Commit

Permalink
code-health: update format for Call to 1.7
Browse files Browse the repository at this point in the history
An incompatible change was introduced in
Tarantool 1.7 which was released in 2016.
This change is about a new binary protocol
command for CALL, which no more restricts
a function to returning an array of tuples
and allows returning an arbitrary MsgPack/JSON
result, including scalars, nil and void (nothing).

We should be in-line with tarantool here and
provide `Call17` as just `Call` and rename
current `Call` to `Call16`.

Closes #125
  • Loading branch information
AnaNek committed Jun 17, 2022
1 parent 1a1fe7b commit 3b3ad86
Show file tree
Hide file tree
Showing 21 changed files with 257 additions and 66 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ jobs:
- name: Run tests
run: make test

- name: Run tests with call_17
run: make test TAGS="go_tarantool_call_17"

- name: Run tests, collect code coverage data and send to Coveralls
if: ${{ matrix.coveralls }}
env:
Expand Down Expand Up @@ -134,6 +137,13 @@ jobs:
env:
TEST_TNT_SSL: ${{matrix.ssl}}

- name: Run tests with call_17
run: |
source tarantool-enterprise/env.sh
make test TAGS="go_tarantool_call_17"
env:
TEST_TNT_SSL: ${{matrix.ssl}}

- name: Run tests, collect code coverage data and send to Coveralls
if: ${{ matrix.coveralls }}
env:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.

### Changed

- Add `Call16` method, support build tag `go_tarantool_call_17`
to choose behavior for `Call` method (#125)

### Fixed

## [1.6.0] - 2022-06-01
Expand Down
19 changes: 10 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ BENCH_REFERENCE_REPO := ${BENCH_PATH}/go-tarantool
BENCH_OPTIONS := -bench=. -run=^Benchmark -benchmem -benchtime=${DURATION} -count=${COUNT}
GO_TARANTOOL_URL := https://github.com/tarantool/go-tarantool
GO_TARANTOOL_DIR := ${PROJECT_DIR}/${BENCH_PATH}/go-tarantool
TAGS :=

.PHONY: clean
clean:
Expand All @@ -33,7 +34,7 @@ golangci-lint:

.PHONY: test
test:
go test ./... -v -p 1
go test -tags "$(TAGS)" ./... -v -p 1

.PHONY: testdata
testdata:
Expand All @@ -43,38 +44,38 @@ testdata:
test-connection-pool:
@echo "Running tests in connection_pool package"
go clean -testcache
go test ./connection_pool/ -v -p 1
go test -tags "$(TAGS)" ./connection_pool/ -v -p 1

.PHONY: test-multi
test-multi:
@echo "Running tests in multiconnection package"
go clean -testcache
go test ./multi/ -v -p 1
go test -tags "$(TAGS)" ./multi/ -v -p 1

.PHONY: test-queue
test-queue:
@echo "Running tests in queue package"
cd ./queue/ && tarantool -e "require('queue')"
go clean -testcache
go test ./queue/ -v -p 1
go test -tags "$(TAGS)" ./queue/ -v -p 1

.PHONY: test-uuid
test-uuid:
@echo "Running tests in UUID package"
go clean -testcache
go test ./uuid/ -v -p 1
go test -tags "$(TAGS)" ./uuid/ -v -p 1

.PHONY: test-main
test-main:
@echo "Running tests in main package"
go clean -testcache
go test . -v -p 1
go test -tags "$(TAGS)" . -v -p 1

.PHONY: coverage
coverage:
go clean -testcache
go get golang.org/x/tools/cmd/cover
go test ./... -v -p 1 -covermode=atomic -coverprofile=$(COVERAGE_FILE) -coverpkg=./...
go test -tags "$(TAGS)" ./... -v -p 1 -covermode=atomic -coverprofile=$(COVERAGE_FILE) -coverpkg=./...
go tool cover -func=$(COVERAGE_FILE)

.PHONY: coveralls
Expand All @@ -94,7 +95,7 @@ ${BENCH_PATH} bench-deps:
.PHONY: bench
${BENCH_FILE} bench: ${BENCH_PATH}
@echo "Running benchmark tests from the current branch"
go test ${TEST_PATH} ${BENCH_OPTIONS} 2>&1 \
go test -tags "$(TAGS)" ${TEST_PATH} ${BENCH_OPTIONS} 2>&1 \
| tee ${BENCH_FILE}
benchstat ${BENCH_FILE}

Expand All @@ -104,7 +105,7 @@ ${GO_TARANTOOL_DIR}:

${REFERENCE_FILE}: ${GO_TARANTOOL_DIR}
@echo "Running benchmark tests from master for using results in bench-diff target"
cd ${GO_TARANTOOL_DIR} && git pull && go test ./... ${BENCH_OPTIONS} 2>&1 \
cd ${GO_TARANTOOL_DIR} && git pull && go test ./... -tags "$(TAGS)" ${BENCH_OPTIONS} 2>&1 \
| tee ${REFERENCE_FILE}

bench-diff: ${BENCH_FILES}
Expand Down
27 changes: 27 additions & 0 deletions call_16_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build !go_tarantool_call_17
// +build !go_tarantool_call_17

package tarantool_test

import (
"testing"

. "github.com/tarantool/go-tarantool"
)

func TestConnection_Call(t *testing.T) {
var resp *Response
var err error

conn := connect(t, server, opts)
defer conn.Close()

// Call16
resp, err = conn.Call("simple_incr", []interface{}{1})
if err != nil {
t.Errorf("Failed to use Call")
}
if resp.Data[0].([]interface{})[0].(uint64) != 2 {
t.Errorf("result is not {{1}} : %v", resp.Data)
}
}
27 changes: 27 additions & 0 deletions call_17_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build go_tarantool_call_17
// +build go_tarantool_call_17

package tarantool_test

import (
"testing"

. "github.com/tarantool/go-tarantool"
)

func TestConnection_Call(t *testing.T) {
var resp *Response
var err error

conn := connect(t, server, opts)
defer conn.Close()

// Call17
resp, err = conn.Call17("simple_incr", []interface{}{1})
if err != nil {
t.Errorf("Failed to use Call")
}
if resp.Data[0].(uint64) != 2 {
t.Errorf("result is not {{1}} : %v", resp.Data)
}
}
4 changes: 2 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
//
// ATTENTION: result argument for *Typed methods should deserialize from
// msgpack array, cause Tarantool always returns result as an array.
// For all space related methods and Call* (but not Call17*) methods Tarantool
// For all space related methods and Call16* (but not Call*) methods Tarantool
// always returns array of array (array of tuples for space related methods).
// For Eval* and Call17* Tarantool always returns array, but does not forces
// For Eval* and Call* Tarantool always returns array, but does not forces
// array of arrays.
type Connection struct {
addr string
Expand Down
56 changes: 49 additions & 7 deletions connection_pool/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ func (connPool *ConnectionPool) Upsert(space interface{}, tuple, ops interface{}
return conn.Upsert(space, tuple, ops)
}

// Call calls registered Tarantool function.
// It uses request code for Tarantool 1.6, so result is converted to array of arrays.
// Call16 calls registered Tarantool function.
// It uses request code for Tarantool >= 1.7 if go-tarantool
// was build with go_tarantool_call_17 tag.
// Otherwise, uses request code for Tarantool 1.6.
func (connPool *ConnectionPool) Call(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
conn, err := connPool.getNextConnection(userMode)
if err != nil {
Expand All @@ -266,8 +268,20 @@ func (connPool *ConnectionPool) Call(functionName string, args interface{}, user
return conn.Call(functionName, args)
}

// Call16 calls registered Tarantool function.
// It uses request code for Tarantool 1.6, so result is converted to array of arrays.
// Deprecated since 1.7.4.
func (connPool *ConnectionPool) Call16(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
conn, err := connPool.getNextConnection(userMode)
if err != nil {
return nil, err
}

return conn.Call16(functionName, args)
}

// Call17 calls registered Tarantool function.
// It uses request code for Tarantool 1.7, so result is not converted
// It uses request code for Tarantool >= 1.7, so result is not converted
// (though, keep in mind, result is always array).
func (connPool *ConnectionPool) Call17(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
conn, err := connPool.getNextConnection(userMode)
Expand Down Expand Up @@ -352,7 +366,9 @@ func (connPool *ConnectionPool) UpdateTyped(space, index interface{}, key, ops i
}

// CallTyped calls registered function.
// It uses request code for Tarantool 1.6, so result is converted to array of arrays.
// It uses request code for Tarantool >= 1.7 if go-tarantool
// was build with go_tarantool_call_17 tag.
// Otherwise, uses request code for Tarantool 1.6.
func (connPool *ConnectionPool) CallTyped(functionName string, args interface{}, result interface{}, userMode Mode) (err error) {
conn, err := connPool.getNextConnection(userMode)
if err != nil {
Expand All @@ -362,8 +378,20 @@ func (connPool *ConnectionPool) CallTyped(functionName string, args interface{},
return conn.CallTyped(functionName, args, result)
}

// Call16Typed calls registered function.
// It uses request code for Tarantool 1.6, so result is converted to array of arrays.
// Deprecated since 1.7.4.
func (connPool *ConnectionPool) Call16Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error) {
conn, err := connPool.getNextConnection(userMode)
if err != nil {
return err
}

return conn.Call16Typed(functionName, args, result)
}

// Call17Typed calls registered function.
// It uses request code for Tarantool 1.7, so result is not converted
// It uses request code for Tarantool >= 1.7, so result is not converted
// (though, keep in mind, result is always array).
func (connPool *ConnectionPool) Call17Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error) {
conn, err := connPool.getNextConnection(userMode)
Expand Down Expand Up @@ -450,7 +478,9 @@ func (connPool *ConnectionPool) UpsertAsync(space interface{}, tuple interface{}
}

// CallAsync sends a call to registered Tarantool function and returns Future.
// It uses request code for Tarantool 1.6, so future's result is always array of arrays.
// It uses request code for Tarantool >= 1.7 if go-tarantool
// was build with go_tarantool_call_17 tag.
// Otherwise, uses request code for Tarantool 1.6.
func (connPool *ConnectionPool) CallAsync(functionName string, args interface{}, userMode Mode) *tarantool.Future {
conn, err := connPool.getNextConnection(userMode)
if err != nil {
Expand All @@ -460,8 +490,20 @@ func (connPool *ConnectionPool) CallAsync(functionName string, args interface{},
return conn.CallAsync(functionName, args)
}

// Call16Async sends a call to registered Tarantool function and returns Future.
// It uses request code for Tarantool 1.6, so future's result is always array of arrays.
// Deprecated since 1.7.4.
func (connPool *ConnectionPool) Call16Async(functionName string, args interface{}, userMode Mode) *tarantool.Future {
conn, err := connPool.getNextConnection(userMode)
if err != nil {
return tarantool.NewErrorFuture(err)
}

return conn.Call16Async(functionName, args)
}

// Call17Async sends a call to registered Tarantool function and returns Future.
// It uses request code for Tarantool 1.7, so future's result will not be converted
// It uses request code for Tarantool >= 1.7, so future's result will not be converted
// (though, keep in mind, result is always array).
func (connPool *ConnectionPool) Call17Async(functionName string, args interface{}, userMode Mode) *tarantool.Future {
conn, err := connPool.getNextConnection(userMode)
Expand Down
2 changes: 1 addition & 1 deletion connection_pool/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func ExampleConnectionPool_Update() {
// Data [[key1 new_value]]
}

func ExampleConnectionPool_Call17() {
func ExampleConnectionPool_Call() {
pool, err := examplePool(testRoles)
if err != nil {
fmt.Println(err)
Expand Down
3 changes: 3 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Connector interface {
Update(space, index interface{}, key, ops interface{}) (resp *Response, err error)
Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error)
Call(functionName string, args interface{}) (resp *Response, err error)
Call16(functionName string, args interface{}) (resp *Response, err error)
Call17(functionName string, args interface{}) (resp *Response, err error)
Eval(expr string, args interface{}) (resp *Response, err error)
Execute(expr string, args interface{}) (resp *Response, err error)
Expand All @@ -26,6 +27,7 @@ type Connector interface {
DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error)
UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error)
CallTyped(functionName string, args interface{}, result interface{}) (err error)
Call16Typed(functionName string, args interface{}, result interface{}) (err error)
Call17Typed(functionName string, args interface{}, result interface{}) (err error)
EvalTyped(expr string, args interface{}, result interface{}) (err error)

Expand All @@ -36,6 +38,7 @@ type Connector interface {
UpdateAsync(space, index interface{}, key, ops interface{}) *Future
UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future
CallAsync(functionName string, args interface{}) *Future
Call16Async(functionName string, args interface{}) *Future
Call17Async(functionName string, args interface{}) *Future
EvalAsync(expr string, args interface{}) *Future
}
4 changes: 2 additions & 2 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const (
ReplaceRequest = 3
UpdateRequest = 4
DeleteRequest = 5
CallRequest = 6 /* call in 1.6 format */
Call16Request = 6 /* call in 1.6 format */
AuthRequest = 7
EvalRequest = 8
UpsertRequest = 9
Call17Request = 10
Call17Request = 10 /* call in >= 1.7 format */
ExecuteRequest = 11
PingRequest = 64
SubscribeRequest = 66
Expand Down
8 changes: 8 additions & 0 deletions const_call_16.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !go_tarantool_call_17
// +build !go_tarantool_call_17

package tarantool

const (
CallRequest = 6 // CALL_16
)
8 changes: 8 additions & 0 deletions const_call_17.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build go_tarantool_call_17
// +build go_tarantool_call_17

package tarantool

const (
CallRequest = 10 // CALL_17
)
6 changes: 3 additions & 3 deletions example_custom_unpacking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func Example_customUnpacking() {
fmt.Println("Tuples (tuples2):", tuples2)

// Call a function "func_name" returning a table of custom tuples.
var tuples3 []Tuple3
err = conn.CallTyped("func_name", []interface{}{}, &tuples3)
var tuples3 [][]Tuple3
err = conn.Call17Typed("func_name", []interface{}{}, &tuples3)
if err != nil {
log.Fatalf("Failed to CallTyped: %s", err.Error())
return
Expand All @@ -131,6 +131,6 @@ func Example_customUnpacking() {
// Code 0
// Tuples (tuples1) [{777 orig [{lol 1} {wut 3}]}]
// Tuples (tuples2): [{{} 777 orig [{lol 1} {wut 3}]}]
// Tuples (tuples3): [{{} 221 [{Moscow 34} {Minsk 23} {Kiev 31}]}]
// Tuples (tuples3): [[{{} 221 [{Moscow 34} {Minsk 23} {Kiev 31}]}]]

}
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func ExampleConnection_Update() {
// Data [[14 bye bla]]
}

func ExampleConnection_Call17() {
func ExampleConnection_Call() {
conn := example_connect()
defer conn.Close()

Expand Down
Loading

0 comments on commit 3b3ad86

Please sign in to comment.