Exemplo n.º 1
0
 def test_empty_pipeline(self):
     c = Client()
     yield c.connect()
     p = Pipeline()
     res = yield c.call(p)
     self.assertTrue(isinstance(res, ClientError))
     c.disconnect()
Exemplo n.º 2
0
 def test_autoconnect_callback(self):
     condition = tornado.locks.Condition()
     c = Client(autoconnect=True)
     cb = functools.partial(self._test_autoconnect_callback_cb, condition)
     c.async_call('PING', callback=cb)
     yield condition.wait()
     c.disconnect()
Exemplo n.º 3
0
 def test_read_timeout1(self):
     orig_constructor = socket.socket
     socket.socket = functools.partial(fake_socket_constructor,
                                       FakeSocketObject5)
     c = Client(read_timeout=1)
     res = yield c.connect()
     self.assertTrue(res)
     res2 = yield c.call('PING')
     self.assertTrue(isinstance(res2, ConnectionError))
     c.disconnect()
     socket.socket = orig_constructor
Exemplo n.º 4
0
 def test_basic_pipeline(self):
     c = Client()
     yield c.connect()
     p = Pipeline()
     p.stack_call('PING')
     p.stack_call('PING')
     res = yield c.call(p)
     self.assertEqual(len(res), 2)
     self.assertEqual(res[0], b'PONG')
     self.assertEqual(res[1], b'PONG')
     c.disconnect()
Exemplo n.º 5
0
 def test_pubsub(self):
     c = PubSubClient()
     c2 = Client()
     yield c.connect()
     yield c2.connect()
     try:
         yield c.pubsub_pop_message()
         raise Exception("exception not raised")
     except Exception:
         pass
     res = yield c.pubsub_subscribe("foo1", "foo2")
     self.assertTrue(res)
     self.assertTrue(c.subscribed)
     self.assertFalse(c2.subscribed)
     try:
         yield c.call("PING")
         raise Exception("exception not raised")
     except Exception:
         pass
     res = yield c.pubsub_psubscribe("bar1*", "bar2*")
     self.assertTrue(res)
     tornado.ioloop.IOLoop.instance().add_future(self.publish(c2), None)
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[2], b"value1")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[2], b"value2")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[3], b"value3")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[3], b"value4")
     msg = yield c.pubsub_pop_message(deadline=1)
     self.assertEqual(msg, None)
     yield c.pubsub_unsubscribe("foo1")
     yield c2.call("PUBLISH", "foo1", "value1")
     c2.disconnect()
     msg = yield c.pubsub_pop_message(deadline=1)
     self.assertEqual(msg, None)
     yield c.pubsub_unsubscribe("foo2")
     yield c.pubsub_unsubscribe("foobar")
     yield c.pubsub_punsubscribe("foobar*")
     yield c.pubsub_punsubscribe("bar1*")
     yield c.pubsub_punsubscribe("bar2*")
     self.assertFalse(c.subscribed)
     c.disconnect()
Exemplo n.º 6
0
 def _pubsub_subscribe(self, command, *args):
     if len(args) == 0:
         raise ClientError("you must provide at least one argument")
     results = yield Client.call(self, command, *args,
                                 __multiple_replies=len(args))
     for reply in results:
         if isinstance(reply, ConnectionError) or len(reply) != 3 or \
                 reply[0].lower() != command.lower() or reply[2] == 0:
             raise tornado.gen.Return(False)
     self.subscribed = True
     raise tornado.gen.Return(True)
Exemplo n.º 7
0
 def test_client_close_connection(self):
     c = Client()
     yield c.connect()
     connection = c._Client__connection
     socket = connection._Connection__socket
     socket.close()
     res = yield c.call("PING")
     self.assertTrue(isinstance(res, ConnectionError))
     self.assertFalse(c.is_connected())
     c.disconnect()
Exemplo n.º 8
0
 def test_read_timeout2(self):
     c = Client(read_timeout=1, autoconnect=False)
     res = yield c.connect()
     self.assertTrue(res)
     res2 = yield c.call('PING')
     self.assertEqual(res2, b"PONG")
     yield tornado.gen.sleep(2)
     res3 = yield c.call('PING')
     self.assertTrue(isinstance(res3, ConnectionError))
     c.disconnect()
Exemplo n.º 9
0
 def test_autoconnect_callback(self):
     condition = tornado.locks.Condition()
     c = Client(autoconnect=True)
     cb = functools.partial(self._test_autoconnect_callback_cb, condition)
     c.async_call('PING', callback=cb)
     yield condition.wait()
     c.disconnect()
Exemplo n.º 10
0
 def test_empty_pipeline(self):
     c = Client()
     yield c.connect()
     p = Pipeline()
     res = yield c.call(p)
     self.assertTrue(isinstance(res, ClientError))
     c.disconnect()
Exemplo n.º 11
0
 def _pubsub_subscribe(self, command, *args):
     if len(args) == 0:
         raise ClientError("you must provide at least one argument")
     results = yield Client.call(self,
                                 command,
                                 *args,
                                 __multiple_replies=len(args))
     for reply in results:
         if isinstance(reply, ConnectionError) or len(reply) != 3 or \
                 reply[0].lower() != command.lower() or reply[2] == 0:
             raise tornado.gen.Return(False)
     self.subscribed = True
     raise tornado.gen.Return(True)
Exemplo n.º 12
0
 def _pubsub_unsubscribe(self, command, *args):
     if len(args) == 0:
         # see https://github.com/thefab/tornadis/issues/17
         args_len = 1
     else:
         args_len = len(args)
     results = yield Client.call(self, command, *args,
                                 __multiple_replies=args_len)
     for reply in results:
         if isinstance(reply, ConnectionError) or len(reply) != 3 or \
                 reply[0].lower() != command.lower():
             raise tornado.gen.Return(False)
         if reply[2] == 0:
             self.subscribed = False
     raise tornado.gen.Return(True)
Exemplo n.º 13
0
 def test_empty_pipeline(self):
     c = Client()
     yield c.connect()
     p = Pipeline()
     try:
         yield c.call(p)
         raise Exception("not raised ClientError")
     except ClientError:
         pass
     c.disconnect()
Exemplo n.º 14
0
 def test_client_close_connection(self):
     c = Client()
     yield c.connect()
     connection = c._Client__connection
     socket = connection._Connection__socket
     socket.close()
     res = yield c.call("PING")
     self.assertTrue(isinstance(res, ConnectionError))
     self.assertFalse(c.is_connected())
     c.disconnect()
Exemplo n.º 15
0
 def test_read_timeout2(self):
     c = Client(read_timeout=1, autoconnect=False)
     res = yield c.connect()
     self.assertTrue(res)
     res2 = yield c.call('PING')
     self.assertEqual(res2, b"PONG")
     yield tornado.gen.sleep(2)
     res3 = yield c.call('PING')
     self.assertTrue(isinstance(res3, ConnectionError))
     c.disconnect()
Exemplo n.º 16
0
 def test_basic_pipeline(self):
     c = Client()
     yield c.connect()
     p = Pipeline()
     p.stack_call('PING')
     p.stack_call('PING')
     res = yield c.call(p)
     self.assertEqual(len(res), 2)
     self.assertEqual(res[0], b'PONG')
     self.assertEqual(res[1], b'PONG')
     c.disconnect()
Exemplo n.º 17
0
 def test_read_timeout1(self):
     orig_constructor = socket.socket
     socket.socket = functools.partial(fake_socket_constructor,
                                       FakeSocketObject5)
     c = Client(read_timeout=1)
     res = yield c.connect()
     self.assertTrue(res)
     res2 = yield c.call('PING')
     self.assertTrue(isinstance(res2, ConnectionError))
     c.disconnect()
     socket.socket = orig_constructor
Exemplo n.º 18
0
 def _pubsub_unsubscribe(self, command, *args):
     if len(args) == 0:
         # see https://github.com/thefab/tornadis/issues/17
         args_len = 1
     else:
         args_len = len(args)
     results = yield Client.call(self,
                                 command,
                                 *args,
                                 __multiple_replies=args_len)
     for reply in results:
         if isinstance(reply, ConnectionError) or len(reply) != 3 or \
                 reply[0].lower() != command.lower():
             raise tornado.gen.Return(False)
         if reply[2] == 0:
             self.subscribed = False
     raise tornado.gen.Return(True)
Exemplo n.º 19
0
 def test_pubsub(self):
     c = PubSubClient()
     c2 = Client()
     yield c.connect()
     yield c2.connect()
     try:
         yield c.pubsub_pop_message()
         raise Exception("exception not raised")
     except:
         pass
     res = yield c.pubsub_subscribe("foo1", "foo2")
     self.assertTrue(res)
     self.assertTrue(c.subscribed)
     self.assertFalse(c2.subscribed)
     try:
         yield c.call("PING")
         raise Exception("exception not raised")
     except:
         pass
     res = yield c.pubsub_psubscribe("bar1*", "bar2*")
     self.assertTrue(res)
     tornado.ioloop.IOLoop.instance().add_future(self.publish(c2), None)
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[2], b"value1")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[2], b"value2")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[3], b"value3")
     msg = yield c.pubsub_pop_message()
     self.assertEqual(msg[3], b"value4")
     msg = yield c.pubsub_pop_message(deadline=1)
     self.assertEqual(msg, None)
     yield c.pubsub_unsubscribe("foo1")
     yield c2.call("PUBLISH", "foo1", "value1")
     c2.disconnect()
     msg = yield c.pubsub_pop_message(deadline=1)
     self.assertEqual(msg, None)
     yield c.pubsub_unsubscribe("foo2")
     yield c.pubsub_unsubscribe("foobar")
     yield c.pubsub_punsubscribe("foobar*")
     yield c.pubsub_punsubscribe("bar1*")
     yield c.pubsub_punsubscribe("bar2*")
     self.assertFalse(c.subscribed)
     c.disconnect()
Exemplo n.º 20
0
 def _make_client(self):
     """Makes and returns a Client object."""
     kwargs = self.client_kwargs
     client = Client(**kwargs)
     return client
Exemplo n.º 21
0
 def test_reply_error(self):
     c = Client()
     yield c.connect()
     res = yield c.call('BADCOMMAND')
     self.assertTrue(isinstance(res, ClientError))
     c.disconnect()
Exemplo n.º 22
0
 def test_server_close_connection(self):
     c = Client()
     c2 = Client()
     yield c.connect()
     yield c2.connect()
     future1 = c.call('BLPOP', 'test_server_close_connection', 0)
     future2 = self._close_connection(c2)
     res = yield [future1, future2]
     self.assertTrue(isinstance(res[0], ConnectionError))
     self.assertFalse(c.is_connected())
     yield c.connect()
     res2 = yield c.call("PING")
     self.assertEqual(res2, b"PONG")
     c.disconnect()
     c2.disconnect()
Exemplo n.º 23
0
 def test_discard(self):
     c = Client()
     yield c.connect()
     c.async_call('PING')
     c.disconnect()
Exemplo n.º 24
0
 def test_reply_error(self):
     c = Client()
     yield c.connect()
     res = yield c.call('BADCOMMAND')
     self.assertTrue(isinstance(res, ClientError))
     c.disconnect()
Exemplo n.º 25
0
 def test_init(self):
     c = Client()
     yield c.connect()
     c.disconnect()
Exemplo n.º 26
0
 def test_ping(self):
     c = Client()
     yield c.connect()
     res = yield c.call('PING')
     self.assertEqual(res, b"PONG")
     c.disconnect()
Exemplo n.º 27
0
 def test_init_with_db(self):
     c = Client(db=2)
     yield c.connect()
     self.assertEqual(c.db, 2)
     c.disconnect()
Exemplo n.º 28
0
 def test_autoconnect_future(self):
     c = Client(autoconnect=True)
     res = yield c.call('PING')
     self.assertEqual(res, b"PONG")
     c.disconnect()
Exemplo n.º 29
0
 def test_discard(self):
     c = Client()
     yield c.connect()
     c.async_call('PING')
     c.disconnect()
Exemplo n.º 30
0
 def test_ping(self):
     c = Client()
     yield c.connect()
     res = yield c.call('PING')
     self.assertEqual(res, b"PONG")
     c.disconnect()
Exemplo n.º 31
0
 def test_init_with_db(self):
     c = Client(db=2)
     yield c.connect()
     self.assertEqual(c.db, 2)
     c.disconnect()
Exemplo n.º 32
0
 def test_init(self):
     c = Client()
     yield c.connect()
     c.disconnect()
Exemplo n.º 33
0
 def test_server_close_connection(self):
     c = Client()
     c2 = Client()
     yield c.connect()
     yield c2.connect()
     future1 = c.call('BLPOP', 'test_server_close_connection', 0)
     future2 = self._close_connection(c2)
     res = yield [future1, future2]
     self.assertTrue(isinstance(res[0], ConnectionError))
     self.assertFalse(c.is_connected())
     yield c.connect()
     res2 = yield c.call("PING")
     self.assertEqual(res2, b"PONG")
     c.disconnect()
     c2.disconnect()
Exemplo n.º 34
0
 def test_autoconnect_future(self):
     c = Client(autoconnect=True)
     res = yield c.call('PING')
     self.assertEqual(res, b"PONG")
     c.disconnect()