示例#1
0
 def test_pubsub_disconnect(self):
     client = Client(io_loop=self.io_loop)
     client.connect()
     client.subscribe("foo", lambda: None)
     client.close()
     with self.assertRaises(IOError):
         client._stream.read_bytes(1024, lambda x: x)
示例#2
0
 def test_pubsub_disconnect(self):
     client = Client(io_loop=self.io_loop)
     client.connect()
     client.subscribe("foo", lambda: None)
     client.close()
     with self.assertRaises(IOError):
         client._stream.read_bytes(1024, lambda x: x)
示例#3
0
def main():
    """ Start the application and Twitter stream monitor """
    options, args = OPTIONS.parse_args()
    if options.port:
        SETTINGS["port"] = options.port
    ioloop = IOLoop.instance()
    prefetch_tweets(ioloop)
    app = Application([(r"/", PageHandler), (r"/stream", StreamHandler),
                       (r"/poll", PollHandler)],
                      static_path="static",
                      debug=True)
    app.listen(SETTINGS["port"])
    client = Client()  # redis connection for all connected clients
    client.connect()
    client.subscribe(SETTINGS["redis_pub_channel"], callback=handle_message)
    # Monitor Twitter Stream once for all clients
    ioloop.start()
示例#4
0
def main():
    """ Start the application and Twitter stream monitor """
    options, args = OPTIONS.parse_args()
    if options.port:
        SETTINGS["port"] = options.port
    ioloop = IOLoop.instance()
    prefetch_tweets(ioloop)
    app = Application([
        (r"/", PageHandler),
        (r"/stream", StreamHandler),
        (r"/poll", PollHandler)
    ], static_path="static", debug=True)
    app.listen(SETTINGS["port"])
    client = Client() # redis connection for all connected clients
    client.connect()
    client.subscribe(SETTINGS["redis_pub_channel"], callback=handle_message)
    # Monitor Twitter Stream once for all clients
    ioloop.start()
示例#5
0
    def test_sub_command(self):
        client = Client(ioloop=self.io_loop)
        result = {"message_count": 0}
        conn = redis.Redis()

        def sub_callback(response):
            if response[0] == "subscribe":
                result["sub"] = response
                conn.publish("foobar", "new message!")
            elif response[0] == "message":
                result["message_count"] += 1
                if result["message_count"] < 100:
                    count = result["message_count"]
                    return conn.publish("foobar", "new message %s!" % count)
                result["message"] = response[2]
                self.stop()

        client.connect()
        client.subscribe("foobar", callback=sub_callback)
        self.wait()
        # blocks
        self.assertTrue("sub" in result)
        self.assertTrue("message" in result)
        self.assertTrue(result["message"], "new message 99!")
示例#6
0
    def test_sub_command(self):
        client = Client(io_loop=self.io_loop)
        result = {"message_count": 0}
        conn = redis.Redis()

        def sub_callback(response):
            if response[0] == "subscribe":
                result["sub"] = response
                conn.publish("foobar", "new message!")
            elif response[0] == "message":
                result["message_count"] += 1
                if result["message_count"] < 100:
                    count = result["message_count"]
                    return conn.publish("foobar", "new message %s!" % count)
                result["message"] = response[2]
                self.stop()

        client.connect()
        client.subscribe("foobar", callback=sub_callback)
        self.wait()
        # blocks
        self.assertTrue("sub" in result)
        self.assertTrue("message" in result)
        self.assertTrue(result["message"], "new message 99!")