Beispiel #1
0
 async def setUp(self):
     self.queue = JsonQueue("127.0.0.1",
                            "guest",
                            "guest",
                            delegate=DumbConsumer())
     self.consume_conn = self.queue.conn_for(ConnType.CONSUME)
     self.write_conn = self.queue.conn_for(ConnType.WRITE)
Beispiel #2
0
 def __init__(
     self,
     route_info: Union[Dict, AMQPRoute],
     host: str,
     username: str,
     password: str,
     prefetch_count: int = 128,
     bucket_class: Type[Bucket] = Bucket[RabbitMQMessage],
 ) -> None:
     self.route = route_info
     self._handler = route_info["handler"]
     self._queue_name = route_info["routes"]
     self._route_options = route_info["options"]
     self.host = host
     self.vhost = route_info.get("vhost", "/")
     if self.vhost != "/":
         self.vhost = self.vhost.lstrip("/")
     self.bucket = bucket_class(
         size=min(self._route_options["bulk_size"], prefetch_count))
     self.queue: JsonQueue = JsonQueue(
         host,
         username,
         password,
         virtual_host=self.vhost,
         delegate=self,
         prefetch_count=prefetch_count,
     )
     self.clock = ClockTicker(seconds=conf.settings.FLUSH_TIMEOUT)
     self.clock_task = None
Beispiel #3
0
 def __init__(
     self,
     route_info: Union[Dict, AMQPRoute],
     host: str,
     username: str,
     password: str,
     prefetch_count: int = 128,
     bucket_class: Type[Bucket] = Bucket[RabbitMQMessage],
 ) -> None:
     self.route = route_info
     self._handler = route_info["handler"]
     self._queue_name = route_info["routes"]
     self._route_options = route_info["options"]
     self.host = host
     self.vhost = route_info.get("vhost", "/")
     self.bucket = bucket_class(
         size=min(self._route_options["bulk_size"], prefetch_count))
     self.queue: JsonQueue = JsonQueue(
         host,
         username,
         password,
         virtual_host=self.vhost,
         delegate=self,
         prefetch_count=prefetch_count,
         logger=conf.logger,
         connection_fail_callback=self._route_options.get(
             Options.CONNECTION_FAIL_CALLBACK, None),
     )
     self.clock = ClockTicker(seconds=self._route_options.get(
         Options.BULK_FLUSH_INTERVAL, conf.settings.FLUSH_TIMEOUT))
     self.clock_task = None
 async def test_its_possibile_to_initialize_without_a_delegate(self):
     queue = JsonQueue(
         host="diogommartins.com",
         username="******",
         password="******",
         loop=Mock(),
     )
     self.assertIsInstance(queue, JsonQueue)
 async def setUp(self):
     self.seconds = 666
     self.queue = JsonQueue(
         "127.0.0.1",
         "guest",
         "guest",
         seconds_between_conn_retry=self.seconds,
         logger=Mock(spec=logging.Logger),
         connection_fail_callback=CoroutineMock(),
     )
Beispiel #6
0
 def setUp(self):
     self.conn_params = dict(
         host="money.que.é.good",
         username="******",
         password="******",
         virtual_host="have",
         heartbeat=5,
     )
     self.queue = JsonQueue(**self.conn_params, delegate=self.get_consumer())
     self.mock_connection()
Beispiel #7
0
 async def test_it_raises_an_error_if_its_initialized_with_both_delegate_and_delegate_class(
         self):
     with self.assertRaises(ValueError):
         JsonQueue(
             host="diogommartins.com",
             username="******",
             password="******",
             loop=Mock(),
             delegate=Mock(),
             delegate_class=Mock(),
         )
Beispiel #8
0
 async def test_it_doesnt_raise_value_error_if_max_message_length_is_zero(
         self):
     valid_value = 0
     queue = JsonQueue(
         host="diogommartins.com",
         username="******",
         password="******",
         loop=Mock(),
         delegate=Mock(),
         max_message_length=valid_value,
     )
     self.assertEqual(queue.max_message_length, valid_value)
Beispiel #9
0
 async def test_it_doesnt_raise_value_error_if_max_message_length_is_a_positive_number(
         self):
     valid_value = 666
     queue = JsonQueue(
         host="Essa",
         username="******",
         password="******",
         loop=Mock(),
         delegate=Mock(),
         max_message_length=valid_value,
     )
     self.assertEqual(queue.max_message_length, valid_value)
Beispiel #10
0
 async def test_it_raises_value_error_if_max_message_length_is_a_negative_number(
         self):
     invalid_value = -666
     with self.assertRaises(ValueError):
         JsonQueue(
             host="Olha",
             username="******",
             password="******",
             loop=Mock(),
             delegate=Mock(),
             max_message_length=invalid_value,
         )
Beispiel #11
0
    def __getitem__(self, key: str) -> JsonQueue:
        """
        Gets a JsonQueue instance for a given virtual host

        :param key: The virtual host of the connection
        :return: An instance of the connection
        """
        try:
            return self.__connections[key]
        except KeyError:
            conn: JsonQueue = JsonQueue(
                host=self.hostname,
                username=self.username,
                password=self.password,
                virtual_host=key,
            )
            self.__connections[key] = conn
            return conn
Beispiel #12
0
 async def setUp(self):
     self.queue = JsonQueue(host="127.0.0.1",
                            username="******",
                            password="******")
     self.write_conn = self.queue.conn_for(ConnType.WRITE)
     self.wrapped = _ensure_conn_is_ready(ConnType.WRITE)(self._func)
 async def test_it_initializes_a_delegate_if_delegate_class_is_provided(
     self
 ):
     delegate_class = Mock()
     JsonQueue(Mock(), Mock(), Mock(), delegate_class=delegate_class)
     delegate_class.assert_called_once_with()