Skip to content

Commit

Permalink
Implement call of 1.7 and make it the main one
Browse files Browse the repository at this point in the history
closes gh-82
  • Loading branch information
bigbes committed May 23, 2017
1 parent bdf48e0 commit 6c2f495
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
6 changes: 4 additions & 2 deletions tarantool/connection.py
Expand Up @@ -88,7 +88,8 @@ def __init__(self, host, port,
reconnect_max_attempts=RECONNECT_MAX_ATTEMPTS,
reconnect_delay=RECONNECT_DELAY,
connect_now=True,
encoding=ENCODING_DEFAULT):
encoding=ENCODING_DEFAULT,
call_16=False):
'''
Initialize a connection to the server.
Expand Down Expand Up @@ -121,6 +122,7 @@ def __init__(self, host, port,
self.connected = False
self.error = True
self.encoding = encoding
self.call_16 = call_16
if connect_now:
self.connect()

Expand Down Expand Up @@ -344,7 +346,7 @@ def call(self, func_name, *args):
if len(args) == 1 and isinstance(args[0], (list, tuple)):
args = args[0]

request = RequestCall(self, func_name, args)
request = RequestCall(self, func_name, args, self.call_16)
response = self._send_request(request)
return response

Expand Down
3 changes: 2 additions & 1 deletion tarantool/const.py
Expand Up @@ -39,10 +39,11 @@
REQUEST_TYPE_REPLACE = 3
REQUEST_TYPE_UPDATE = 4
REQUEST_TYPE_DELETE = 5
REQUEST_TYPE_CALL = 6
REQUEST_TYPE_CALL16 = 6
REQUEST_TYPE_AUTHENTICATE = 7
REQUEST_TYPE_EVAL = 8
REQUEST_TYPE_UPSERT = 9
REQUEST_TYPE_CALL = 10
REQUEST_TYPE_PING = 64
REQUEST_TYPE_JOIN = 65
REQUEST_TYPE_SUBSCRIBE = 66
Expand Down
5 changes: 4 additions & 1 deletion tarantool/request.py
Expand Up @@ -35,6 +35,7 @@
REQUEST_TYPE_DELETE,
REQUEST_TYPE_UPDATE,
REQUEST_TYPE_UPSERT,
REQUEST_TYPE_CALL16,
REQUEST_TYPE_CALL,
REQUEST_TYPE_EVAL,
REQUEST_TYPE_AUTHENTICATE,
Expand Down Expand Up @@ -218,7 +219,9 @@ class RequestCall(Request):
request_type = REQUEST_TYPE_CALL

# pylint: disable=W0231
def __init__(self, conn, name, args):
def __init__(self, conn, name, args, call_16):
if call_16:
self.request_type = REQUEST_TYPE_CALL16
super(RequestCall, self).__init__(conn)
assert isinstance(args, (list, tuple))

Expand Down
50 changes: 37 additions & 13 deletions tests/suites/test_dml.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

import six
import yaml
import unittest
import tarantool
Expand Down Expand Up @@ -154,29 +153,54 @@ def test_06_update(self):
self.assertSequenceEqual(self.con.update('space_1', (2,), [('#', 2, 2)]),
[[2, 2, 'tuplalal_3']])

def test_07_call(self):
self.assertSequenceEqual(self.con.call('json.decode', '[123, 234, 345]'), [[123, 234, 345]])
self.assertSequenceEqual(self.con.call('json.decode', ['[123, 234, 345]']), [[123, 234, 345]])
self.assertSequenceEqual(self.con.call('json.decode', ('[123, 234, 345]',)), [[123, 234, 345]])
def test_07_call_16(self):
con = tarantool.Connection('localhost', self.srv.args['primary'], call_16 = True)
con.authenticate('test', 'test')
self.assertSequenceEqual(con.call('json.decode', '[123, 234, 345]'), [[123, 234, 345]])
self.assertSequenceEqual(con.call('json.decode', ['[123, 234, 345]']), [[123, 234, 345]])
self.assertSequenceEqual(con.call('json.decode', ('[123, 234, 345]',)), [[123, 234, 345]])
with self.assertRaisesRegexp(tarantool.DatabaseError, '(32, .*)'):
self.con.call('json.decode')
con.call('json.decode')
with self.assertRaisesRegexp(tarantool.DatabaseError, '(32, .*)'):
self.con.call('json.decode', '{[1, 2]: "world"}')
ans = self.con.call('fiber.time')
con.call('json.decode', '{[1, 2]: "world"}')
ans = con.call('fiber.time')
self.assertEqual(len(ans), 1)
self.assertEqual(len(ans[0]), 1)
self.assertIsInstance(ans[0][0], float)
ans = self.con.call('fiber.time64')
ans = con.call('fiber.time64')
self.assertEqual(len(ans), 1)
self.assertEqual(len(ans[0]), 1)
self.assertIsInstance(ans[0][0], six.integer_types)
ans = self.con.call('uuid.str')
self.assertIsInstance(ans[0][0], tarantool.utils.integer_types)
ans = con.call('uuid.str')
self.assertEqual(len(ans), 1)
self.assertEqual(len(ans[0]), 1)
self.assertIsInstance(ans[0][0], str)

self.assertSequenceEqual(self.con.call('box.tuple.new', [1, 2, 3, 'fld_1']), [[1, 2, 3, 'fld_1']])
self.assertSequenceEqual(self.con.call('box.tuple.new', 'fld_1'), [['fld_1']])
self.assertSequenceEqual(con.call('box.tuple.new', [1, 2, 3, 'fld_1']), [[1, 2, 3, 'fld_1']])
self.assertSequenceEqual(con.call('box.tuple.new', 'fld_1'), [['fld_1']])

def test_07_call_17(self):
con = tarantool.Connection('localhost', self.srv.args['primary'])
con.authenticate('test', 'test')
self.assertSequenceEqual(con.call('json.decode', '[123, 234, 345]'), [[123, 234, 345]])
self.assertSequenceEqual(con.call('json.decode', ['[123, 234, 345]']), [[123, 234, 345]])
self.assertSequenceEqual(con.call('json.decode', ('[123, 234, 345]',)), [[123, 234, 345]])
with self.assertRaisesRegexp(tarantool.DatabaseError, '(32, .*)'):
con.call('json.decode')
with self.assertRaisesRegexp(tarantool.DatabaseError, '(32, .*)'):
con.call('json.decode', '{[1, 2]: "world"}')
ans = con.call('fiber.time')
self.assertEqual(len(ans), 1)
self.assertIsInstance(ans[0], float)
ans = con.call('fiber.time64')
self.assertEqual(len(ans), 1)
self.assertIsInstance(ans[0], tarantool.utils.integer_types)
ans = con.call('uuid.str')
self.assertEqual(len(ans), 1)
self.assertIsInstance(ans[0], str)

self.assertSequenceEqual(con.call('box.tuple.new', [1, 2, 3, 'fld_1']), [[1, 2, 3, 'fld_1']])
self.assertSequenceEqual(con.call('box.tuple.new', 'fld_1'), [['fld_1']])

def test_08_eval(self):
self.assertSequenceEqual(self.con.eval('return json.decode(...)',
Expand Down

0 comments on commit 6c2f495

Please sign in to comment.