diff --git a/CHANGELOG.md b/CHANGELOG.md index f0cc0b40a..2ad37cad0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release. ### Added +- Rename `Call` to `Call16` and `Call17` to `Call` (#125) - Coveralls support (#149) - Reusable testing workflow (integration testing with latest Tarantool) (#123) - Simple CI based on GitHub actions (#114) diff --git a/connection.go b/connection.go index d8e381364..3e1584740 100644 --- a/connection.go +++ b/connection.go @@ -111,9 +111,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 diff --git a/connector.go b/connector.go index d6d87eaca..977e718cb 100644 --- a/connector.go +++ b/connector.go @@ -14,8 +14,8 @@ type Connector interface { Delete(space, index interface{}, key interface{}) (resp *Response, err error) Update(space, index interface{}, key, ops interface{}) (resp *Response, err error) Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error) + Call16(functionName string, args interface{}) (resp *Response, err error) Call(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) GetTyped(space, index interface{}, key interface{}, result interface{}) (err error) @@ -24,8 +24,8 @@ type Connector interface { ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error) DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error) + Call16Typed(functionName string, args interface{}, result interface{}) (err error) CallTyped(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) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *Future @@ -34,7 +34,7 @@ type Connector interface { DeleteAsync(space, index interface{}, key interface{}) *Future UpdateAsync(space, index interface{}, key, ops interface{}) *Future UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future + Call16Async(functionName string, args interface{}) *Future CallAsync(functionName string, args interface{}) *Future - Call17Async(functionName string, args interface{}) *Future EvalAsync(expr string, args interface{}) *Future } diff --git a/const.go b/const.go index 03b00c6b1..7ddc0e6a8 100644 --- a/const.go +++ b/const.go @@ -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 + CallRequest = 10 /* call in 1.7 format */ PingRequest = 64 SubscribeRequest = 66 diff --git a/example_custom_unpacking_test.go b/example_custom_unpacking_test.go index 772c9faf3..b50dd9659 100644 --- a/example_custom_unpacking_test.go +++ b/example_custom_unpacking_test.go @@ -117,7 +117,7 @@ func Example_customUnpacking() { fmt.Println("Tuples (tuples2):", tuples2) // Call a function "func_name" returning a table of custom tuples. - var tuples3 []Tuple3 + var tuples3 [][]Tuple3 err = conn.CallTyped("func_name", []interface{}{}, &tuples3) if err != nil { log.Fatalf("Failed to CallTyped: %s", err.Error()) @@ -130,6 +130,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}]}]] } diff --git a/example_test.go b/example_test.go index 1e8c883ab..4b72c706e 100644 --- a/example_test.go +++ b/example_test.go @@ -253,12 +253,12 @@ func ExampleConnection_Update() { // Data [[14 bye bla]] } -func ExampleConnection_Call17() { +func ExampleConnection_Call() { conn := example_connect() defer conn.Close() // Call a function 'simple_incr' with arguments. - resp, err := conn.Call17("simple_incr", []interface{}{1}) + resp, err := conn.Call("simple_incr", []interface{}{1}) fmt.Println("Call simple_incr()") fmt.Println("Error", err) fmt.Println("Code", resp.Code) diff --git a/multi/multi.go b/multi/multi.go index c83010c36..8b34f73c2 100644 --- a/multi/multi.go +++ b/multi/multi.go @@ -186,7 +186,7 @@ func (connMulti *ConnectionMulti) checker() { continue } var resp [][]string - err := connMulti.Call17Typed(connMulti.opts.NodesGetFunctionName, []interface{}{}, &resp) + err := connMulti.CallTyped(connMulti.opts.NodesGetFunctionName, []interface{}{}, &resp) if err != nil { continue } @@ -321,18 +321,18 @@ func (connMulti *ConnectionMulti) Upsert(space interface{}, tuple, ops interface return connMulti.getCurrentConnection().Upsert(space, tuple, ops) } -// Call calls registered Tarantool function. +// Call16 calls registered Tarantool function. // It uses request code for Tarantool 1.6, so result is converted to array of // arrays. -func (connMulti *ConnectionMulti) Call(functionName string, args interface{}) (resp *tarantool.Response, err error) { - return connMulti.getCurrentConnection().Call(functionName, args) +func (connMulti *ConnectionMulti) Call16(functionName string, args interface{}) (resp *tarantool.Response, err error) { + return connMulti.getCurrentConnection().Call16(functionName, args) } -// Call17 calls registered Tarantool function. +// Call 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). -func (connMulti *ConnectionMulti) Call17(functionName string, args interface{}) (resp *tarantool.Response, err error) { - return connMulti.getCurrentConnection().Call17(functionName, args) +func (connMulti *ConnectionMulti) Call(functionName string, args interface{}) (resp *tarantool.Response, err error) { + return connMulti.getCurrentConnection().Call(functionName, args) } // Eval passes Lua expression for evaluation. @@ -375,18 +375,18 @@ func (connMulti *ConnectionMulti) UpdateTyped(space, index interface{}, key, ops return connMulti.getCurrentConnection().UpdateTyped(space, index, key, ops, result) } -// CallTyped calls registered function. +// Call16Typed calls registered function. // It uses request code for Tarantool 1.6, so result is converted to array of // arrays. -func (connMulti *ConnectionMulti) CallTyped(functionName string, args interface{}, result interface{}) (err error) { - return connMulti.getCurrentConnection().CallTyped(functionName, args, result) +func (connMulti *ConnectionMulti) Call16Typed(functionName string, args interface{}, result interface{}) (err error) { + return connMulti.getCurrentConnection().Call16Typed(functionName, args, result) } -// Call17Typed calls registered function. +// CallTyped calls registered function. // It uses request code for Tarantool 1.7, so result is not converted (though, // keep in mind, result is always array) -func (connMulti *ConnectionMulti) Call17Typed(functionName string, args interface{}, result interface{}) (err error) { - return connMulti.getCurrentConnection().Call17Typed(functionName, args, result) +func (connMulti *ConnectionMulti) CallTyped(functionName string, args interface{}, result interface{}) (err error) { + return connMulti.getCurrentConnection().CallTyped(functionName, args, result) } // EvalTyped passes Lua expression for evaluation. @@ -429,18 +429,18 @@ func (connMulti *ConnectionMulti) UpsertAsync(space interface{}, tuple interface return connMulti.getCurrentConnection().UpsertAsync(space, tuple, ops) } -// CallAsync sends a call to registered Tarantool function and returns Future. +// 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. -func (connMulti *ConnectionMulti) CallAsync(functionName string, args interface{}) *tarantool.Future { - return connMulti.getCurrentConnection().CallAsync(functionName, args) +func (connMulti *ConnectionMulti) Call16Async(functionName string, args interface{}) *tarantool.Future { + return connMulti.getCurrentConnection().Call16Async(functionName, args) } -// Call17Async sends a call to registered Tarantool function and returns Future. +// CallAsync 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). -func (connMulti *ConnectionMulti) Call17Async(functionName string, args interface{}) *tarantool.Future { - return connMulti.getCurrentConnection().Call17Async(functionName, args) +func (connMulti *ConnectionMulti) CallAsync(functionName string, args interface{}) *tarantool.Future { + return connMulti.getCurrentConnection().CallAsync(functionName, args) } // EvalAsync passes Lua expression for evaluation. diff --git a/queue/queue.go b/queue/queue.go index ce0eeb49f..43280a271 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -289,7 +289,7 @@ func (q *queue) Kick(count uint64) (uint64, error) { resp, err := q.conn.Call(q.cmds.kick, []interface{}{count}) var id uint64 if err == nil { - id = resp.Data[0].([]interface{})[0].(uint64) + id = resp.Data[0].(uint64) } return id, err } @@ -309,10 +309,7 @@ func (q *queue) Statistic() (interface{}, error) { } if len(resp.Data) != 0 { - data, ok := resp.Data[0].([]interface{}) - if ok && len(data) != 0 { - return data[0], nil - } + return resp.Data[0], nil } return nil, nil diff --git a/request.go b/request.go index ff8a7e8a5..d47465a76 100644 --- a/request.go +++ b/request.go @@ -96,21 +96,21 @@ func (conn *Connection) Upsert(space interface{}, tuple, ops interface{}) (resp return conn.UpsertAsync(space, tuple, ops).Get() } -// Call calls registered Tarantool function. +// Call16 calls registered Tarantool function. // It uses request code for Tarantool 1.6, so result is converted to array of arrays // -// It is equal to conn.CallAsync(functionName, args).Get(). -func (conn *Connection) Call(functionName string, args interface{}) (resp *Response, err error) { - return conn.CallAsync(functionName, args).Get() +// It is equal to conn.Call16Async(functionName, args).Get(). +func (conn *Connection) Call16(functionName string, args interface{}) (resp *Response, err error) { + return conn.Call16Async(functionName, args).Get() } -// Call17 calls registered Tarantool function. +// Call 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 is equal to conn.Call17Async(functionName, args).Get(). -func (conn *Connection) Call17(functionName string, args interface{}) (resp *Response, err error) { - return conn.Call17Async(functionName, args).Get() +// It is equal to conn.CallAsync(functionName, args).Get(). +func (conn *Connection) Call(functionName string, args interface{}) (resp *Response, err error) { + return conn.CallAsync(functionName, args).Get() } // Eval passes Lua expression for evaluation. @@ -188,21 +188,21 @@ func (conn *Connection) UpdateTyped(space, index interface{}, key, ops interface return conn.UpdateAsync(space, index, key, ops).GetTyped(result) } -// CallTyped calls registered function. +// Call16Typed calls registered function. // It uses request code for Tarantool 1.6, so result is converted to array of arrays // -// It is equal to conn.CallAsync(functionName, args).GetTyped(&result). -func (conn *Connection) CallTyped(functionName string, args interface{}, result interface{}) (err error) { - return conn.CallAsync(functionName, args).GetTyped(result) +// It is equal to conn.Call16Async(functionName, args).GetTyped(&result). +func (conn *Connection) Call16Typed(functionName string, args interface{}, result interface{}) (err error) { + return conn.Call16Async(functionName, args).GetTyped(result) } -// Call17Typed calls registered function. +// CallTyped 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 is equal to conn.Call17Async(functionName, args).GetTyped(&result). -func (conn *Connection) Call17Typed(functionName string, args interface{}, result interface{}) (err error) { - return conn.Call17Async(functionName, args).GetTyped(result) +// It is equal to conn.CallAsync(functionName, args).GetTyped(&result). +func (conn *Connection) CallTyped(functionName string, args interface{}, result interface{}) (err error) { + return conn.CallAsync(functionName, args).GetTyped(result) } // EvalTyped passes Lua expression for evaluation. @@ -307,10 +307,10 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in }) } -// CallAsync sends a call to registered Tarantool function and returns Future. +// 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 -func (conn *Connection) CallAsync(functionName string, args interface{}) *Future { - future := conn.newFuture(CallRequest) +func (conn *Connection) Call16Async(functionName string, args interface{}) *Future { + future := conn.newFuture(Call16Request) return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(2) enc.EncodeUint64(KeyFunctionName) @@ -320,11 +320,11 @@ func (conn *Connection) CallAsync(functionName string, args interface{}) *Future }) } -// Call17Async sends a call to registered Tarantool function and returns Future. +// CallAsync 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) -func (conn *Connection) Call17Async(functionName string, args interface{}) *Future { - future := conn.newFuture(Call17Request) +func (conn *Connection) CallAsync(functionName string, args interface{}) *Future { + future := conn.newFuture(CallRequest) return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(2) enc.EncodeUint64(KeyFunctionName) @@ -426,7 +426,7 @@ func (fut *Future) Get() (*Response, error) { // GetTyped waits for Future and calls msgpack.Decoder.Decode(result) if no error happens. // It is could be much faster than Get() function. // -// Note: Tarantool usually returns array of tuples (except for Eval and Call17 actions) +// Note: Tarantool usually returns array of tuples (except for Eval and Call actions) func (fut *Future) GetTyped(result interface{}) error { fut.wait() if fut.err != nil { diff --git a/response.go b/response.go index 2e0783659..cbf6875a4 100644 --- a/response.go +++ b/response.go @@ -147,7 +147,7 @@ func (resp *Response) String() (str string) { return fmt.Sprintf("<%d ERR 0x%x %s>", resp.RequestId, resp.Code, resp.Error) } -// Tuples converts result of Eval and Call17 to same format +// Tuples converts result of Eval and Call to same format // as other actions returns (i.e. array of arrays). func (resp *Response) Tuples() (res [][]interface{}) { res = make([][]interface{}, len(resp.Data)) diff --git a/tarantool_test.go b/tarantool_test.go index 5f5078a8b..408e57066 100644 --- a/tarantool_test.go +++ b/tarantool_test.go @@ -620,25 +620,25 @@ func TestClient(t *testing.T) { t.Errorf("Result len of SelectTyped != 1") } - // Call - resp, err = conn.Call("box.info", []interface{}{"box.schema.SPACE_ID"}) + // Call16 + resp, err = conn.Call16("box.info", []interface{}{"box.schema.SPACE_ID"}) if err != nil { - t.Errorf("Failed to Call: %s", err.Error()) + t.Errorf("Failed to Call16: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Call") + t.Errorf("Response is nil after Call16") } if len(resp.Data) < 1 { t.Errorf("Response.Data is empty after Eval") } - // Call vs Call17 - resp, err = conn.Call("simple_incr", []interface{}{1}) + // Call16 vs Call + resp, err = conn.Call16("simple_incr", []interface{}{1}) if resp.Data[0].([]interface{})[0].(uint64) != 2 { t.Errorf("result is not {{1}} : %v", resp.Data) } - resp, err = conn.Call17("simple_incr", []interface{}{1}) + resp, err = conn.Call("simple_incr", []interface{}{1}) if resp.Data[0].(uint64) != 2 { t.Errorf("result is not {{1}} : %v", resp.Data) }