Ejemplo n.º 1
0
    async def test_check_route_registry_full_options(self):
        expected_routes = ["/asgard/counts/ok"]
        expected_vhost = "/"

        @self.app.amqp.consume(
            expected_routes,
            vhost=expected_vhost,
            options=AMQPRouteOptions(bulk_size=1024, bulk_flush_interval=120),
        )
        async def _handler(message):
            return 42

        self.assertIsNotNone(self.app.routes_registry)
        expected_registry_entry = AMQPRoute(
            type=RouteTypes.AMQP_RABBITMQ,
            routes=expected_routes,
            handler=_handler,
            default_options={},
            vhost=expected_vhost,
            options={
                "bulk_size": 1024,
                "bulk_flush_interval": 120,
                Events.ON_SUCCESS: Actions.ACK,
                Events.ON_EXCEPTION: Actions.REQUEUE,
            },
        )
        route = self.app.routes_registry.route_for(_handler)
        self.assertEqual(expected_registry_entry, route)
        self.assertEqual(42, await route["handler"](None))
Ejemplo n.º 2
0
 async def test_it_raises_an_error_if_route_connection_is_invalid(self):
     with self.assertRaises(ValueError):
         AMQPRoute(
             routes=["Xablau", "Xena"],
             handler=lambda *args, **kwargs: 42,
             options={"connection": (..., ..., ...)},
         )
Ejemplo n.º 3
0
    async def test_check_route_registry_full_options(self):
        expected_routes = ["/asgard/counts/ok"]
        expected_vhost = "/"
        app = App(connections=[self.connection])

        @app.route(
            expected_routes,
            type=RouteTypes.AMQP_RABBITMQ,
            vhost=expected_vhost,
            options={Options.BULK_SIZE: 1024, Options.BULK_FLUSH_INTERVAL: 120},
        )
        async def _handler(message):
            return 42

        self.assertIsNotNone(app.routes_registry)
        expected_registry_entry = AMQPRoute(
            type=RouteTypes.AMQP_RABBITMQ,
            routes=expected_routes,
            handler=_handler,
            default_options={},
            vhost=expected_vhost,
            options={
                "bulk_size": 1024,
                "bulk_flush_interval": 120,
                Events.ON_SUCCESS: Actions.ACK,
                Events.ON_EXCEPTION: Actions.REQUEUE,
            },
        )
        route = app.routes_registry.route_for(_handler)
        self.assertEqual(expected_registry_entry, route)
        self.assertEqual(42, await route["handler"](None))
Ejemplo n.º 4
0
    def test_register_amqp_handler(self):
        route = AMQPRoute(
            handler=CoroutineMock(),
            routes=["queue1", "queue2"],
            options=AMQPRouteOptions(),
        )

        self.routes_registry.add_amqp_route(route)

        self.assertEqual(len(self.routes_registry.amqp_routes), 1)
        self.assertEqual(self.routes_registry.amqp_routes[0], route)
Ejemplo n.º 5
0
    def _wrap(f):

        cb = _extract_async_callable(f)
        route = AMQPRoute(
            handler=cb,
            routes=routes,
            vhost=vhost,
            connection=connection,
            options=options,
        )
        registry.add_amqp_route(route)

        return f