def test_drop():
    policy = create_policy()
    policy.leased_messages['ack_id_string'] = 0
    policy._bytes = 20
    policy.drop([base.DropRequest(ack_id='ack_id_string', byte_size=20)])
    assert len(policy.leased_messages) == 0
    assert policy._bytes == 0

    # Do this again to establish idempotency.
    policy.drop([base.DropRequest(ack_id='ack_id_string', byte_size=20)])
    assert len(policy.leased_messages) == 0
    assert policy._bytes == 0
Esempio n. 2
0
def test_drop():
    policy = create_policy()
    policy.managed_ack_ids.add('ack_id_string')
    policy._bytes = 20
    policy.drop([base.DropRequest(ack_id='ack_id_string', byte_size=20)])
    assert len(policy.managed_ack_ids) == 0
    assert policy._bytes == 0

    # Do this again to establish idempotency.
    policy.drop([base.DropRequest(ack_id='ack_id_string', byte_size=20)])
    assert len(policy.managed_ack_ids) == 0
    assert policy._bytes == 0
def test_drop_unexpected_negative(_LOGGER):
    policy = create_policy()
    policy.leased_messages['ack_id_string'] = 0
    policy._bytes = 0
    policy.drop([base.DropRequest(ack_id='ack_id_string', byte_size=20)])
    assert len(policy.leased_messages) == 0
    assert policy._bytes == 0
    _LOGGER.debug.assert_called_once_with(
        'Bytes was unexpectedly negative: %d', -20)
def test_drop():
    msg = create_message(b'foo', ack_id='bogus_ack_id')
    with mock.patch.object(msg._request_queue, 'put') as put:
        msg.drop()
        put.assert_called_once_with(
            base.DropRequest(
                ack_id='bogus_ack_id',
                byte_size=25,
            ))
        check_call_types(put, base.DropRequest)
def test_nack():
    policy = create_policy()
    with mock.patch.object(policy, 'modify_ack_deadline') as mad:
        with mock.patch.object(policy, 'drop') as drop:
            items = [base.NackRequest(ack_id='ack_id_string', byte_size=10)]
            policy.nack(items)
            drop.assert_called_once_with(
                [base.DropRequest(ack_id='ack_id_string', byte_size=10)])
        mad.assert_called_once_with(
            [base.ModAckRequest(ack_id='ack_id_string', seconds=0)])
Esempio n. 6
0
    def drop(self):
        """Release the message from lease management.

        This informs the policy to no longer hold on to the lease for this
        message. Pub/Sub will re-deliver the message if it is not acknowledged
        before the existing lease expires.

        .. warning::
            For most use cases, the only reason to drop a message from
            lease management is on :meth:`ack` or :meth:`nack`; these methods
            both call this one. You probably do not want to call this method
            directly.
        """
        self._request_queue.put(
            base_policy.DropRequest(ack_id=self._ack_id, byte_size=self.size))
def test_drop_below_threshold():
    """Establish that we resume a paused subscription.

    If the subscription is paused, and we drop sufficiently below
    the flow control thresholds, it should resume.
    """
    policy = create_policy()
    policy.leased_messages['ack_id_string'] = 0
    num_bytes = 20
    policy._bytes = num_bytes
    consumer = policy._consumer
    assert consumer.paused is True

    policy.drop(
        [base.DropRequest(ack_id='ack_id_string', byte_size=num_bytes)])

    assert consumer.paused is False
    threads[2].start.assert_called_once_with()


def test_open_already_open():
    policy = create_policy()
    policy._future = mock.sentinel.future

    with pytest.raises(ValueError) as exc_info:
        policy.open(None)

    assert exc_info.value.args == ('This policy has already been opened.', )


@pytest.mark.parametrize('item,method',
                         [(base.AckRequest(0, 0, 0), 'ack'),
                          (base.DropRequest(0, 0), 'drop'),
                          (base.LeaseRequest(0, 0), 'lease'),
                          (base.ModAckRequest(0, 0), 'modify_ack_deadline'),
                          (base.NackRequest(0, 0), 'nack')])
def test_dispatch_callback_valid(item, method):
    policy = create_policy()
    with mock.patch.object(policy, method) as mocked:
        items = [item]
        policy.dispatch_callback(items)
        mocked.assert_called_once_with([item])


def test_on_exception_deadline_exceeded():
    policy = create_policy()

    details = 'Bad thing happened. Time out, go sit in the corner.'