示例#1
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()
示例#2
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()
示例#3
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()
示例#4
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()
示例#5
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()
示例#6
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()
示例#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()
示例#8
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()
示例#9
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()
示例#10
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()
示例#11
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()
示例#12
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)
示例#13
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
示例#14
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
示例#15
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)
示例#16
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)
示例#17
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)
示例#18
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()
示例#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 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()
示例#20
0
 def test_ping(self):
     c = Client()
     yield c.connect()
     res = yield c.call('PING')
     self.assertEqual(res, b"PONG")
     c.disconnect()
示例#21
0
 def test_autoconnect_future(self):
     c = Client(autoconnect=True)
     res = yield c.call('PING')
     self.assertEqual(res, b"PONG")
     c.disconnect()
示例#22
0
 def test_reply_error(self):
     c = Client()
     yield c.connect()
     res = yield c.call('BADCOMMAND')
     self.assertTrue(isinstance(res, ClientError))
     c.disconnect()
示例#23
0
 def test_autoconnect_future(self):
     c = Client(autoconnect=True)
     res = yield c.call('PING')
     self.assertEqual(res, b"PONG")
     c.disconnect()
示例#24
0
 def test_reply_error(self):
     c = Client()
     yield c.connect()
     res = yield c.call('BADCOMMAND')
     self.assertTrue(isinstance(res, ClientError))
     c.disconnect()
示例#25
0
 def test_ping(self):
     c = Client()
     yield c.connect()
     res = yield c.call('PING')
     self.assertEqual(res, b"PONG")
     c.disconnect()