예제 #1
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)
예제 #2
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)
예제 #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__prepare_body(self):
        def dummy_callback():
            pass

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

        body = message._prepare_body(b'{}')
        self.assertEqual(body, '{}')
예제 #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))
예제 #6
0
파일: queue.py 프로젝트: nozayasu/funnel
 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))
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #12
0
파일: queue.py 프로젝트: nozayasu/funnel
    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")
예제 #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")