示例#1
0
文件: queue.py 项目: nozayasu/funnel
    def test_serializer(self):
        class SomeObject(object):
            def __init__(self, entity):
                self.entity = entity

            def __repr__(self):
                return self.entity

        queue = AsyncManager()
        self.addCleanup(queue.close_connection)
        queue.connect(host=HOST)

        counter = {"n": 0}
        def on_message(body):
            self.assertEqual(body, {"message": "Hello, world!"})
            counter["n"] += 1

        queue.start_consuming(
            on_message,
        )

        self.assertRaises(TypeError, lambda: queue.publish({"message": SomeObject("Hello, world!")}, routing_key=queue.name))

        def serializer(o):
            if isinstance(o, SomeObject):
                return repr(o)
            raise TypeError(repr(o) + " is not JSON serializable")

        queue.publish({"message": SomeObject("Hello, world!")}, routing_key=queue.name, serializer=serializer)
        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()

        self.assertEqual(counter["n"], 1)
示例#2
0
文件: queue.py 项目: nozayasu/funnel
    def test_basis(self):
        # manager二つ使っているのでqueue nameは固定にしないと動かない
        queue = SyncManager(queue="dummy")
        worker_queue = AsyncManager(queue="dummy")
        self.addCleanup(queue.close_connection)
        # XXX こちらをcloseするとtesting のAsyncWorkerTestCase.doCleanupと競合しているのかエラーになるのでコメントアウト
#         self.addCleanup(worker_queue.close_connection)
        queue.connect(host=HOST)
        worker_queue.connect(host=HOST)

        counter = {"n": 0}
        def on_message(body):
            self.assertEqual(body, {"message": "Hello, world!"})
            counter["n"] += 1

        worker_queue.start_consuming(
            on_message,
        )

        queue.publish({"message": "Hello, world!"}, routing_key=queue.name)

        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()

        self.assertEqual(counter["n"], 1)
示例#3
0
    def test_ready_flag_when_queue_declere_completed(self):
        queue = SyncManager(queue="dummy")
        worker_queue = AsyncManager(queue="dummy")
        self.addCleanup(queue.close_connection)
        queue.connect(host=HOST)
        worker_queue.connect(host=HOST)

        def on_message():
            pass

        worker_queue.start_consuming(on_message)

        queue.publish({"message": "Hello, world!"}, routing_key=queue.name)
        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()
        self.assertTrue(queue._ready)
示例#4
0
    def test_ready_flag_when_queue_declere_completed(self):
        queue = SyncManager(queue="dummy")
        worker_queue = AsyncManager(queue="dummy")
        self.addCleanup(queue.close_connection)
        queue.connect(host=HOST)
        worker_queue.connect(host=HOST)

        def on_message():
            pass

        worker_queue.start_consuming(on_message, )

        queue.publish({"message": "Hello, world!"}, routing_key=queue.name)
        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()
        self.assertTrue(queue._ready)
示例#5
0
    def test_basis(self):
        queue = AsyncManager()
        self.addCleanup(queue.close_connection)
        queue.connect(host=HOST)

        counter = {"n": 0}

        def on_message(body):
            self.assertEqual(body, {"message": "Hello, world!"})
            counter["n"] += 1

        queue.start_consuming(on_message)

        queue.publish({"message": "Hello, world!"}, routing_key=queue.name)

        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()

        self.assertEqual(counter["n"], 1)
示例#6
0
    def test_basis(self):
        queue = AsyncManager()
        self.addCleanup(queue.close_connection)
        queue.connect(host=HOST)

        counter = {"n": 0}

        def on_message(body):
            self.assertEqual(body, {"message": "Hello, world!"})
            counter["n"] += 1

        queue.start_consuming(on_message, )

        queue.publish({"message": "Hello, world!"}, routing_key=queue.name)

        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()

        self.assertEqual(counter["n"], 1)
示例#7
0
    def test_serializer(self):
        class SomeObject(object):
            def __init__(self, entity):
                self.entity = entity

            def __repr__(self):
                return self.entity

        queue = AsyncManager()
        self.addCleanup(queue.close_connection)
        queue.connect(host=HOST)

        counter = {"n": 0}

        def on_message(body):
            self.assertEqual(body, {"message": "Hello, world!"})
            counter["n"] += 1

        queue.start_consuming(on_message, )

        self.assertRaises(
            TypeError,
            lambda: queue.publish({"message": SomeObject("Hello, world!")},
                                  routing_key=queue.name))

        def serializer(o):
            if isinstance(o, SomeObject):
                return repr(o)
            raise TypeError(repr(o) + " is not JSON serializable")

        queue.publish({"message": SomeObject("Hello, world!")},
                      routing_key=queue.name,
                      serializer=serializer)
        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()

        self.assertEqual(counter["n"], 1)
示例#8
0
    def test_basis(self):
        # manager二つ使っているのでqueue nameは固定にしないと動かない
        queue = SyncManager(queue="dummy")
        worker_queue = AsyncManager(queue="dummy")
        self.addCleanup(queue.close_connection)
        # XXX こちらをcloseするとtesting のAsyncWorkerTestCase.doCleanupと競合しているのかエラーになるのでコメントアウト
        #         self.addCleanup(worker_queue.close_connection)
        queue.connect(host=HOST)
        worker_queue.connect(host=HOST)

        counter = {"n": 0}

        def on_message(body):
            self.assertEqual(body, {"message": "Hello, world!"})
            counter["n"] += 1

        worker_queue.start_consuming(on_message, )

        queue.publish({"message": "Hello, world!"}, routing_key=queue.name)

        IOLoop.current().add_timeout(time() + 0.2, self.stop)
        self.wait()

        self.assertEqual(counter["n"], 1)