From 3f34802c1887879b5bb5e973e5ee415a3a5cd940 Mon Sep 17 00:00:00 2001 From: Oleg Jukovec Date: Wed, 22 Mar 2023 15:24:08 +0300 Subject: [PATCH] api: make Call = Call17 Closes #235 --- .github/workflows/testing.yml | 19 ------ CHANGELOG.md | 1 + README.md | 16 ++--- call_16_test.go | 54 ---------------- call_17_test.go | 54 ---------------- const.go | 1 + const_call_16.go | 8 --- const_call_17.go | 8 --- pool/call_16_test.go | 69 -------------------- pool/call_17_test.go | 69 -------------------- pool/connection_pool.go | 29 +++------ pool/connection_pool_test.go | 114 ++++++++++++++++++++++++++++++++++ pool/connector.go | 27 +++----- request.go | 32 ++++------ request_test.go | 7 ++- tarantool_test.go | 33 ++++++++++ 16 files changed, 194 insertions(+), 347 deletions(-) delete mode 100644 call_16_test.go delete mode 100644 call_17_test.go delete mode 100644 const_call_16.go delete mode 100644 const_call_17.go delete mode 100644 pool/call_16_test.go delete mode 100644 pool/call_17_test.go diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 68f283b95..6745870a2 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -99,11 +99,6 @@ jobs: make test make testrace - - name: Run regression tests with call_17 - run: | - make test TAGS="go_tarantool_call_17" - make testrace TAGS="go_tarantool_call_17" - - name: Run fuzzing tests if: ${{ matrix.fuzzing }} run: make fuzzing TAGS="go_tarantool_decimal_fuzzing" @@ -189,14 +184,6 @@ jobs: env: TEST_TNT_SSL: ${{matrix.ssl}} - - name: Run regression tests with call_17 - run: | - source tarantool-enterprise/env.sh - make test TAGS="go_tarantool_call_17" - make testrace TAGS="go_tarantool_call_17" - env: - TEST_TNT_SSL: ${{matrix.ssl}} - - name: Run fuzzing tests if: ${{ matrix.fuzzing }} run: make fuzzing TAGS="go_tarantool_decimal_fuzzing" @@ -363,12 +350,6 @@ jobs: make test make testrace - - name: Run regression tests with call_17 - run: | - cd "${SRCDIR}" - make test TAGS="go_tarantool_call_17" - make testrace TAGS="go_tarantool_call_17" - - name: Run fuzzing tests if: ${{ matrix.fuzzing }} run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index d3db41a52..5cb0424f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release. - connection_pool renamed to pool (#239) - Use msgpack/v5 instead of msgpack.v2 (#236) +- Call/NewCallRequest = Call17/NewCall17Request (#235) ### Removed diff --git a/README.md b/README.md index ea941d964..d51a11cdd 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ faster than other packages according to public benchmarks. * [multi package](#multi-package) * [pool package](#pool-package) * [msgpack.v5](#msgpackv5) + * [Call = Call17](#call--call17) * [Contributing](#contributing) * [Alternative connectors](#alternative-connectors) @@ -66,13 +67,7 @@ This allows us to introduce new features without losing backward compatibility. ``` go_tarantool_ssl_disable ``` -2. To change the default `Call` behavior from `Call16` to `Call17`, you can use - the build tag: - ``` - go_tarantool_call_17 - ``` - **Note:** In future releases, `Call17` may be used as default `Call` behavior. -3. To run fuzz tests with decimals, you can use the build tag: +2. To run fuzz tests with decimals, you can use the build tag: ``` go_tarantool_decimal_fuzzing ``` @@ -188,6 +183,13 @@ There are also changes in the logic that can lead to errors in the old code, to achieve full compliance of behavior between `msgpack.v5` and `msgpack.v2`. So we don't go this way. We use standard settings if it possible. +#### Call = Call17 + +Call requests uses `IPROTO_CALL` instead of `IPROTO_CALL_16`. + +So now `Call` = `Call17` and `NewCallRequest` = `NewCall17Request`. A result +of the requests is an array instead of array of arrays. + ## Contributing See [the contributing guide](CONTRIBUTING.md) for detailed instructions on how diff --git a/call_16_test.go b/call_16_test.go deleted file mode 100644 index 8407f109d..000000000 --- a/call_16_test.go +++ /dev/null @@ -1,54 +0,0 @@ -//go:build !go_tarantool_call_17 -// +build !go_tarantool_call_17 - -package tarantool_test - -import ( - "testing" - - . "github.com/tarantool/go-tarantool/v2" - "github.com/tarantool/go-tarantool/v2/test_helpers" -) - -func TestConnection_Call(t *testing.T) { - var resp *Response - var err error - - conn := test_helpers.ConnectWithValidation(t, server, opts) - defer conn.Close() - - // Call16 - resp, err = conn.Call("simple_concat", []interface{}{"1"}) - if err != nil { - t.Errorf("Failed to use Call") - } - if val, ok := resp.Data[0].([]interface{})[0].(string); !ok || val != "11" { - t.Errorf("result is not {{1}} : %v", resp.Data) - } -} - -func TestCallRequest(t *testing.T) { - var resp *Response - var err error - - conn := test_helpers.ConnectWithValidation(t, server, opts) - defer conn.Close() - - req := NewCallRequest("simple_concat").Args([]interface{}{"1"}) - resp, err = conn.Do(req).Get() - if err != nil { - t.Errorf("Failed to use Call") - } - if val, ok := resp.Data[0].([]interface{})[0].(string); !ok || val != "11" { - t.Errorf("result is not {{1}} : %v", resp.Data) - } -} - -func TestCallRequestCode(t *testing.T) { - req := NewCallRequest("simple_concat") - code := req.Code() - expected := Call16RequestCode - if code != int32(expected) { - t.Errorf("CallRequest actual code %v != %v", code, expected) - } -} diff --git a/call_17_test.go b/call_17_test.go deleted file mode 100644 index 6111aa52c..000000000 --- a/call_17_test.go +++ /dev/null @@ -1,54 +0,0 @@ -//go:build go_tarantool_call_17 -// +build go_tarantool_call_17 - -package tarantool_test - -import ( - "testing" - - . "github.com/tarantool/go-tarantool/v2" - "github.com/tarantool/go-tarantool/v2/test_helpers" -) - -func TestConnection_Call(t *testing.T) { - var resp *Response - var err error - - conn := test_helpers.ConnectWithValidation(t, server, opts) - defer conn.Close() - - // Call17 - resp, err = conn.Call17("simple_concat", []interface{}{"1"}) - if err != nil { - t.Errorf("Failed to use Call") - } - if val, ok := resp.Data[0].(string); !ok || val != "11" { - t.Errorf("result is not {{1}} : %v", resp.Data) - } -} - -func TestCallRequest(t *testing.T) { - var resp *Response - var err error - - conn := test_helpers.ConnectWithValidation(t, server, opts) - defer conn.Close() - - req := NewCallRequest("simple_concat").Args([]interface{}{"1"}) - resp, err = conn.Do(req).Get() - if err != nil { - t.Errorf("Failed to use Call") - } - if val, ok := resp.Data[0].(string); !ok || val != "11" { - t.Errorf("result is not {{1}} : %v", resp.Data) - } -} - -func TestCallRequestCode(t *testing.T) { - req := NewCallRequest("simple_concat") - code := req.Code() - expected := Call17RequestCode - if code != int32(expected) { - t.Errorf("CallRequest actual code %v != %v", code, expected) - } -} diff --git a/const.go b/const.go index 4b6458645..4580e4cb0 100644 --- a/const.go +++ b/const.go @@ -21,6 +21,7 @@ const ( IdRequestCode = 73 WatchRequestCode = 74 UnwatchRequestCode = 75 + CallRequestCode = Call17RequestCode KeyCode = 0x00 KeySync = 0x01 diff --git a/const_call_16.go b/const_call_16.go deleted file mode 100644 index 7d80cc631..000000000 --- a/const_call_16.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build !go_tarantool_call_17 -// +build !go_tarantool_call_17 - -package tarantool - -const ( - CallRequestCode = Call16RequestCode -) diff --git a/const_call_17.go b/const_call_17.go deleted file mode 100644 index d50d8f1c1..000000000 --- a/const_call_17.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build go_tarantool_call_17 -// +build go_tarantool_call_17 - -package tarantool - -const ( - CallRequestCode = Call17RequestCode -) diff --git a/pool/call_16_test.go b/pool/call_16_test.go deleted file mode 100644 index 04b8898bc..000000000 --- a/pool/call_16_test.go +++ /dev/null @@ -1,69 +0,0 @@ -//go:build !go_tarantool_call_17 -// +build !go_tarantool_call_17 - -package pool_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/tarantool/go-tarantool/v2/pool" - "github.com/tarantool/go-tarantool/v2/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 := 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{}{}, 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{}{}, 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{}{}, 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{}{}, 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`") -} diff --git a/pool/call_17_test.go b/pool/call_17_test.go deleted file mode 100644 index 6ca8381ad..000000000 --- a/pool/call_17_test.go +++ /dev/null @@ -1,69 +0,0 @@ -//go:build go_tarantool_call_17 -// +build go_tarantool_call_17 - -package pool_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/tarantool/go-tarantool/v2/pool" - "github.com/tarantool/go-tarantool/v2/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 := 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{}{}, 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{}{}, 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{}{}, 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{}{}, 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`") -} diff --git a/pool/connection_pool.go b/pool/connection_pool.go index bc8a3541a..a2cb9e48c 100644 --- a/pool/connection_pool.go +++ b/pool/connection_pool.go @@ -345,10 +345,8 @@ func (connPool *ConnectionPool) Upsert(space interface{}, tuple, ops interface{} return conn.Upsert(space, tuple, ops) } -// 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. +// Call calls registered Tarantool function. +// It uses request code for Tarantool >= 1.7, result is an array. func (connPool *ConnectionPool) Call(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -359,7 +357,7 @@ func (connPool *ConnectionPool) Call(functionName string, args interface{}, user } // Call16 calls registered Tarantool function. -// It uses request code for Tarantool 1.6, so result is converted to array of arrays. +// It uses request code for Tarantool 1.6, result is an array of arrays. // Deprecated since Tarantool 1.7.2. func (connPool *ConnectionPool) Call16(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getNextConnection(userMode) @@ -371,8 +369,7 @@ func (connPool *ConnectionPool) Call16(functionName string, args interface{}, us } // Call17 calls registered Tarantool function. -// It uses request code for Tarantool >= 1.7, so result is not converted -// (though, keep in mind, result is always array). +// It uses request code for Tarantool >= 1.7, result is an array. func (connPool *ConnectionPool) Call17(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -466,9 +463,7 @@ func (connPool *ConnectionPool) UpdateTyped(space, index interface{}, key, ops i } // CallTyped calls registered 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. +// It uses request code for Tarantool >= 1.7, result is an array. func (connPool *ConnectionPool) CallTyped(functionName string, args interface{}, result interface{}, userMode Mode) (err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -479,7 +474,7 @@ func (connPool *ConnectionPool) CallTyped(functionName string, args interface{}, } // Call16Typed 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.6, result is an array of arrays. // Deprecated since Tarantool 1.7.2. func (connPool *ConnectionPool) Call16Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error) { conn, err := connPool.getNextConnection(userMode) @@ -491,8 +486,7 @@ func (connPool *ConnectionPool) Call16Typed(functionName string, args interface{ } // Call17Typed calls registered function. -// It uses request code for Tarantool >= 1.7, so result is not converted -// (though, keep in mind, result is always array). +// It uses request code for Tarantool >= 1.7, result is an array. func (connPool *ConnectionPool) Call17Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -588,9 +582,7 @@ 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.7 if go-tarantool -// was build with go_tarantool_call_17 tag. -// Otherwise, uses request code for Tarantool 1.6. +// It uses request code for Tarantool >= 1.7, future's result is an array. func (connPool *ConnectionPool) CallAsync(functionName string, args interface{}, userMode Mode) *tarantool.Future { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -601,7 +593,7 @@ func (connPool *ConnectionPool) CallAsync(functionName string, args interface{}, } // 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. +// It uses request code for Tarantool 1.6, so future's result is an array of arrays. // Deprecated since Tarantool 1.7.2. func (connPool *ConnectionPool) Call16Async(functionName string, args interface{}, userMode Mode) *tarantool.Future { conn, err := connPool.getNextConnection(userMode) @@ -613,8 +605,7 @@ func (connPool *ConnectionPool) Call16Async(functionName string, args interface{ } // 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 -// (though, keep in mind, result is always array). +// It uses request code for Tarantool >= 1.7, future's result is an array. func (connPool *ConnectionPool) Call17Async(functionName string, args interface{}, userMode Mode) *tarantool.Future { conn, err := connPool.getNextConnection(userMode) if err != nil { diff --git a/pool/connection_pool_test.go b/pool/connection_pool_test.go index b31e01cee..2f1d50764 100644 --- a/pool/connection_pool_test.go +++ b/pool/connection_pool_test.go @@ -579,6 +579,120 @@ func TestGetPoolInfo(t *testing.T) { } } +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 := 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{}{}, 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{}{}, 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{}{}, 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{}{}, 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`") +} + +func TestCall16(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 := 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.Call16("box.info", []interface{}{}, 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.Call16("box.info", []interface{}{}, 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.Call16("box.info", []interface{}{}, 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.Call16("box.info", []interface{}{}, 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`") +} + func TestCall17(t *testing.T) { roles := []bool{false, true, false, false, true} diff --git a/pool/connector.go b/pool/connector.go index 128d80575..22760801b 100644 --- a/pool/connector.go +++ b/pool/connector.go @@ -99,16 +99,14 @@ func (c *ConnectorAdapter) Upsert(space interface{}, } // Call 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. +// It uses request code for Tarantool >= 1.7, result is an array. func (c *ConnectorAdapter) Call(functionName string, args interface{}) (*tarantool.Response, error) { return c.pool.Call(functionName, args, c.mode) } // Call16 calls registered Tarantool function. -// It uses request code for Tarantool 1.6, so result is converted to array of arrays +// It uses request code for Tarantool 1.6, result is an array of arrays. // Deprecated since Tarantool 1.7.2. func (c *ConnectorAdapter) Call16(functionName string, args interface{}) (*tarantool.Response, error) { @@ -116,8 +114,7 @@ func (c *ConnectorAdapter) Call16(functionName string, } // Call17 calls registered Tarantool function. -// It uses request code for Tarantool >= 1.7, so result is not converted -// (though, keep in mind, result is always array) +// It uses request code for Tarantool >= 1.7, result is an array. func (c *ConnectorAdapter) Call17(functionName string, args interface{}) (*tarantool.Response, error) { return c.pool.Call17(functionName, args, c.mode) @@ -174,16 +171,14 @@ func (c *ConnectorAdapter) UpdateTyped(space, index interface{}, } // CallTyped calls registered 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. +// It uses request code for Tarantool >= 1.7, result is an array. func (c *ConnectorAdapter) CallTyped(functionName string, args interface{}, result interface{}) error { return c.pool.CallTyped(functionName, args, result, c.mode) } // Call16Typed 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.6, result is an array of arrays. // Deprecated since Tarantool 1.7.2. func (c *ConnectorAdapter) Call16Typed(functionName string, args interface{}, result interface{}) error { @@ -191,8 +186,7 @@ func (c *ConnectorAdapter) Call16Typed(functionName string, } // Call17Typed calls registered function. -// It uses request code for Tarantool >= 1.7, so result is not converted -// (though, keep in mind, result is always array) +// It uses request code for Tarantool >= 1.7, result is an array. func (c *ConnectorAdapter) Call17Typed(functionName string, args interface{}, result interface{}) error { return c.pool.Call17Typed(functionName, args, result, c.mode) @@ -247,16 +241,14 @@ func (c *ConnectorAdapter) UpsertAsync(space interface{}, tuple interface{}, } // CallAsync sends a call to registered Tarantool function and returns Future. -// 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. +// It uses request code for Tarantool >= 1.7, future's result is an array. func (c *ConnectorAdapter) CallAsync(functionName string, args interface{}) *tarantool.Future { return c.pool.CallAsync(functionName, args, c.mode) } // 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. +// It uses request code for Tarantool 1.6, so future's result is an array of arrays. // Deprecated since Tarantool 1.7.2. func (c *ConnectorAdapter) Call16Async(functionName string, args interface{}) *tarantool.Future { @@ -264,8 +256,7 @@ func (c *ConnectorAdapter) Call16Async(functionName string, } // 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 -// (though, keep in mind, result is always array) +// It uses request code for Tarantool >= 1.7, future's result is an array. func (c *ConnectorAdapter) Call17Async(functionName string, args interface{}) *tarantool.Future { return c.pool.Call17Async(functionName, args, c.mode) diff --git a/request.go b/request.go index 5388c0e1a..3f539b2dd 100644 --- a/request.go +++ b/request.go @@ -218,9 +218,7 @@ func (conn *Connection) Upsert(space interface{}, tuple, ops interface{}) (resp } // Call 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. +// It uses request code for Tarantool >= 1.7, result is an array. // // It is equal to conn.CallAsync(functionName, args).Get(). func (conn *Connection) Call(functionName string, args interface{}) (resp *Response, err error) { @@ -228,7 +226,7 @@ func (conn *Connection) Call(functionName string, args interface{}) (resp *Respo } // Call16 calls registered Tarantool function. -// It uses request code for Tarantool 1.6, so result is converted to array of arrays +// It uses request code for Tarantool 1.6, result is an array of arrays. // Deprecated since Tarantool 1.7.2. // // It is equal to conn.Call16Async(functionName, args).Get(). @@ -237,8 +235,7 @@ func (conn *Connection) Call16(functionName string, args interface{}) (resp *Res } // Call17 calls registered Tarantool function. -// It uses request code for Tarantool >= 1.7, so result is not converted -// (though, keep in mind, result is always array) +// It uses request code for Tarantool >= 1.7, result is an array. // // It is equal to conn.Call17Async(functionName, args).Get(). func (conn *Connection) Call17(functionName string, args interface{}) (resp *Response, err error) { @@ -329,9 +326,7 @@ func (conn *Connection) UpdateTyped(space, index interface{}, key, ops interface } // CallTyped calls registered 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. +// It uses request code for Tarantool >= 1.7, result is an array. // // It is equal to conn.Call16Async(functionName, args).GetTyped(&result). func (conn *Connection) CallTyped(functionName string, args interface{}, result interface{}) (err error) { @@ -339,7 +334,7 @@ func (conn *Connection) CallTyped(functionName string, args interface{}, result } // Call16Typed 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.6, result is an array of arrays. // Deprecated since Tarantool 1.7.2. // // It is equal to conn.Call16Async(functionName, args).GetTyped(&result). @@ -348,8 +343,7 @@ func (conn *Connection) Call16Typed(functionName string, args interface{}, resul } // Call17Typed calls registered function. -// It uses request code for Tarantool >= 1.7, so result is not converted -// (though, keep in mind, result is always array) +// It uses request code for Tarantool >= 1.7, result is an array. // // It is equal to conn.Call17Async(functionName, args).GetTyped(&result). func (conn *Connection) Call17Typed(functionName string, args interface{}, result interface{}) (err error) { @@ -422,16 +416,14 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in } // CallAsync sends a call to registered Tarantool function and returns Future. -// 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. +// It uses request code for Tarantool >= 1.7, so future's result is an array. func (conn *Connection) CallAsync(functionName string, args interface{}) *Future { req := NewCallRequest(functionName).Args(args) return conn.Do(req) } // 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. +// It uses request code for Tarantool 1.6, so future's result is an array of arrays. // Deprecated since Tarantool 1.7.2. func (conn *Connection) Call16Async(functionName string, args interface{}) *Future { req := NewCall16Request(functionName).Args(args) @@ -439,8 +431,7 @@ func (conn *Connection) Call16Async(functionName string, args interface{}) *Futu } // 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 -// (though, keep in mind, result is always array) +// It uses request code for Tarantool >= 1.7, so future's result is an array. func (conn *Connection) Call17Async(functionName string, args interface{}) *Future { req := NewCall17Request(functionName).Args(args) return conn.Do(req) @@ -1115,9 +1106,8 @@ type CallRequest struct { args interface{} } -// NewCallRequest return a new empty CallRequest. 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. +// NewCallRequest returns a new empty CallRequest. It uses request code for +// Tarantool >= 1.7. func NewCallRequest(function string) *CallRequest { req := new(CallRequest) req.requestCode = CallRequestCode diff --git a/request_test.go b/request_test.go index d3f15c179..b9a3a656d 100644 --- a/request_test.go +++ b/request_test.go @@ -180,6 +180,8 @@ func TestRequestsCodes(t *testing.T) { {req: NewInsertRequest(validSpace), code: InsertRequestCode}, {req: NewReplaceRequest(validSpace), code: ReplaceRequestCode}, {req: NewDeleteRequest(validSpace), code: DeleteRequestCode}, + {req: NewCallRequest(validExpr), code: CallRequestCode}, + {req: NewCallRequest(validExpr), code: Call17RequestCode}, {req: NewCall16Request(validExpr), code: Call16RequestCode}, {req: NewCall17Request(validExpr), code: Call17RequestCode}, {req: NewEvalRequest(validExpr), code: EvalRequestCode}, @@ -213,6 +215,7 @@ func TestRequestsAsync(t *testing.T) { {req: NewInsertRequest(validSpace), async: false}, {req: NewReplaceRequest(validSpace), async: false}, {req: NewDeleteRequest(validSpace), async: false}, + {req: NewCallRequest(validExpr), async: false}, {req: NewCall16Request(validExpr), async: false}, {req: NewCall17Request(validExpr), async: false}, {req: NewEvalRequest(validExpr), async: false}, @@ -246,6 +249,7 @@ func TestRequestsCtx_default(t *testing.T) { {req: NewInsertRequest(validSpace), expected: nil}, {req: NewReplaceRequest(validSpace), expected: nil}, {req: NewDeleteRequest(validSpace), expected: nil}, + {req: NewCallRequest(validExpr), expected: nil}, {req: NewCall16Request(validExpr), expected: nil}, {req: NewCall17Request(validExpr), expected: nil}, {req: NewEvalRequest(validExpr), expected: nil}, @@ -280,6 +284,7 @@ func TestRequestsCtx_setter(t *testing.T) { {req: NewInsertRequest(validSpace).Context(ctx), expected: ctx}, {req: NewReplaceRequest(validSpace).Context(ctx), expected: ctx}, {req: NewDeleteRequest(validSpace).Context(ctx), expected: ctx}, + {req: NewCallRequest(validExpr).Context(ctx), expected: ctx}, {req: NewCall16Request(validExpr).Context(ctx), expected: ctx}, {req: NewCall17Request(validExpr).Context(ctx), expected: ctx}, {req: NewEvalRequest(validExpr).Context(ctx), expected: ctx}, @@ -598,7 +603,7 @@ func TestCallRequestsSetters(t *testing.T) { return } - req := NewCall16Request(validExpr). + req := NewCallRequest(validExpr). Args(args) req16 := NewCall16Request(validExpr). Args(args) diff --git a/tarantool_test.go b/tarantool_test.go index bc15b3eed..07f9ab55a 100644 --- a/tarantool_test.go +++ b/tarantool_test.go @@ -2601,6 +2601,39 @@ func TestConnectionDoSelectRequest_pagination_pos(t *testing.T) { testConnectionDoSelectRequestCheck(t, resp, err, true, 2, 1012) } +func TestConnection_Call(t *testing.T) { + var resp *Response + var err error + + conn := test_helpers.ConnectWithValidation(t, server, opts) + defer conn.Close() + + resp, err = conn.Call("simple_concat", []interface{}{"1"}) + if err != nil { + t.Errorf("Failed to use Call") + } + if val, ok := resp.Data[0].(string); !ok || val != "11" { + t.Errorf("result is not {{1}} : %v", resp.Data) + } +} + +func TestCallRequest(t *testing.T) { + var resp *Response + var err error + + conn := test_helpers.ConnectWithValidation(t, server, opts) + defer conn.Close() + + req := NewCallRequest("simple_concat").Args([]interface{}{"1"}) + resp, err = conn.Do(req).Get() + if err != nil { + t.Errorf("Failed to use Call") + } + if val, ok := resp.Data[0].(string); !ok || val != "11" { + t.Errorf("result is not {{1}} : %v", resp.Data) + } +} + func TestClientRequestObjectsWithNilContext(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, server, opts) defer conn.Close()