Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 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)
Esempio n. 4
0
    def test__prepare_body(self):
        def dummy_callback():
            pass

        queue = AsyncManager()
        message = Message(queue, dummy_callback)

        body = message._prepare_body(b'{}')
        self.assertEqual(body, '{}')
Esempio n. 5
0
 def test_publish_with_not_ready(self):
     queue = AsyncManager(queue="dummy")
     self.addCleanup(queue.close_connection)
     queue.connect(host=HOST)
     queue._ready = False
     try:
         queue.publish(None, None)
     except Exception as e:
         self.fail("This exception is raised: {}".format(e))
Esempio n. 6
0
 def test_publish_with_not_ready(self):
     queue = AsyncManager(queue="dummy")
     self.addCleanup(queue.close_connection)
     queue.connect(host=HOST)
     queue._ready = False
     try:
         queue.publish(None,None)
     except Exception as e:
         self.fail("This exception is raised: {}".format(e))
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
0
    def test_handling_static_queue_name(self):
        queue = AsyncManager(queue="dummy")
        self.addCleanup(queue.close_connection)
        queue.connect(host=HOST)

        self.assertEqual(queue.name, "dummy")
Esempio n. 13
0
    def test_handling_static_queue_name(self):
        queue = AsyncManager(queue="dummy")
        self.addCleanup(queue.close_connection)
        queue.connect(host=HOST)

        self.assertEqual(queue.name, "dummy")