コード例 #1
0
def test_queue_cancel_scheduled_messages(live_servicebus_config,
                                         standard_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)

    queue_client = client.get_queue(standard_queue)
    enqueue_time = (datetime.utcnow() +
                    timedelta(minutes=2)).replace(microsecond=0)
    with queue_client.get_receiver() as receiver:
        with queue_client.get_sender() as sender:
            message_a = Message("Test scheduled message")
            message_b = Message("Test scheduled message")
            tokens = sender.schedule(enqueue_time, message_a, message_b)
            assert len(tokens) == 2

            sender.cancel_scheduled_messages(*tokens)

        messages = receiver.fetch_next(timeout=120)
        try:
            assert len(messages) == 0
        except AssertionError:
            for m in messages:
                print(str(m))
                m.complete()
            raise
コード例 #2
0
def test_qsession_cancel_scheduled_messages(live_servicebus_config, partitioned_session_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    session_id = str(uuid.uuid4())
    queue_client = client.get_queue(partitioned_session_queue)
    enqueue_time = (datetime.utcnow() + timedelta(minutes=2)).replace(microsecond=0)

    with queue_client.get_sender(session=session_id) as sender:
        message_id = uuid.uuid4()
        message_a = Message("Test scheduled message")
        message_a.properties.message_id = message_id
        message_b = Message("Test scheduled message")
        message_b.properties.message_id = message_id
        tokens = sender.schedule(enqueue_time, message_a, message_b)
        assert len(tokens) == 2
        sender.cancel_scheduled_messages(*tokens)

    with queue_client.get_receiver(session=session_id) as receiver:
        messages = []
        count = 0
        while not messages and count < 13:
            messages = receiver.fetch_next(timeout=10)
            receiver.renew_lock()
            count += 1
        assert len(messages) == 0
コード例 #3
0
    def test_session_cancel_scheduled_messages(
            self, servicebus_namespace, servicebus_namespace_key_name,
            servicebus_namespace_primary_key, servicebus_queue, **kwargs):

        client = ServiceBusClient(
            service_namespace=servicebus_namespace.name,
            shared_access_key_name=servicebus_namespace_key_name,
            shared_access_key_value=servicebus_namespace_primary_key,
            debug=False)

        session_id = str(uuid.uuid4())
        queue_client = client.get_queue(servicebus_queue.name)
        enqueue_time = (datetime.utcnow() +
                        timedelta(minutes=2)).replace(microsecond=0)

        with queue_client.get_sender(session=session_id) as sender:
            message_a = Message("Test scheduled message")
            message_b = Message("Test scheduled message")
            tokens = sender.schedule(enqueue_time, message_a, message_b)
            assert len(tokens) == 2
            sender.cancel_scheduled_messages(*tokens)

        with queue_client.get_receiver(session=session_id) as receiver:
            messages = []
            count = 0
            while not messages and count < 13:
                messages = receiver.fetch_next(timeout=10)
                receiver.renew_lock()
                count += 1
            assert len(messages) == 0
コード例 #4
0
def test_queue_by_servicebus_client_fail_send_messages(live_servicebus_config,
                                                       standard_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)

    queue_client = client.get_queue(standard_queue)
    too_large = "A" * 1024 * 512
    try:
        results = queue_client.send(Message(too_large))
    except MessageSendFailed:
        pytest.skip("Open issue for uAMQP on OSX")

    assert len(results) == 1
    assert not results[0][0]
    assert isinstance(results[0][1], MessageSendFailed)

    with queue_client.get_sender() as sender:
        with pytest.raises(MessageSendFailed):
            sender.send(Message(too_large))

    with queue_client.get_sender() as sender:
        sender.queue_message(Message(too_large))
        results = sender.send_pending_messages()
        assert len(results) == 1
        assert not results[0][0]
        assert isinstance(results[0][1], MessageSendFailed)
コード例 #5
0
def test_qsession_schedule_multiple_messages(live_servicebus_config, partitioned_session_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)
    import uuid
    session_id = str(uuid.uuid4())
    queue_client = client.get_queue(partitioned_session_queue)
    enqueue_time = (datetime.utcnow() + timedelta(minutes=2)).replace(microsecond=0)

    with queue_client.get_receiver(session=session_id, prefetch=20) as receiver:
        with queue_client.get_sender(session=session_id) as sender:
            content = str(uuid.uuid4())
            message_id = uuid.uuid4()
            message_a = Message(content)
            message_a.properties.message_id = message_id
            message_b = Message(content)
            message_b.properties.message_id = message_id
            sender.schedule(enqueue_time, message_a, message_b)
            assert len(tokens) == 2

        messages = []
        count = 0
        while len(messages) < 2 and count < 12:
            messages = receiver.fetch_next(timeout=10)
            receiver.renew_lock()
            count += 1

        data = str(messages[0])
        assert data == content
        assert messages[0].scheduled_enqueue_time == enqueue_time
        assert messages[0].scheduled_enqueue_time == messages[0].enqueued_time.replace(microsecond=0)
        assert len(messages) == 2
コード例 #6
0
    def test_sb_client_writeonly_credentials(
            self, servicebus_authorization_rule_connection_string,
            servicebus_queue, **kwargs):
        client = ServiceBusClient.from_connection_string(
            servicebus_authorization_rule_connection_string)
        with pytest.raises(AzureHttpError):
            client.get_queue(servicebus_queue.name)

        client = QueueClient.from_connection_string(
            servicebus_authorization_rule_connection_string,
            name=servicebus_queue.name,
            debug=False)
        with pytest.raises(ServiceBusAuthorizationError):
            with client.get_receiver(idle_timeout=5) as receiver:
                messages = receiver.fetch_next()

        client.send([Message("test1"), Message("test2")])
        with pytest.raises(TypeError):
            client.send("cat")
        with pytest.raises(TypeError):
            client.send(1234)
        with pytest.raises(TypeError):
            client.send([1, 2, 3])
        with pytest.raises(TypeError):
            client.send([Message("test1"), "test2"])
def test_topic_by_topic_client_conn_str_send_basic(live_servicebus_config,
                                                   standard_topic):

    topic_client = TopicClient.from_connection_string(
        live_servicebus_config['conn_str'], name=standard_topic, debug=False)
    with topic_client.get_sender() as sender:
        message = Message(b"Sample topic message")
        sender.send(message)
    message = Message(b"Another sample topic message")
    topic_client.send(message)
コード例 #8
0
    def test_topic_by_topic_client_conn_str_send_basic(
            self, servicebus_namespace_connection_string, servicebus_topic,
            **kwargs):

        topic_client = TopicClient.from_connection_string(
            servicebus_namespace_connection_string,
            name=servicebus_topic.name,
            debug=False)
        with topic_client.get_sender() as sender:
            message = Message(b"Sample topic message")
            sender.send(message)
        message = Message(b"Another sample topic message")
        topic_client.send(message)
def test_topic_by_servicebus_client_conn_str_send_basic(
        live_servicebus_config, standard_topic):

    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)

    topic_client = client.get_topic(standard_topic)
    with topic_client.get_sender() as sender:
        message = Message(b"Sample topic message")
        sender.send(message)
    message = Message(b"Another sample topic message")
    topic_client.send(message)
コード例 #10
0
def test_queue_by_servicebus_client_iter_messages_with_retrieve_deferred_not_found(
        live_servicebus_config, standard_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)

    queue_client = client.get_queue(standard_queue)
    deferred_messages = []
    with queue_client.get_receiver(
            idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:

        with queue_client.get_sender() as sender:
            for i in range(3):
                message = Message("Deferred message no. {}".format(i))
                sender.send(message)

        count = 0
        for message in receiver:
            deferred_messages.append(message.sequence_number)
            print_message(message)
            count += 1
            message.defer()

    assert count == 3

    with pytest.raises(ServiceBusError):
        deferred = queue_client.receive_deferred_messages(
            [3, 4], mode=ReceiveSettleMode.PeekLock)

    with pytest.raises(ServiceBusError):
        deferred = queue_client.receive_deferred_messages(
            [5, 6, 7], mode=ReceiveSettleMode.PeekLock)
コード例 #11
0
def test_queue_by_servicebus_client_iter_messages_with_retrieve_deferred_receiver_deletemode(
        live_servicebus_config, standard_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)

    queue_client = client.get_queue(standard_queue)
    deferred_messages = []
    messages = [
        Message("Deferred message no. {}".format(i)) for i in range(10)
    ]
    results = queue_client.send(messages)
    assert all(result[0] for result in results)

    count = 0
    receiver = queue_client.get_receiver(idle_timeout=5)
    for message in receiver:
        deferred_messages.append(message.sequence_number)
        print_message(message)
        count += 1
        message.defer()

    assert count == 10
    with queue_client.get_receiver(idle_timeout=5) as receiver:
        deferred = receiver.receive_deferred_messages(
            deferred_messages, mode=ReceiveSettleMode.ReceiveAndDelete)
        assert len(deferred) == 10
        for message in deferred:
            assert isinstance(message, DeferredMessage)
            with pytest.raises(MessageAlreadySettled):
                message.complete()
        with pytest.raises(ServiceBusError):
            deferred = receiver.receive_deferred_messages(deferred_messages)
コード例 #12
0
def test_queue_by_servicebus_client_iter_messages_with_defer(
        live_servicebus_config, standard_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)

    queue_client = client.get_queue(standard_queue)
    deferred_messages = []
    with queue_client.get_receiver(
            idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:

        with queue_client.get_sender() as sender:
            for i in range(10):
                message = Message("Deferred message no. {}".format(i))
                sender.send(message)

        count = 0
        for message in receiver:
            deferred_messages.append(message.sequence_number)
            print_message(message)
            count += 1
            message.defer()

    assert count == 10
    with queue_client.get_receiver(
            idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:
        count = 0
        for message in receiver:
            print_message(message)
            message.complete()
            count += 1
    assert count == 0
コード例 #13
0
def test_queue_by_servicebus_conn_str_client_iter_messages_with_abandon(
        live_servicebus_config, standard_queue):
    client = ServiceBusClient.from_connection_string(
        live_servicebus_config['conn_str'], debug=False)
    queue_client = client.get_queue(standard_queue)
    with queue_client.get_receiver(
            idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:

        with queue_client.get_sender() as sender:
            for i in range(10):
                message = Message("Abandoned message no. {}".format(i))
                sender.send(message)

        count = 0
        for message in receiver:
            print_message(message)
            if not message.header.delivery_count:
                count += 1
                message.abandon()
            else:
                assert message.header.delivery_count == 1
                message.complete()

    assert count == 10

    with queue_client.get_receiver(
            idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:
        count = 0
        for message in receiver:
            print_message(message)
            message.complete()
            count += 1
    assert count == 0
コード例 #14
0
def test_queue_by_servicebus_client_iter_messages_simple(
        live_servicebus_config, standard_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)

    queue_client = client.get_queue(standard_queue)
    with queue_client.get_receiver(
            idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:

        with queue_client.get_sender() as sender:
            for i in range(10):
                message = Message("Iter message no. {}".format(i))
                sender.send(message)

        count = 0
        for message in receiver:
            print_message(message)
            message.complete()
            with pytest.raises(MessageAlreadySettled):
                message.complete()
            with pytest.raises(MessageAlreadySettled):
                message.renew_lock()
            count += 1

        with pytest.raises(InvalidHandlerState):
            next(receiver)
    assert count == 10
コード例 #15
0
def test_queue_by_queue_client_conn_str_receive_handler_with_stop(
        live_servicebus_config, standard_queue):
    queue_client = QueueClient.from_connection_string(
        live_servicebus_config['conn_str'], name=standard_queue, debug=False)

    with queue_client.get_sender() as sender:
        for i in range(10):
            message = Message("Stop message no. {}".format(i))
            sender.send(message)

    messages = []
    receiver = queue_client.get_receiver(idle_timeout=5)
    for message in receiver:
        messages.append(message)
        message.complete()
        if len(messages) >= 5:
            break

    assert receiver.running
    assert len(messages) == 5

    with receiver:
        for message in receiver:
            messages.append(message)
            message.complete()
            if len(messages) >= 5:
                break

    assert not receiver.running
    assert len(messages) == 6
コード例 #16
0
def test_qsession_message_expiry(live_servicebus_config, partitioned_session_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)
    session_id = str(uuid.uuid4())
    queue_client = client.get_queue(partitioned_session_queue)
    
    with queue_client.get_sender() as sender:
        message = Message("Testing expired messages")
        message.session_id = session_id
        sender.send(message)

    with queue_client.get_receiver(session=session_id) as receiver:
        messages = receiver.fetch_next(timeout=10)
        assert len(messages) == 1
        print_message(messages[0])
        time.sleep(30)
        with pytest.raises(TypeError):
            messages[0].expired
        with pytest.raises(TypeError):
            messages[0].renew_lock()
        assert receiver.expired
        with pytest.raises(SessionLockExpired):
            messages[0].complete()
        with pytest.raises(SessionLockExpired):
            receiver.renew_lock()

    with queue_client.get_receiver(session=session_id) as receiver:
        messages = receiver.fetch_next(timeout=30)
        assert len(messages) == 1
        print_message(messages[0])
        #assert messages[0].header.delivery_count  # TODO confirm this with service
        messages[0].complete()
コード例 #17
0
def test_queue_schedule_message(live_servicebus_config, standard_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)
    import uuid
    queue_client = client.get_queue(standard_queue)
    enqueue_time = (datetime.utcnow() +
                    timedelta(minutes=2)).replace(microsecond=0)
    with queue_client.get_receiver() as receiver:
        with queue_client.get_sender() as sender:
            content = str(uuid.uuid4())
            message_id = uuid.uuid4()
            message = Message(content)
            message.properties.message_id = message_id
            message.schedule(enqueue_time)
            sender.send(message)

        messages = receiver.fetch_next(timeout=120)
        if messages:
            try:
                data = str(messages[0])
                assert data == content
                assert messages[0].properties.message_id == message_id
                assert messages[0].scheduled_enqueue_time == enqueue_time
                assert messages[0].scheduled_enqueue_time == messages[
                    0].enqueued_time.replace(microsecond=0)
                assert len(messages) == 1
            finally:
                for m in messages:
                    m.complete()
        else:
            raise Exception("Failed to receive schdeduled message.")
コード例 #18
0
def test_qsession_by_servicebus_client_iter_messages_with_retrieve_deferred_client(live_servicebus_config, partitioned_session_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(partitioned_session_queue)
    deferred_messages = []
    session_id = str(uuid.uuid4())
    with queue_client.get_sender(session=session_id) as sender:
        for i in range(10):
            message = Message("Deferred message no. {}".format(i))
            sender.send(message)

    session = queue_client.get_receiver(session=session_id, idle_timeout=5)
    count = 0
    for message in session:
        deferred_messages.append(message.sequence_number)
        print_message(message)
        count += 1
        message.defer()

    assert count == 10

    with pytest.raises(ValueError):
        deferred = queue_client.receive_deferred_messages(deferred_messages, session=session_id)

    with pytest.raises(ValueError):
        queue_client.settle_deferred_messages('completed', [message], session=session_id)
コード例 #19
0
def test_queue_message_expiry(live_servicebus_config, standard_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)
    import uuid
    queue_client = client.get_queue(standard_queue)

    with queue_client.get_sender() as sender:
        content = str(uuid.uuid4())
        message = Message(content)
        sender.send(message)

    with queue_client.get_receiver() as receiver:
        messages = receiver.fetch_next(timeout=10)
        assert len(messages) == 1
        time.sleep(30)
        assert messages[0].expired
        with pytest.raises(MessageLockExpired):
            messages[0].complete()
        with pytest.raises(MessageLockExpired):
            messages[0].renew_lock()

    with queue_client.get_receiver() as receiver:
        messages = receiver.fetch_next(timeout=30)
        assert len(messages) == 1
        print_message(messages[0])
        assert messages[0].header.delivery_count > 0
        messages[0].complete()
コード例 #20
0
def test_queue_message_duplicate_detection(live_servicebus_config,
                                           duplicate_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)
    import uuid
    message_id = uuid.uuid4()
    queue_client = client.get_queue(duplicate_queue)

    with queue_client.get_sender() as sender:
        for i in range(5):
            message = Message(str(i))
            message.properties.message_id = message_id
            sender.send(message)

    with queue_client.get_receiver(idle_timeout=5) as receiver:
        count = 0
        for message in receiver:
            print_message(message)
            assert message.properties.message_id == message_id
            message.complete()
            count += 1
        assert count == 1
コード例 #21
0
def test_qsession_by_queue_client_conn_str_receive_handler_receiveanddelete(live_servicebus_config, partitioned_session_queue):
    queue_client = QueueClient.from_connection_string(
        live_servicebus_config['conn_str'],
        name=partitioned_session_queue,
        debug=True)
    queue_client.get_properties()

    session_id = str(uuid.uuid4())
    with queue_client.get_sender(session=session_id) as sender:
        for i in range(10):
            message = Message("Handler message no. {}".format(i))
            sender.send(message)

    messages = []
    session = queue_client.get_receiver(session=session_id, mode=ReceiveSettleMode.ReceiveAndDelete, idle_timeout=5)
    for message in session:
        messages.append(message)
        assert session_id == session.session_id
        assert session_id == message.session_id
        with pytest.raises(MessageAlreadySettled):
            message.complete()

    assert not session.running
    assert len(messages) == 10
    time.sleep(30)

    messages = []
    session = queue_client.get_receiver(session=session_id, mode=ReceiveSettleMode.ReceiveAndDelete, idle_timeout=5)
    for message in session:
        messages.append(message)
    assert len(messages) == 0
コード例 #22
0
def test_qsession_by_servicebus_client_list_sessions_with_client(live_servicebus_config, partitioned_session_queue):

    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(partitioned_session_queue)
    sessions = []
    start_time = datetime.now()
    for i in range(5):
        sessions.append(str(uuid.uuid4()))

    for session in sessions:
        with queue_client.get_sender(session=session) as sender:
            for i in range(5):
                message = Message("Test message no. {}".format(i))
                sender.send(message)
    for session in sessions:
        with queue_client.get_receiver(session=session) as receiver:
            receiver.set_session_state("SESSION {}".format(session))

    current_sessions = queue_client.list_sessions(updated_since=start_time)
    assert len(current_sessions) == 5
    assert current_sessions == sessions
コード例 #23
0
def test_qsession_by_servicebus_client_browse_messages_client(live_servicebus_config, partitioned_session_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(partitioned_session_queue)
    session_id = str(uuid.uuid4())
    with queue_client.get_sender(session=session_id) as sender:
        for i in range(5):
            message = Message("Test message no. {}".format(i))
            message.partition_key = "MyPartitionKey"
            sender.send(message)

    with pytest.raises(ValueError):
        messages = queue_client.peek(5)

    messages = queue_client.peek(5, session=session_id)
    assert len(messages) == 5
    assert all(isinstance(m, PeekMessage) for m in messages)
    for message in messages:
        print_message(message)
        with pytest.raises(TypeError):
            message.complete()
コード例 #24
0
def test_qsession_by_servicebus_client_iter_messages_with_retrieve_deferred_receiver_deletemode(live_servicebus_config, partitioned_session_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(partitioned_session_queue)
    deferred_messages = []
    session_id = str(uuid.uuid4())
    messages = [Message("Deferred message no. {}".format(i)) for i in range(10)]
    for m in messages:
        m.partition_key = "MyPartitionKey"
    results = queue_client.send(messages, session=session_id)
    assert all(result[0] for result in results)

    count = 0
    session = queue_client.get_receiver(session=session_id, idle_timeout=5)
    for message in session:
        deferred_messages.append(message.sequence_number)
        print_message(message)
        count += 1
        message.defer()

    assert count == 10
    with queue_client.get_receiver(session=session_id, idle_timeout=5) as session:
        deferred = session.receive_deferred_messages(deferred_messages, mode=ReceiveSettleMode.ReceiveAndDelete)
        assert len(deferred) == 10
        for message in deferred:
            assert isinstance(message, DeferredMessage)
            with pytest.raises(MessageAlreadySettled):
                message.complete()
        with pytest.raises(ServiceBusError):
            deferred = session.receive_deferred_messages(deferred_messages)
コード例 #25
0
def test_queue_message_time_to_live(live_servicebus_config, standard_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)
    import uuid
    queue_client = client.get_queue(standard_queue)

    with queue_client.get_sender() as sender:
        content = str(uuid.uuid4())
        message_id = uuid.uuid4()
        message = Message(content)
        message.time_to_live = timedelta(seconds=30)
        sender.send(message)

    time.sleep(30)
    with queue_client.get_receiver() as receiver:
        messages = receiver.fetch_next(timeout=10)
    assert not messages

    with queue_client.get_deadletter_receiver(
            idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:
        count = 0
        for message in receiver:
            print_message(message)
            message.complete()
            count += 1
        assert count == 1
コード例 #26
0
def test_qsession_by_session_client_conn_str_receive_handler_peeklock(live_servicebus_config, partitioned_session_queue):
    queue_client = QueueClient.from_connection_string(
        live_servicebus_config['conn_str'],
        name=partitioned_session_queue,
        debug=True)
    queue_client.get_properties()

    session_id = str(uuid.uuid4())
    with queue_client.get_sender(session=session_id) as sender:
        for i in range(3):
            message = Message("Handler message no. {}".format(i))
            sender.send(message)

    with pytest.raises(ValueError):
        session = queue_client.get_receiver(idle_timeout=5)

    session = queue_client.get_receiver(session=session_id, idle_timeout=5)
    count = 0
    for message in session:
        print_message(message)
        assert message.session_id == session_id
        count += 1
        message.complete()

    assert count == 3
コード例 #27
0
def test_queue_by_queue_client_conn_str_receive_handler_receiveanddelete(
        live_servicebus_config, standard_queue):
    queue_client = QueueClient.from_connection_string(
        live_servicebus_config['conn_str'], name=standard_queue, debug=False)

    with queue_client.get_sender() as sender:
        for i in range(10):
            message = Message("Handler message no. {}".format(i))
            message.enqueue_sequence_number = i
            sender.send(message)

    messages = []
    receiver = queue_client.get_receiver(
        mode=ReceiveSettleMode.ReceiveAndDelete, idle_timeout=5)
    for message in receiver:
        messages.append(message)
        with pytest.raises(MessageAlreadySettled):
            message.complete()

    assert not receiver.running
    assert len(messages) == 10
    time.sleep(30)

    messages = []
    receiver = queue_client.get_receiver(
        mode=ReceiveSettleMode.ReceiveAndDelete, idle_timeout=5)
    for message in receiver:
        messages.append(message)
    assert len(messages) == 0
コード例 #28
0
def test_pqueue_by_servicebus_client_receive_batch_with_deadletter(live_servicebus_config, partitioned_queue):

    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)

    queue_client = client.get_queue(partitioned_queue)
    with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock, prefetch=10) as receiver:

        with queue_client.get_sender() as sender:
            for i in range(10):
                message = Message("Dead lettered message no. {}".format(i))
                sender.send(message)

        count = 0
        messages = receiver.fetch_next()
        while messages:
            for message in messages:
                print_message(message)
                count += 1
                message.dead_letter(description="Testing")
            messages = receiver.fetch_next()

    assert count == 10

    with queue_client.get_receiver(idle_timeout=5, mode=ReceiveSettleMode.PeekLock) as receiver:
        count = 0
        for message in receiver:
            print_message(message)
            message.complete()
            count += 1
    assert count == 0
コード例 #29
0
def test_queue_message_lock_renew(live_servicebus_config, standard_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=False)
    import uuid
    queue_client = client.get_queue(standard_queue)

    with queue_client.get_sender() as sender:
        content = str(uuid.uuid4())
        message = Message(content)
        sender.send(message)

    with queue_client.get_receiver() as receiver:
        messages = receiver.fetch_next(timeout=10)
        assert len(messages) == 1
        time.sleep(15)
        messages[0].renew_lock()
        time.sleep(15)
        messages[0].renew_lock()
        time.sleep(15)
        assert not messages[0].expired
        messages[0].complete()

    with queue_client.get_receiver() as receiver:
        messages = receiver.fetch_next(timeout=10)
        assert len(messages) == 0
コード例 #30
0
def test_pqueue_message_receive_and_delete(live_servicebus_config, partitioned_queue):
    client = ServiceBusClient(
        service_namespace=live_servicebus_config['hostname'],
        shared_access_key_name=live_servicebus_config['key_name'],
        shared_access_key_value=live_servicebus_config['access_key'],
        debug=True)
    queue_client = client.get_queue(partitioned_queue)
    
    with queue_client.get_sender() as sender:
        message = Message("Receive and delete test")
        sender.send(message)

    with queue_client.get_receiver(mode=ReceiveSettleMode.ReceiveAndDelete) as receiver:
        messages = receiver.fetch_next(timeout=10)
        assert len(messages) == 1
        received = messages[0]
        print_message(received)
        with pytest.raises(MessageAlreadySettled):
            received.complete()
        with pytest.raises(MessageAlreadySettled):
            received.abandon()
        with pytest.raises(MessageAlreadySettled):
            received.defer()
        with pytest.raises(MessageAlreadySettled):
            received.dead_letter()
        with pytest.raises(MessageAlreadySettled):
            received.renew_lock()

    time.sleep(30)

    with queue_client.get_receiver() as receiver:
        messages = receiver.fetch_next(timeout=10)
        for m in messages:
            print_message(m)
        assert len(messages) == 0