Esempio n. 1
0
async def test_declare_exchanges(data_connection, empty_db):
    channel = create_autospec(RobustChannel, spec_set=True)
    data_connection.channel = AsyncMock(return_value=channel)

    manager = QueueManager(data_connection=data_connection, config_db=empty_db)

    # Assert that exchanges are not available before they are declared
    with pytest.raises(RuntimeError):
        manager.data_exchange
    with pytest.raises(RuntimeError):
        manager.history_exchange

    data_exchange, history_exchange = await manager.declare_exchanges(
        data_exchange_name="data", history_exchange_name="history")

    # Check that the exchanges have been declared with the correct parameters
    for declare_call in (
            call.declare_exchange(name="data",
                                  durable=True,
                                  type=ExchangeType.TOPIC),
            call.declare_exchange(name="history",
                                  durable=True,
                                  type=ExchangeType.TOPIC),
    ):
        assert declare_call in channel.method_calls
Esempio n. 2
0
async def test_declare_transformer_queue_no_config(data_connection, empty_db):
    channel = create_autospec(RobustChannel, spec_set=True)

    data_connection.attach_mock(AsyncMock(return_value=channel), "channel")

    manager = QueueManager(data_connection=data_connection,
                           config_db=mock_db({"transformer-foo": {}}))

    await manager.transformer_declare_data_queue("transformer-foo")

    assert channel.declare_queue.await_args.kwargs["durable"]
Esempio n. 3
0
async def test_declare_history_queue_no_config(data_connection, empty_db):
    channel = create_autospec(RobustChannel, spec_set=True)

    data_connection.attach_mock(AsyncMock(return_value=channel), "channel")

    manager = QueueManager(data_connection=data_connection, config_db=empty_db)

    await manager.history_declare_response_queue("history-foo")

    # Make sure history response queues expire by default
    args, kwargs = channel.declare_queue.call_args
    assert (kwargs["arguments"]["x-expires"] ==
            QueueManager.DEFAULT_HISTORY_RESPONSE_QUEUE_TTL)
Esempio n. 4
0
    async def connect(self):
        await super().connect()

        data_url = URL(self._management_url).with_path(self.data_vhost)

        self.queue_manager = QueueManager(
            data_connection=await self.make_connection(str(data_url)),
            config_db=await self.config_db(),
        )

        await self.queue_manager.declare_exchanges(
            data_exchange_name=self.data_exchange,
            history_exchange_name=self.history_exchange,
        )
Esempio n. 5
0
async def test_close(empty_db):
    async def close():
        pass

    async def channel(self):
        assert (
            False
        ), "No channel should be opened unless QueueManager.channel() is called"

    data_connection = create_autospec(RobustConnection,
                                      spec_set=True,
                                      close=close,
                                      channel=channel)
    manager = QueueManager(data_connection=data_connection, config_db=empty_db)

    await manager.close()
    data_connection.close.assert_called_once()
Esempio n. 6
0
async def test_declare_sink_queue(data_connection, empty_db):
    channel = create_autospec(RobustChannel, spec_set=True)

    data_connection.attach_mock(AsyncMock(return_value=channel), "channel")

    manager = QueueManager(
        data_connection=data_connection,
        config_db=empty_db,
    )

    await manager.sink_declare_data_queue("sink-foo", queue_name=None)

    args, kwargs = channel.declare_queue.call_args
    assert not kwargs["robust"]
    assert kwargs["auto_delete"]
    assert kwargs["arguments"][
        "x-expires"] == QueueManager.DEFAULT_SINK_DATA_QUEUE_TTL
Esempio n. 7
0
async def test_declare_sink_queue_default_queue_name(data_connection,
                                                     empty_db):
    channel = create_autospec(RobustChannel)
    data_connection.attach_mock(
        AsyncMock(return_value=channel),
        "channel",
    )

    manager = QueueManager(
        data_connection=data_connection,
        config_db=empty_db,
    )

    QUEUE_NAME_OVERRIDE = "sink-foo-override-data"
    await manager.sink_declare_data_queue("sink-foo",
                                          queue_name=QUEUE_NAME_OVERRIDE)

    args, kwargs = channel.declare_queue.call_args
    assert QUEUE_NAME_OVERRIDE in args[:1] or kwargs[
        "name"] == QUEUE_NAME_OVERRIDE
Esempio n. 8
0
async def test_read_config_allow_missing(data_connection, empty_db):
    manager = QueueManager(data_connection=data_connection, config_db=empty_db)

    assert (await manager.read_config("does-not-exist-in-db",
                                      role="test",
                                      allow_missing=True)).config == {}
Esempio n. 9
0
async def test_read_config_missing(data_connection, empty_db):
    manager = QueueManager(data_connection=data_connection, config_db=empty_db)

    with pytest.raises(KeyError):
        await manager.read_config("does-not-exist-in-db", role="test")
Esempio n. 10
0
async def test_read_config(data_connection, mocker: MockFixture):
    CONFIG = mocker.sentinel.CONFIG
    manager = QueueManager(data_connection=data_connection,
                           config_db=mock_db({"foo": CONFIG}))

    assert (await manager.read_config("foo", role="test")).config is CONFIG