From aecaf88a881ce384a302c78be5214e7cb89f8c4d Mon Sep 17 00:00:00 2001 From: Viktor Tsapovskiy Date: Mon, 17 Nov 2025 19:21:23 +0300 Subject: [PATCH] api: removed Connection deprecated methods Removed deprecated `Connection` methods. Related tests are updated (deleted or refactored). Closes #479 --- CHANGELOG.md | 1 + MIGRATION.md | 16 ++ boxerror_test.go | 44 +++-- connection.go | 2 +- request.go | 411 ---------------------------------------------- shutdown_test.go | 20 ++- tarantool_test.go | 233 +++++++++++++++++--------- 7 files changed, 218 insertions(+), 509 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6121a22df..02eef5a15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release. and Future.GetIterator() methods, ResponseIterator and TimeoutResponseIterator types, Future.pushes[] (#480). * `LogAppendPushFailed` replaced with `LogBoxSessionPushUnsupported` (#480) +* Removed deprecated `Connection` methods, related interfaces and tests are updated (#479) ### Fixed diff --git a/MIGRATION.md b/MIGRATION.md index b6849da32..39f2247e0 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -14,6 +14,22 @@ TODO * Removed deprecated `pool` methods, related interfaces and tests are updated. * Removed `box.session.push()` support: Future.AppendPush() and Future.GetIterator() methods, ResponseIterator and TimeoutResponseIterator types. +* Removed deprecated `Connection` methods, related interfaces and tests are updated. + *NOTE*: due to Future.GetTyped() doesn't decode SelectRequest into structure, substitute Connection.GetTyped() following the example: + ```Go + var singleTpl = Tuple{} + err = conn.GetTyped(spaceNo, indexNo, []interface{}{uint(10)}, &singleTpl) + ``` + At now became: + ```Go + var tpl [1]Tuple + err = conn.Do(NewSelectRequest(spaceNo). + Index(indexNo). + Limit(1). + Key([]interface{}{uint(10)}) + ).GetTyped(&tpl) + singleTpl := tpl[0] + ``` ## Migration from v1.x.x to v2.x.x diff --git a/boxerror_test.go b/boxerror_test.go index acb051d31..1aa32a74f 100644 --- a/boxerror_test.go +++ b/boxerror_test.go @@ -304,7 +304,7 @@ func TestErrorTypeEval(t *testing.T) { for name, testcase := range tupleCases { t.Run(name, func(t *testing.T) { - data, err := conn.Eval("return ...", []interface{}{&testcase.tuple.val}) + data, err := conn.Do(NewEvalRequest("return ...").Args([]interface{}{&testcase.tuple.val})).Get() require.Nil(t, err) require.NotNil(t, data) require.Equal(t, len(data), 1) @@ -324,7 +324,9 @@ func TestErrorTypeEvalTyped(t *testing.T) { for name, testcase := range tupleCases { t.Run(name, func(t *testing.T) { var res []BoxError - err := conn.EvalTyped("return ...", []interface{}{&testcase.tuple.val}, &res) + err := conn.Do(NewEvalRequest("return ..."). + Args([]interface{}{&testcase.tuple.val}), + ).GetTyped(&res) require.Nil(t, err) require.NotNil(t, res) require.Equal(t, len(res), 1) @@ -340,12 +342,12 @@ func TestErrorTypeInsert(t *testing.T) { defer conn.Close() truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space) - _, err := conn.Eval(truncateEval, []interface{}{}) + _, err := conn.Do(NewEvalRequest(truncateEval).Args([]interface{}{})).Get() require.Nil(t, err) for name, testcase := range tupleCases { t.Run(name, func(t *testing.T) { - _, err = conn.Insert(space, &testcase.tuple) + _, err = conn.Do(NewInsertRequest(space).Tuple(&testcase.tuple)).Get() require.Nil(t, err) checkEval := fmt.Sprintf(` @@ -365,7 +367,7 @@ func TestErrorTypeInsert(t *testing.T) { // of connector BoxError are equal to the Tarantool ones // since they may differ between different Tarantool versions // and editions. - _, err := conn.Eval(checkEval, []interface{}{}) + _, err := conn.Do(NewEvalRequest(checkEval).Args([]interface{}{})).Get() require.Nilf(t, err, "Tuple has been successfully inserted") }) } @@ -378,13 +380,13 @@ func TestErrorTypeInsertTyped(t *testing.T) { defer conn.Close() truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space) - _, err := conn.Eval(truncateEval, []interface{}{}) + _, err := conn.Do(NewEvalRequest(truncateEval).Args([]interface{}{})).Get() require.Nil(t, err) for name, testcase := range tupleCases { t.Run(name, func(t *testing.T) { var res []TupleBoxError - err = conn.InsertTyped(space, &testcase.tuple, &res) + err = conn.Do(NewInsertRequest(space).Tuple(&testcase.tuple)).GetTyped(&res) require.Nil(t, err) require.NotNil(t, res) require.Equal(t, len(res), 1) @@ -407,7 +409,7 @@ func TestErrorTypeInsertTyped(t *testing.T) { // of connector BoxError are equal to the Tarantool ones // since they may differ between different Tarantool versions // and editions. - _, err := conn.Eval(checkEval, []interface{}{}) + _, err := conn.Do(NewEvalRequest(checkEval).Args([]interface{}{})).Get() require.Nilf(t, err, "Tuple has been successfully inserted") }) } @@ -420,7 +422,7 @@ func TestErrorTypeSelect(t *testing.T) { defer conn.Close() truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space) - _, err := conn.Eval(truncateEval, []interface{}{}) + _, err := conn.Do(NewEvalRequest(truncateEval).Args([]interface{}{})).Get() require.Nil(t, err) for name, testcase := range tupleCases { @@ -433,13 +435,18 @@ func TestErrorTypeSelect(t *testing.T) { assert(tuple ~= nil) `, testcase.ttObj, space, testcase.tuple.pk) - _, err := conn.Eval(insertEval, []interface{}{}) + _, err := conn.Do(NewEvalRequest(insertEval).Args([]interface{}{})).Get() require.Nilf(t, err, "Tuple has been successfully inserted") var offset uint32 = 0 var limit uint32 = 1 - data, err := conn.Select(space, index, offset, limit, IterEq, - []interface{}{testcase.tuple.pk}) + data, err := conn.Do(NewSelectRequest(space). + Index(index). + Offset(offset). + Limit(limit). + Iterator(IterEq). + Key([]interface{}{testcase.tuple.pk}), + ).Get() require.Nil(t, err) require.NotNil(t, data) require.Equalf(t, len(data), 1, "Exactly one tuple had been found") @@ -464,7 +471,7 @@ func TestErrorTypeSelectTyped(t *testing.T) { defer conn.Close() truncateEval := fmt.Sprintf("box.space[%q]:truncate()", space) - _, err := conn.Eval(truncateEval, []interface{}{}) + _, err := conn.Do(NewEvalRequest(truncateEval).Args([]interface{}{})).Get() require.Nil(t, err) for name, testcase := range tupleCases { @@ -477,14 +484,19 @@ func TestErrorTypeSelectTyped(t *testing.T) { assert(tuple ~= nil) `, testcase.ttObj, space, testcase.tuple.pk) - _, err := conn.Eval(insertEval, []interface{}{}) + _, err := conn.Do(NewEvalRequest(insertEval).Args([]interface{}{})).Get() require.Nilf(t, err, "Tuple has been successfully inserted") var offset uint32 = 0 var limit uint32 = 1 var resp []TupleBoxError - err = conn.SelectTyped(space, index, offset, limit, IterEq, - []interface{}{testcase.tuple.pk}, &resp) + err = conn.Do(NewSelectRequest(space). + Index(index). + Offset(offset). + Limit(limit). + Iterator(IterEq). + Key([]interface{}{testcase.tuple.pk}), + ).GetTyped(&resp) require.Nil(t, err) require.NotNil(t, resp) require.Equalf(t, len(resp), 1, "Exactly one tuple had been found") diff --git a/connection.go b/connection.go index 62829772c..483dbc02b 100644 --- a/connection.go +++ b/connection.go @@ -739,7 +739,7 @@ func (conn *Connection) pinger() { return case <-t.C: } - conn.Ping() + conn.Do(NewPingRequest()) } } diff --git a/request.go b/request.go index c18b3aeb2..b01e1f92c 100644 --- a/request.go +++ b/request.go @@ -103,417 +103,6 @@ func fillSearch(enc *msgpack.Encoder, spaceEnc spaceEncoder, indexEnc indexEncod return enc.Encode(key) } -// Ping sends empty request to Tarantool to check connection. -// -// Deprecated: the method will be removed in the next major version, -// use a PingRequest object + Do() instead. -func (conn *Connection) Ping() ([]interface{}, error) { - return conn.Do(NewPingRequest()).Get() -} - -// Select performs select to box space. -// -// It is equal to conn.SelectAsync(...).Get(). -// -// Deprecated: the method will be removed in the next major version, -// use a SelectRequest object + Do() instead. -func (conn *Connection) Select(space, index interface{}, offset, limit uint32, iterator Iter, - key interface{}) ([]interface{}, error) { - return conn.SelectAsync(space, index, offset, limit, iterator, key).Get() -} - -// Insert performs insertion to box space. -// Tarantool will reject Insert when tuple with same primary key exists. -// -// It is equal to conn.InsertAsync(space, tuple).Get(). -// -// Deprecated: the method will be removed in the next major version, -// use an InsertRequest object + Do() instead. -func (conn *Connection) Insert(space interface{}, tuple interface{}) ([]interface{}, error) { - return conn.InsertAsync(space, tuple).Get() -} - -// Replace performs "insert or replace" action to box space. -// If tuple with same primary key exists, it will be replaced. -// -// It is equal to conn.ReplaceAsync(space, tuple).Get(). -// -// Deprecated: the method will be removed in the next major version, -// use a ReplaceRequest object + Do() instead. -func (conn *Connection) Replace(space interface{}, tuple interface{}) ([]interface{}, error) { - return conn.ReplaceAsync(space, tuple).Get() -} - -// Delete performs deletion of a tuple by key. -// Result will contain array with deleted tuple. -// -// It is equal to conn.DeleteAsync(space, tuple).Get(). -// -// Deprecated: the method will be removed in the next major version, -// use a DeleteRequest object + Do() instead. -func (conn *Connection) Delete(space, index interface{}, key interface{}) ([]interface{}, error) { - return conn.DeleteAsync(space, index, key).Get() -} - -// Update performs update of a tuple by key. -// Result will contain array with updated tuple. -// -// It is equal to conn.UpdateAsync(space, tuple).Get(). -// -// Deprecated: the method will be removed in the next major version, -// use a UpdateRequest object + Do() instead. -func (conn *Connection) Update(space, index, key interface{}, - ops *Operations) ([]interface{}, error) { - return conn.UpdateAsync(space, index, key, ops).Get() -} - -// Upsert performs "update or insert" action of a tuple by key. -// Result will not contain any tuple. -// -// It is equal to conn.UpsertAsync(space, tuple, ops).Get(). -// -// Deprecated: the method will be removed in the next major version, -// use a UpsertRequest object + Do() instead. -func (conn *Connection) Upsert(space, tuple interface{}, ops *Operations) ([]interface{}, error) { - return conn.UpsertAsync(space, tuple, ops).Get() -} - -// Call calls registered Tarantool function. -// It uses request code for Tarantool >= 1.7, result is an array. -// -// It is equal to conn.CallAsync(functionName, args).Get(). -// -// Deprecated: the method will be removed in the next major version, -// use a CallRequest object + Do() instead. -func (conn *Connection) Call(functionName string, args interface{}) ([]interface{}, error) { - return conn.CallAsync(functionName, args).Get() -} - -// Call16 calls registered Tarantool function. -// 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(). -// -// Deprecated: the method will be removed in the next major version, -// use a Call16Request object + Do() instead. -func (conn *Connection) Call16(functionName string, args interface{}) ([]interface{}, error) { - return conn.Call16Async(functionName, args).Get() -} - -// Call17 calls registered Tarantool function. -// It uses request code for Tarantool >= 1.7, result is an array. -// -// It is equal to conn.Call17Async(functionName, args).Get(). -// -// Deprecated: the method will be removed in the next major version, -// use a Call17Request object + Do() instead. -func (conn *Connection) Call17(functionName string, args interface{}) ([]interface{}, error) { - return conn.Call17Async(functionName, args).Get() -} - -// Eval passes Lua expression for evaluation. -// -// It is equal to conn.EvalAsync(space, tuple).Get(). -// -// Deprecated: the method will be removed in the next major version, -// use an EvalRequest object + Do() instead. -func (conn *Connection) Eval(expr string, args interface{}) ([]interface{}, error) { - return conn.EvalAsync(expr, args).Get() -} - -// Execute passes sql expression to Tarantool for execution. -// -// It is equal to conn.ExecuteAsync(expr, args).Get(). -// Since 1.6.0 -// -// Deprecated: the method will be removed in the next major version, -// use an ExecuteRequest object + Do() instead. -func (conn *Connection) Execute(expr string, args interface{}) ([]interface{}, error) { - return conn.ExecuteAsync(expr, args).Get() -} - -// single used for conn.GetTyped for decode one tuple. -type single struct { - res interface{} - found bool -} - -func (s *single) DecodeMsgpack(d *msgpack.Decoder) error { - var err error - var len int - if len, err = d.DecodeArrayLen(); err != nil { - return err - } - if s.found = len >= 1; !s.found { - return nil - } - if len != 1 { - return errors.New("tarantool returns unexpected value for Select(limit=1)") - } - return d.Decode(s.res) -} - -// GetTyped performs select (with limit = 1 and offset = 0) -// to box space and fills typed result. -// -// It is equal to conn.SelectAsync(space, index, 0, 1, IterEq, key).GetTyped(&result) -// -// Deprecated: the method will be removed in the next major version, -// use a SelectRequest object + Do() instead. -func (conn *Connection) GetTyped(space, index interface{}, key interface{}, - result interface{}) error { - s := single{res: result} - return conn.SelectAsync(space, index, 0, 1, IterEq, key).GetTyped(&s) -} - -// SelectTyped performs select to box space and fills typed result. -// -// It is equal to conn.SelectAsync(space, index, offset, limit, iterator, key).GetTyped(&result) -// -// Deprecated: the method will be removed in the next major version, -// use a SelectRequest object + Do() instead. -func (conn *Connection) SelectTyped(space, index interface{}, offset, limit uint32, iterator Iter, - key interface{}, result interface{}) error { - return conn.SelectAsync(space, index, offset, limit, iterator, key).GetTyped(result) -} - -// InsertTyped performs insertion to box space. -// Tarantool will reject Insert when tuple with same primary key exists. -// -// It is equal to conn.InsertAsync(space, tuple).GetTyped(&result). -// -// Deprecated: the method will be removed in the next major version, -// use an InsertRequest object + Do() instead. -func (conn *Connection) InsertTyped(space interface{}, tuple interface{}, - result interface{}) error { - return conn.InsertAsync(space, tuple).GetTyped(result) -} - -// ReplaceTyped performs "insert or replace" action to box space. -// If tuple with same primary key exists, it will be replaced. -// -// It is equal to conn.ReplaceAsync(space, tuple).GetTyped(&result). -// -// Deprecated: the method will be removed in the next major version, -// use a ReplaceRequest object + Do() instead. -func (conn *Connection) ReplaceTyped(space interface{}, tuple interface{}, - result interface{}) error { - return conn.ReplaceAsync(space, tuple).GetTyped(result) -} - -// DeleteTyped performs deletion of a tuple by key and fills result with deleted tuple. -// -// It is equal to conn.DeleteAsync(space, tuple).GetTyped(&result). -// -// Deprecated: the method will be removed in the next major version, -// use a DeleteRequest object + Do() instead. -func (conn *Connection) DeleteTyped(space, index interface{}, key interface{}, - result interface{}) error { - return conn.DeleteAsync(space, index, key).GetTyped(result) -} - -// UpdateTyped performs update of a tuple by key and fills result with updated tuple. -// -// It is equal to conn.UpdateAsync(space, tuple, ops).GetTyped(&result). -// -// Deprecated: the method will be removed in the next major version, -// use a UpdateRequest object + Do() instead. -func (conn *Connection) UpdateTyped(space, index interface{}, key interface{}, - ops *Operations, result interface{}) error { - return conn.UpdateAsync(space, index, key, ops).GetTyped(result) -} - -// CallTyped calls registered function. -// It uses request code for Tarantool >= 1.7, result is an array. -// -// It is equal to conn.Call16Async(functionName, args).GetTyped(&result). -// -// Deprecated: the method will be removed in the next major version, -// use a CallRequest object + Do() instead. -func (conn *Connection) CallTyped(functionName string, args interface{}, - result interface{}) error { - return conn.CallAsync(functionName, args).GetTyped(result) -} - -// Call16Typed calls registered function. -// 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). -// -// Deprecated: the method will be removed in the next major version, -// use a Call16Request object + Do() instead. -func (conn *Connection) Call16Typed(functionName string, args interface{}, - result interface{}) error { - return conn.Call16Async(functionName, args).GetTyped(result) -} - -// Call17Typed calls registered function. -// It uses request code for Tarantool >= 1.7, result is an array. -// -// It is equal to conn.Call17Async(functionName, args).GetTyped(&result). -// -// Deprecated: the method will be removed in the next major version, -// use a Call17Request object + Do() instead. -func (conn *Connection) Call17Typed(functionName string, args interface{}, - result interface{}) error { - return conn.Call17Async(functionName, args).GetTyped(result) -} - -// EvalTyped passes Lua expression for evaluation. -// -// It is equal to conn.EvalAsync(space, tuple).GetTyped(&result). -// -// Deprecated: the method will be removed in the next major version, -// use an EvalRequest object + Do() instead. -func (conn *Connection) EvalTyped(expr string, args interface{}, result interface{}) error { - return conn.EvalAsync(expr, args).GetTyped(result) -} - -// ExecuteTyped passes sql expression to Tarantool for execution. -// -// In addition to error returns sql info and columns meta data -// Since 1.6.0 -// -// Deprecated: the method will be removed in the next major version, -// use an ExecuteRequest object + Do() instead. -func (conn *Connection) ExecuteTyped(expr string, args interface{}, - result interface{}) (SQLInfo, []ColumnMetaData, error) { - var ( - sqlInfo SQLInfo - metaData []ColumnMetaData - ) - - fut := conn.ExecuteAsync(expr, args) - err := fut.GetTyped(&result) - if resp, ok := fut.resp.(*ExecuteResponse); ok { - sqlInfo = resp.sqlInfo - metaData = resp.metaData - } else if err == nil { - err = fmt.Errorf("unexpected response type %T, want: *ExecuteResponse", fut.resp) - } - return sqlInfo, metaData, err -} - -// SelectAsync sends select request to Tarantool and returns Future. -// -// Deprecated: the method will be removed in the next major version, -// use a SelectRequest object + Do() instead. -func (conn *Connection) SelectAsync(space, index interface{}, offset, limit uint32, iterator Iter, - key interface{}) *Future { - req := NewSelectRequest(space). - Index(index). - Offset(offset). - Limit(limit). - Iterator(iterator). - Key(key) - return conn.Do(req) -} - -// InsertAsync sends insert action to Tarantool and returns Future. -// Tarantool will reject Insert when tuple with same primary key exists. -// -// Deprecated: the method will be removed in the next major version, -// use an InsertRequest object + Do() instead. -func (conn *Connection) InsertAsync(space interface{}, tuple interface{}) *Future { - req := NewInsertRequest(space).Tuple(tuple) - return conn.Do(req) -} - -// ReplaceAsync sends "insert or replace" action to Tarantool and returns Future. -// If tuple with same primary key exists, it will be replaced. -// -// Deprecated: the method will be removed in the next major version, -// use a ReplaceRequest object + Do() instead. -func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Future { - req := NewReplaceRequest(space).Tuple(tuple) - return conn.Do(req) -} - -// DeleteAsync sends deletion action to Tarantool and returns Future. -// Future's result will contain array with deleted tuple. -// -// Deprecated: the method will be removed in the next major version, -// use a DeleteRequest object + Do() instead. -func (conn *Connection) DeleteAsync(space, index interface{}, key interface{}) *Future { - req := NewDeleteRequest(space).Index(index).Key(key) - return conn.Do(req) -} - -// Update sends deletion of a tuple by key and returns Future. -// Future's result will contain array with updated tuple. -// -// Deprecated: the method will be removed in the next major version, -// use a UpdateRequest object + Do() instead. -func (conn *Connection) UpdateAsync(space, index interface{}, key interface{}, - ops *Operations) *Future { - req := NewUpdateRequest(space).Index(index).Key(key) - req.ops = ops - return conn.Do(req) -} - -// UpsertAsync sends "update or insert" action to Tarantool and returns Future. -// Future's sesult will not contain any tuple. -// -// Deprecated: the method will be removed in the next major version, -// use a UpsertRequest object + Do() instead. -func (conn *Connection) UpsertAsync(space, tuple interface{}, ops *Operations) *Future { - req := NewUpsertRequest(space).Tuple(tuple) - req.ops = ops - return conn.Do(req) -} - -// CallAsync sends a call to registered Tarantool function and returns Future. -// It uses request code for Tarantool >= 1.7, so future's result is an array. -// -// Deprecated: the method will be removed in the next major version, -// use a CallRequest object + Do() instead. -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 an array of arrays. -// Deprecated since Tarantool 1.7.2. -// -// Deprecated: the method will be removed in the next major version, -// use a Call16Request object + Do() instead. -func (conn *Connection) Call16Async(functionName string, args interface{}) *Future { - req := NewCall16Request(functionName).Args(args) - return conn.Do(req) -} - -// Call17Async sends a call to registered Tarantool function and returns Future. -// It uses request code for Tarantool >= 1.7, so future's result is an array. -// -// Deprecated: the method will be removed in the next major version, -// use a Call17Request object + Do() instead. -func (conn *Connection) Call17Async(functionName string, args interface{}) *Future { - req := NewCall17Request(functionName).Args(args) - return conn.Do(req) -} - -// EvalAsync sends a Lua expression for evaluation and returns Future. -// -// Deprecated: the method will be removed in the next major version, -// use an EvalRequest object + Do() instead. -func (conn *Connection) EvalAsync(expr string, args interface{}) *Future { - req := NewEvalRequest(expr).Args(args) - return conn.Do(req) -} - -// ExecuteAsync sends a sql expression for execution and returns Future. -// Since 1.6.0 -// -// Deprecated: the method will be removed in the next major version, -// use an ExecuteRequest object + Do() instead. -func (conn *Connection) ExecuteAsync(expr string, args interface{}) *Future { - req := NewExecuteRequest(expr).Args(args) - return conn.Do(req) -} - // KeyValueBind is a type for encoding named SQL parameters type KeyValueBind struct { Key string diff --git a/shutdown_test.go b/shutdown_test.go index 434600824..2b7be538a 100644 --- a/shutdown_test.go +++ b/shutdown_test.go @@ -53,7 +53,9 @@ func testGracefulShutdown(t *testing.T, conn *Connection, inst *test_helpers.Tar // Set a big timeout so it would be easy to differ // if server went down on timeout or after all connections were terminated. serverShutdownTimeout := 60 // in seconds - _, err = conn.Call("box.ctl.set_on_shutdown_timeout", []interface{}{serverShutdownTimeout}) + _, err = conn.Do(NewCallRequest("box.ctl.set_on_shutdown_timeout"). + Args([]interface{}{serverShutdownTimeout}), + ).Get() require.Nil(t, err) // Send request with sleep. @@ -284,7 +286,9 @@ func TestGracefulShutdownRespectsClose(t *testing.T) { // Set a big timeout so it would be easy to differ // if server went down on timeout or after all connections were terminated. serverShutdownTimeout := 60 // in seconds - _, err = conn.Call("box.ctl.set_on_shutdown_timeout", []interface{}{serverShutdownTimeout}) + _, err = conn.Do(NewCallRequest("box.ctl.set_on_shutdown_timeout"). + Args([]interface{}{serverShutdownTimeout}), + ).Get() require.Nil(t, err) // Send request with sleep. @@ -358,7 +362,9 @@ func TestGracefulShutdownNotRacesWithRequestReconnect(t *testing.T) { // Set a small timeout so server will shutdown before requesst finishes. serverShutdownTimeout := 1 // in seconds - _, err = conn.Call("box.ctl.set_on_shutdown_timeout", []interface{}{serverShutdownTimeout}) + _, err = conn.Do(NewCallRequest("box.ctl.set_on_shutdown_timeout"). + Args([]interface{}{serverShutdownTimeout}), + ).Get() require.Nil(t, err) // Send request with sleep. @@ -425,7 +431,9 @@ func TestGracefulShutdownCloseConcurrent(t *testing.T) { // Set a big timeout so it would be easy to differ // if server went down on timeout or after all connections were terminated. serverShutdownTimeout := 60 // in seconds - _, err = conn.Call("box.ctl.set_on_shutdown_timeout", []interface{}{serverShutdownTimeout}) + _, err = conn.Do(NewCallRequest("box.ctl.set_on_shutdown_timeout"). + Args([]interface{}{serverShutdownTimeout}), + ).Get() require.Nil(t, err) conn.Close() @@ -500,7 +508,9 @@ func TestGracefulShutdownConcurrent(t *testing.T) { // Set a big timeout so it would be easy to differ // if server went down on timeout or after all connections were terminated. serverShutdownTimeout := 60 // in seconds - _, err = conn.Call("box.ctl.set_on_shutdown_timeout", []interface{}{serverShutdownTimeout}) + _, err = conn.Do(NewCallRequest("box.ctl.set_on_shutdown_timeout"). + Args([]interface{}{serverShutdownTimeout}), + ).Get() require.Nil(t, err) conn.Close() diff --git a/tarantool_test.go b/tarantool_test.go index 5bf790ced..46289bf23 100644 --- a/tarantool_test.go +++ b/tarantool_test.go @@ -528,7 +528,7 @@ func TestFutureMultipleGetGetTyped(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, dialer, opts) defer conn.Close() - fut := conn.Call17Async("simple_concat", []interface{}{"1"}) + fut := conn.Do(NewCall17Request("simple_concat").Args([]interface{}{"1"})) for i := 0; i < 30; i++ { // [0, 10) fut.Get() @@ -566,7 +566,7 @@ func TestFutureMultipleGetWithError(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, dialer, opts) defer conn.Close() - fut := conn.Call17Async("non_exist", []interface{}{"1"}) + fut := conn.Do(NewCall17Request("non_exist").Args([]interface{}{"1"})) for i := 0; i < 2; i++ { if _, err := fut.Get(); err == nil { @@ -579,7 +579,7 @@ func TestFutureMultipleGetTypedWithError(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, dialer, opts) defer conn.Close() - fut := conn.Call17Async("simple_concat", []interface{}{"1"}) + fut := conn.Do(NewCall17Request("simple_concat").Args([]interface{}{"1"})) wrongTpl := struct { Val int @@ -602,13 +602,17 @@ func TestFutureMultipleGetTypedWithError(t *testing.T) { // ///////////////// func TestClient(t *testing.T) { - var err error - conn := test_helpers.ConnectWithValidation(t, dialer, opts) defer conn.Close() + var ( + req Request + err error + ) + // Ping - data, err := conn.Ping() + req = NewPingRequest() + data, err := conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Ping: %s", err) } @@ -617,7 +621,8 @@ func TestClient(t *testing.T) { } // Insert - data, err = conn.Insert(spaceNo, []interface{}{uint(1), "hello", "world"}) + req = NewInsertRequest(spaceNo).Tuple([]interface{}{uint(1), "hello", "world"}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Insert: %s", err) } @@ -637,7 +642,8 @@ func TestClient(t *testing.T) { t.Errorf("Unexpected body of Insert (1)") } } - data, err = conn.Insert(spaceNo, &Tuple{Id: 1, Msg: "hello", Name: "world"}) + req = NewInsertRequest(spaceNo).Tuple(&Tuple{Id: 1, Msg: "hello", Name: "world"}) + data, err = conn.Do(req).Get() if tntErr, ok := err.(Error); !ok || tntErr.Code != iproto.ER_TUPLE_FOUND { t.Errorf("Expected %s but got: %v", iproto.ER_TUPLE_FOUND, err) } @@ -646,7 +652,8 @@ func TestClient(t *testing.T) { } // Delete - data, err = conn.Delete(spaceNo, indexNo, []interface{}{uint(1)}) + req = NewDeleteRequest(spaceNo).Index(indexNo).Key([]interface{}{uint(1)}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Delete: %s", err) } @@ -666,7 +673,8 @@ func TestClient(t *testing.T) { t.Errorf("Unexpected body of Delete (1)") } } - data, err = conn.Delete(spaceNo, indexNo, []interface{}{uint(101)}) + req = NewDeleteRequest(spaceNo).Index(indexNo).Key([]interface{}{uint(101)}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Delete: %s", err) } @@ -675,14 +683,16 @@ func TestClient(t *testing.T) { } // Replace - data, err = conn.Replace(spaceNo, []interface{}{uint(2), "hello", "world"}) + req = NewReplaceRequest(spaceNo).Tuple([]interface{}{uint(2), "hello", "world"}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Replace: %s", err) } if data == nil { t.Fatalf("Response is nil after Replace") } - data, err = conn.Replace(spaceNo, []interface{}{uint(2), "hi", "planet"}) + req = NewReplaceRequest(spaceNo).Tuple([]interface{}{uint(2), "hi", "planet"}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Replace (duplicate): %s", err) } @@ -704,8 +714,11 @@ func TestClient(t *testing.T) { } // Update - data, err = conn.Update(spaceNo, indexNo, []interface{}{uint(2)}, - NewOperations().Assign(1, "bye").Delete(2, 1)) + req = NewUpdateRequest(spaceNo). + Index(indexNo). + Key([]interface{}{uint(2)}). + Operations(NewOperations().Assign(1, "bye").Delete(2, 1)) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Update: %s", err) } @@ -727,16 +740,20 @@ func TestClient(t *testing.T) { } // Upsert - data, err = conn.Upsert(spaceNo, []interface{}{uint(3), 1}, - NewOperations().Add(1, 1)) + req = NewUpsertRequest(spaceNo). + Tuple([]interface{}{uint(3), 1}). + Operations(NewOperations().Add(1, 1)) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Upsert (insert): %s", err) } if data == nil { t.Fatalf("Response is nil after Upsert (insert)") } - data, err = conn.Upsert(spaceNo, []interface{}{uint(3), 1}, - NewOperations().Add(1, 1)) + req = NewUpsertRequest(spaceNo). + Tuple([]interface{}{uint(3), 1}). + Operations(NewOperations().Add(1, 1)) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Upsert (update): %s", err) } @@ -746,7 +763,8 @@ func TestClient(t *testing.T) { // Select for i := 10; i < 20; i++ { - data, err = conn.Replace(spaceNo, []interface{}{uint(i), fmt.Sprintf("val %d", i), "bla"}) + req = NewReplaceRequest(spaceNo).Tuple([]interface{}{uint(i), fmt.Sprintf("val %d", i), "bla"}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Replace: %s", err) } @@ -754,7 +772,13 @@ func TestClient(t *testing.T) { t.Errorf("Response is nil after Replace") } } - data, err = conn.Select(spaceNo, indexNo, 0, 1, IterEq, []interface{}{uint(10)}) + req = NewSelectRequest(spaceNo). + Index(indexNo). + Offset(0). + Limit(1). + Iterator(IterEq). + Key([]interface{}{uint(10)}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Select: %s", err) } @@ -773,7 +797,13 @@ func TestClient(t *testing.T) { } // Select empty - data, err = conn.Select(spaceNo, indexNo, 0, 1, IterEq, []interface{}{uint(30)}) + req = NewSelectRequest(spaceNo). + Index(indexNo). + Offset(0). + Limit(1). + Iterator(IterEq). + Key([]interface{}{uint(30)}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Select: %s", err) } @@ -783,7 +813,13 @@ func TestClient(t *testing.T) { // Select Typed var tpl []Tuple - err = conn.SelectTyped(spaceNo, indexNo, 0, 1, IterEq, []interface{}{uint(10)}, &tpl) + req = NewSelectRequest(spaceNo). + Index(indexNo). + Offset(0). + Limit(1). + Iterator(IterEq). + Key([]interface{}{uint(10)}) + err = conn.Do(req).GetTyped(&tpl) if err != nil { t.Fatalf("Failed to SelectTyped: %s", err) } @@ -793,31 +829,34 @@ func TestClient(t *testing.T) { t.Errorf("Bad value loaded from SelectTyped") } - // Get Typed - var singleTpl = Tuple{} - err = conn.GetTyped(spaceNo, indexNo, []interface{}{uint(10)}, &singleTpl) - if err != nil { - t.Fatalf("Failed to GetTyped: %s", err) - } - if singleTpl.Id != 10 { - t.Errorf("Bad value loaded from GetTyped") - } - // Select Typed for one tuple var tpl1 [1]Tuple - err = conn.SelectTyped(spaceNo, indexNo, 0, 1, IterEq, []interface{}{uint(10)}, &tpl1) + req = NewSelectRequest(spaceNo). + Index(indexNo). + Offset(0). + Limit(1). + Iterator(IterEq). + Key([]interface{}{uint(10)}) + err = conn.Do(req).GetTyped(&tpl1) + singleTpl := tpl[0] if err != nil { t.Fatalf("Failed to SelectTyped: %s", err) } if len(tpl) != 1 { t.Errorf("Result len of SelectTyped != 1") - } else if tpl[0].Id != 10 { + } else if singleTpl.Id != 10 { t.Errorf("Bad value loaded from SelectTyped") } // Get Typed Empty var singleTpl2 Tuple - err = conn.GetTyped(spaceNo, indexNo, []interface{}{uint(30)}, &singleTpl2) + req = NewSelectRequest(spaceNo). + Index(indexNo). + Offset(0). + Limit(1). + Iterator(IterEq). + Key([]interface{}{uint(30)}) + err = conn.Do(req).GetTyped(&singleTpl2) if err != nil { t.Fatalf("Failed to GetTyped: %s", err) } @@ -827,7 +866,13 @@ func TestClient(t *testing.T) { // Select Typed Empty var tpl2 []Tuple - err = conn.SelectTyped(spaceNo, indexNo, 0, 1, IterEq, []interface{}{uint(30)}, &tpl2) + req = NewSelectRequest(spaceNo). + Index(indexNo). + Offset(0). + Limit(1). + Iterator(IterEq). + Key([]interface{}{uint(30)}) + err = conn.Do(req).GetTyped(&tpl2) if err != nil { t.Fatalf("Failed to SelectTyped: %s", err) } @@ -836,7 +881,8 @@ func TestClient(t *testing.T) { } // Call16 - data, err = conn.Call16("box.info", []interface{}{"box.schema.SPACE_ID"}) + req = NewCall16Request("box.info").Args([]interface{}{"box.schema.SPACE_ID"}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Call16: %s", err) } @@ -845,7 +891,8 @@ func TestClient(t *testing.T) { } // Call16 vs Call17 - data, err = conn.Call16("simple_concat", []interface{}{"1"}) + req = NewCall16Request("simple_concat").Args([]interface{}{"1"}) + data, err = conn.Do(req).Get() if err != nil { t.Errorf("Failed to use Call16") } @@ -853,7 +900,8 @@ func TestClient(t *testing.T) { t.Errorf("result is not {{1}} : %v", data) } - data, err = conn.Call17("simple_concat", []interface{}{"1"}) + req = NewCall17Request("simple_concat").Args([]interface{}{"1"}) + data, err = conn.Do(req).Get() if err != nil { t.Errorf("Failed to use Call") } @@ -862,7 +910,8 @@ func TestClient(t *testing.T) { } // Eval - data, err = conn.Eval("return 5 + 6", []interface{}{}) + req = NewEvalRequest("return 5 + 6").Args([]interface{}{}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Eval: %s", err) } @@ -1069,7 +1118,19 @@ func TestSQLTyped(t *testing.T) { defer conn.Close() mem := []Member{} - info, meta, err := conn.ExecuteTyped(selectTypedQuery, []interface{}{1}, &mem) + fut := conn.Do(NewExecuteRequest(selectTypedQuery). + Args([]interface{}{1}), + ) + fut.GetTyped(&mem) + resp, err := fut.GetResponse() + assert.NoError(t, err, "Error while getting Response") + exResp, ok := resp.(*ExecuteResponse) + assert.True(t, ok, "Got wrong response type") + + info, err := exResp.SQLInfo() + assert.NoError(t, err, "Error while getting SQLInfo") + meta, err := exResp.MetaData() + assert.NoError(t, err, "Error while getting MetaData") if info.AffectedCount != 0 { t.Errorf("Rows affected count must be 0") } @@ -1718,8 +1779,15 @@ func TestClientNamed(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, dialer, opts) defer conn.Close() + var ( + req Request + data []interface{} + err error + ) + // Insert - data, err := conn.Insert(spaceName, []interface{}{uint(1001), "hello2", "world2"}) + req = NewInsertRequest(spaceName).Tuple([]interface{}{uint(1001), "hello2", "world2"}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Insert: %s", err) } @@ -1728,7 +1796,8 @@ func TestClientNamed(t *testing.T) { } // Delete - data, err = conn.Delete(spaceName, indexName, []interface{}{uint(1001)}) + req = NewDeleteRequest(spaceName).Index(indexName).Key([]interface{}{uint(1001)}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Delete: %s", err) } @@ -1737,7 +1806,8 @@ func TestClientNamed(t *testing.T) { } // Replace - data, err = conn.Replace(spaceName, []interface{}{uint(1002), "hello", "world"}) + req = NewReplaceRequest(spaceName).Tuple([]interface{}{uint(1002), "hello", "world"}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Replace: %s", err) } @@ -1746,10 +1816,11 @@ func TestClientNamed(t *testing.T) { } // Update - data, err = conn.Update(spaceName, indexName, - []interface{}{ - uint(1002)}, - NewOperations().Assign(1, "buy").Delete(2, 1)) + req = NewUpdateRequest(spaceName). + Index(indexName). + Key([]interface{}{uint(1002)}). + Operations(NewOperations().Assign(1, "buy").Delete(2, 1)) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Update: %s", err) } @@ -1758,16 +1829,21 @@ func TestClientNamed(t *testing.T) { } // Upsert - data, err = conn.Upsert(spaceName, - []interface{}{uint(1003), 1}, NewOperations().Add(1, 1)) + req = NewUpsertRequest(spaceName). + Tuple([]interface{}{uint(1003), 1}). + Operations(NewOperations().Add(1, 1)) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Upsert (insert): %s", err) } if data == nil { t.Errorf("Response is nil after Upsert (insert)") } - data, err = conn.Upsert(spaceName, - []interface{}{uint(1003), 1}, NewOperations().Add(1, 1)) + + req = NewUpsertRequest(spaceName). + Tuple([]interface{}{uint(1003), 1}). + Operations(NewOperations().Add(1, 1)) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Upsert (update): %s", err) } @@ -1777,8 +1853,9 @@ func TestClientNamed(t *testing.T) { // Select for i := 1010; i < 1020; i++ { - data, err = conn.Replace(spaceName, - []interface{}{uint(i), fmt.Sprintf("val %d", i), "bla"}) + req = NewReplaceRequest(spaceName). + Tuple([]interface{}{uint(i), fmt.Sprintf("val %d", i), "bla"}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Replace: %s", err) } @@ -1786,7 +1863,13 @@ func TestClientNamed(t *testing.T) { t.Errorf("Response is nil after Replace") } } - data, err = conn.Select(spaceName, indexName, 0, 1, IterEq, []interface{}{uint(1010)}) + req = NewSelectRequest(spaceName). + Index(indexName). + Offset(0). + Limit(1). + Iterator(IterEq). + Key([]interface{}{uint(1010)}) + data, err = conn.Do(req).Get() if err != nil { t.Fatalf("Failed to Select: %s", err) } @@ -1796,7 +1879,13 @@ func TestClientNamed(t *testing.T) { // Select Typed var tpl []Tuple - err = conn.SelectTyped(spaceName, indexName, 0, 1, IterEq, []interface{}{uint(1010)}, &tpl) + req = NewSelectRequest(spaceName). + Index(indexName). + Offset(0). + Limit(1). + Iterator(IterEq). + Key([]interface{}{uint(1010)}) + err = conn.Do(req).GetTyped(&tpl) if err != nil { t.Fatalf("Failed to SelectTyped: %s", err) } @@ -1826,7 +1915,7 @@ func TestClientRequestObjects(t *testing.T) { // The code prepares data. for i := 1010; i < 1020; i++ { - conn.Delete(spaceName, nil, []interface{}{uint(i)}) + conn.Do(NewDeleteRequest(spaceName).Index(nil).Key([]interface{}{uint(i)})) } // Insert @@ -2274,19 +2363,6 @@ func TestConnectionDoSelectRequest_pagination_pos(t *testing.T) { testConnectionDoSelectRequestCheck(t, selResp, err, true, 2, 1012) } -func TestConnection_Call(t *testing.T) { - conn := test_helpers.ConnectWithValidation(t, dialer, opts) - defer conn.Close() - - data, err := conn.Call("simple_concat", []interface{}{"1"}) - if err != nil { - t.Errorf("Failed to use Call") - } - if val, ok := data[0].(string); !ok || val != "11" { - t.Errorf("result is not {{1}} : %v", data) - } -} - func TestCallRequest(t *testing.T) { var err error @@ -2446,13 +2522,18 @@ func TestComplexStructs(t *testing.T) { defer conn.Close() tuple := Tuple2{Cid: 777, Orig: "orig", Members: []Member{{"lol", "", 1}, {"wut", "", 3}}} - _, err = conn.Replace(spaceNo, &tuple) + _, err = conn.Do(NewReplaceRequest(spaceNo).Tuple(&tuple)).Get() if err != nil { t.Fatalf("Failed to insert: %s", err) } var tuples [1]Tuple2 - err = conn.SelectTyped(spaceNo, indexNo, 0, 1, IterEq, []interface{}{777}, &tuples) + err = conn.Do(NewSelectRequest(spaceNo). + Index(indexNo). + Limit(1). + Iterator(IterEq). + Key([]interface{}{777}), + ).GetTyped(&tuples) if err != nil { t.Fatalf("Failed to selectTyped: %s", err) } @@ -3072,7 +3153,7 @@ func TestErrorExtendedInfoBasic(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, dialer, opts) defer conn.Close() - _, err := conn.Eval("not a Lua code", []interface{}{}) + _, err := conn.Do(NewEvalRequest("not a Lua code").Args([]interface{}{})).Get() require.NotNilf(t, err, "expected error on invalid Lua code") ttErr, ok := err.(Error) @@ -3100,7 +3181,7 @@ func TestErrorExtendedInfoStack(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, dialer, opts) defer conn.Close() - _, err := conn.Eval("error(chained_error)", []interface{}{}) + _, err := conn.Do(NewEvalRequest("error(chained_error)").Args([]interface{}{})).Get() require.NotNilf(t, err, "expected error on explicit error raise") ttErr, ok := err.(Error) @@ -3136,7 +3217,7 @@ func TestErrorExtendedInfoFields(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, dialer, opts) defer conn.Close() - _, err := conn.Eval("error(access_denied_error)", []interface{}{}) + _, err := conn.Do(NewEvalRequest("error(access_denied_error)").Args([]interface{}{})).Get() require.NotNilf(t, err, "expected error on forbidden action") ttErr, ok := err.(Error) @@ -3839,7 +3920,7 @@ func TestFdDialer(t *testing.T) { `, sidecarExe) var resp []interface{} - err = conn.EvalTyped(evalBody, []interface{}{}, &resp) + err = conn.Do(NewEvalRequest(evalBody).Args([]interface{}{})).GetTyped(&resp) require.NoError(t, err) require.Equal(t, "", resp[1], resp[1]) require.Equal(t, "", resp[2], resp[2])