forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code-health: allow to use
Call17
as default Call
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`. For backward compatibility in current `go-tarantool` version build tag `go_tarantool_call_17` have been defined. This tag used to change the default `Call` behavior from `Call16` to `Call17`. Closes #125
- Loading branch information
Showing
28 changed files
with
505 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//go:build !go_tarantool_call_17 | ||
// +build !go_tarantool_call_17 | ||
|
||
package connection_pool_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tarantool/go-tarantool/connection_pool" | ||
"github.com/tarantool/go-tarantool/test_helpers" | ||
) | ||
|
||
func TestCall(t *testing.T) { | ||
roles := []bool{false, true, false, false, true} | ||
|
||
err := test_helpers.SetClusterRO(servers, connOpts, roles) | ||
require.Nilf(t, err, "fail to set roles for cluster") | ||
|
||
connPool, err := connection_pool.Connect(servers, connOpts) | ||
require.Nilf(t, err, "failed to connect") | ||
require.NotNilf(t, connPool, "conn is nil after Connect") | ||
|
||
defer connPool.Close() | ||
|
||
// PreferRO | ||
resp, err := connPool.Call("box.info", []interface{}{}, connection_pool.PreferRO) | ||
require.Nilf(t, err, "failed to Call") | ||
require.NotNilf(t, resp, "response is nil after Call") | ||
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") | ||
|
||
val := resp.Data[0].([]interface{})[0].(map[interface{}]interface{})["ro"] | ||
ro, ok := val.(bool) | ||
require.Truef(t, ok, "expected `true` with mode `PreferRO`") | ||
require.Truef(t, ro, "expected `true` with mode `PreferRO`") | ||
|
||
// PreferRW | ||
resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.PreferRW) | ||
require.Nilf(t, err, "failed to Call") | ||
require.NotNilf(t, resp, "response is nil after Call") | ||
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") | ||
|
||
val = resp.Data[0].([]interface{})[0].(map[interface{}]interface{})["ro"] | ||
ro, ok = val.(bool) | ||
require.Truef(t, ok, "expected `false` with mode `PreferRW`") | ||
require.Falsef(t, ro, "expected `false` with mode `PreferRW`") | ||
|
||
// RO | ||
resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RO) | ||
require.Nilf(t, err, "failed to Call") | ||
require.NotNilf(t, resp, "response is nil after Call") | ||
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") | ||
|
||
val = resp.Data[0].([]interface{})[0].(map[interface{}]interface{})["ro"] | ||
ro, ok = val.(bool) | ||
require.Truef(t, ok, "expected `true` with mode `RO`") | ||
require.Truef(t, ro, "expected `true` with mode `RO`") | ||
|
||
// RW | ||
resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RW) | ||
require.Nilf(t, err, "failed to Call") | ||
require.NotNilf(t, resp, "response is nil after Call") | ||
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") | ||
|
||
val = resp.Data[0].([]interface{})[0].(map[interface{}]interface{})["ro"] | ||
ro, ok = val.(bool) | ||
require.Truef(t, ok, "expected `false` with mode `RW`") | ||
require.Falsef(t, ro, "expected `false` with mode `RW`") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//go:build go_tarantool_call_17 | ||
// +build go_tarantool_call_17 | ||
|
||
package connection_pool_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tarantool/go-tarantool/connection_pool" | ||
"github.com/tarantool/go-tarantool/test_helpers" | ||
) | ||
|
||
func TestCall(t *testing.T) { | ||
roles := []bool{false, true, false, false, true} | ||
|
||
err := test_helpers.SetClusterRO(servers, connOpts, roles) | ||
require.Nilf(t, err, "fail to set roles for cluster") | ||
|
||
connPool, err := connection_pool.Connect(servers, connOpts) | ||
require.Nilf(t, err, "failed to connect") | ||
require.NotNilf(t, connPool, "conn is nil after Connect") | ||
|
||
defer connPool.Close() | ||
|
||
// PreferRO | ||
resp, err := connPool.Call("box.info", []interface{}{}, connection_pool.PreferRO) | ||
require.Nilf(t, err, "failed to Call") | ||
require.NotNilf(t, resp, "response is nil after Call") | ||
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") | ||
|
||
val := resp.Data[0].(map[interface{}]interface{})["ro"] | ||
ro, ok := val.(bool) | ||
require.Truef(t, ok, "expected `true` with mode `PreferRO`") | ||
require.Truef(t, ro, "expected `true` with mode `PreferRO`") | ||
|
||
// PreferRW | ||
resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.PreferRW) | ||
require.Nilf(t, err, "failed to Call") | ||
require.NotNilf(t, resp, "response is nil after Call") | ||
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") | ||
|
||
val = resp.Data[0].(map[interface{}]interface{})["ro"] | ||
ro, ok = val.(bool) | ||
require.Truef(t, ok, "expected `false` with mode `PreferRW`") | ||
require.Falsef(t, ro, "expected `false` with mode `PreferRW`") | ||
|
||
// RO | ||
resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RO) | ||
require.Nilf(t, err, "failed to Call") | ||
require.NotNilf(t, resp, "response is nil after Call") | ||
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") | ||
|
||
val = resp.Data[0].(map[interface{}]interface{})["ro"] | ||
ro, ok = val.(bool) | ||
require.Truef(t, ok, "expected `true` with mode `RO`") | ||
require.Truef(t, ro, "expected `true` with mode `RO`") | ||
|
||
// RW | ||
resp, err = connPool.Call("box.info", []interface{}{}, connection_pool.RW) | ||
require.Nilf(t, err, "failed to Call") | ||
require.NotNilf(t, resp, "response is nil after Call") | ||
require.GreaterOrEqualf(t, len(resp.Data), 1, "response.Data is empty after Call") | ||
|
||
val = resp.Data[0].(map[interface{}]interface{})["ro"] | ||
ro, ok = val.(bool) | ||
require.Truef(t, ok, "expected `false` with mode `RW`") | ||
require.Falsef(t, ro, "expected `false` with mode `RW`") | ||
} |
Oops, something went wrong.