Example #1
0
def test_process_work_queue_sends_websocket_messages_to_websocket_handle_message(session):
    message = websocket.Message(socket=mock.sentinel.SOCKET, payload='bar')
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    websocket.handle_message.assert_called_once_with(message)
Example #2
0
def test_process_work_queue_calls_close_after_commit(session):
    message = messages.Message(topic="annotation", payload="bar")
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda _: session)

    assert session.method_calls[-2:] == [call.commit(), call.close()]
Example #3
0
def test_process_work_queue_sends_websocket_messages_to_websocket_handle_message(session):
    message = websocket.Message(socket=mock.sentinel.SOCKET, payload='bar')
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda _: session)

    websocket.handle_message.assert_called_once_with(message, session)
Example #4
0
def test_process_work_queue_calls_close_after_commit(session):
    message = nsq.Message(topic='foo', payload='bar')
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    assert session.method_calls[-2:] == [call.commit(), call.close()]
Example #5
0
def test_process_work_queue_calls_close_after_commit(session):
    message = messages.Message(topic="annotation", payload="bar")
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda _: session)

    assert session.method_calls[-2:] == [mock.call.commit(), mock.call.close()]
Example #6
0
def test_process_work_queue_commits_after_each_message(session):
    message1 = websocket.Message(socket=mock.sentinel.SOCKET, payload='bar')
    message2 = nsq.Message(topic='foo', payload='bar')
    queue = [message1, message2]

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    assert session.commit.call_count == 2
Example #7
0
def test_process_work_queue_commits_after_each_message(session):
    message1 = websocket.Message(socket=mock.sentinel.SOCKET, payload="bar")
    message2 = messages.Message(topic="user", payload="bar")
    queue = [message1, message2]

    streamer.process_work_queue({}, queue, session_factory=lambda _: session)

    assert session.commit.call_count == 2
Example #8
0
def test_process_work_queue_rolls_back_on_unknown_message_type(session):
    message = "something that is not a message"
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda _: session)

    session.commit.assert_not_called()
    session.rollback.assert_called_once_with()
Example #9
0
def test_process_work_queue_rolls_back_on_unknown_message_type(session):
    message = 'something that is not a message'
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    session.commit.assert_not_called()
    session.rollback.assert_called_once_with()
Example #10
0
def test_process_work_queue_sends_nsq_messages_to_nsq_handle_message(session):
    message = nsq.Message(topic='foo', payload='bar')
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    nsq.handle_message.assert_called_once_with(message,
                                               topic_handlers=mock.ANY)
Example #11
0
def test_process_work_queue_sends_nsq_messages_to_nsq_handle_message(session):
    message = nsq.Message(topic='foo', payload='bar')
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    nsq.handle_message.assert_called_once_with(message,
                                               topic_handlers=mock.ANY)
Example #12
0
def test_process_work_queue_calls_close_after_rollback(session):
    message = messages.Message(topic='foo', payload='bar')
    queue = [message]

    messages.handle_message.side_effect = RuntimeError('explosion')

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    assert session.method_calls[-2:] == [call.rollback(), call.close()]
Example #13
0
def test_process_work_queue_calls_close_after_rollback(session):
    message = messages.Message(topic="foo", payload="bar")
    queue = [message]

    messages.handle_message.side_effect = RuntimeError("explosion")

    streamer.process_work_queue({}, queue, session_factory=lambda _: session)

    assert session.method_calls[-2:] == [call.rollback(), call.close()]
Example #14
0
def test_process_work_queue_rolls_back_on_handler_exception(session):
    message = messages.Message(topic="foo", payload="bar")
    queue = [message]

    messages.handle_message.side_effect = RuntimeError("explosion")

    streamer.process_work_queue({}, queue, session_factory=lambda _: session)

    session.commit.assert_not_called()
    session.rollback.assert_called_once_with()
Example #15
0
def test_process_work_queue_sends_realtime_messages_to_messages_handle_message(session):
    message = messages.Message(topic="foo", payload="bar")
    queue = [message]
    settings = {"foo": "bar"}

    streamer.process_work_queue(settings, queue, session_factory=lambda _: session)

    messages.handle_message.assert_called_once_with(
        message, settings, session, topic_handlers=mock.ANY
    )
Example #16
0
def test_process_work_queue_calls_close_after_commit(session):
    message = nsq.Message(topic='foo', payload='bar')
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    assert session.method_calls[-2:] == [
        call.commit(),
        call.close()
    ]
Example #17
0
def test_process_work_queue_rolls_back_on_handler_exception(session):
    message = nsq.Message(topic='foo', payload='bar')
    queue = [message]

    nsq.handle_message.side_effect = RuntimeError('explosion')

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    session.commit.assert_not_called()
    session.rollback.assert_called_once_with()
Example #18
0
def test_process_work_queue_rolls_back_on_handler_exception(session):
    message = messages.Message(topic="foo", payload="bar")
    queue = [message]

    messages.handle_message.side_effect = RuntimeError("explosion")

    streamer.process_work_queue({}, queue, session_factory=lambda _: session)

    session.commit.assert_not_called()
    session.rollback.assert_called_once_with()
Example #19
0
def test_process_work_queue_rolls_back_on_handler_exception(session):
    message = nsq.Message(topic='foo', payload='bar')
    queue = [message]

    nsq.handle_message.side_effect = RuntimeError('explosion')

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    session.commit.assert_not_called()
    session.rollback.assert_called_once_with()
Example #20
0
def test_process_work_queue_calls_close_after_rollback(session):
    message = messages.Message(topic="foo", payload="bar")
    queue = [message]

    messages.handle_message.side_effect = RuntimeError("explosion")

    streamer.process_work_queue({}, queue, session_factory=lambda _: session)

    assert session.method_calls[-2:] == [
        mock.call.rollback(), mock.call.close()
    ]
Example #21
0
def test_process_work_queue_sends_realtime_messages_to_messages_handle_message(session):
    message = messages.Message(topic='foo', payload='bar')
    queue = [message]
    settings = {'foo': 'bar'}

    streamer.process_work_queue(settings, queue, session_factory=lambda _: session)

    messages.handle_message.assert_called_once_with(message,
                                                    settings,
                                                    session,
                                                    topic_handlers=mock.ANY)
Example #22
0
def test_process_work_queue_calls_close_after_rollback(session):
    message = nsq.Message(topic='foo', payload='bar')
    queue = [message]

    nsq.handle_message.side_effect = RuntimeError('explosion')

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    assert session.method_calls[-2:] == [
        call.rollback(),
        call.close()
    ]
Example #23
0
def test_process_work_queue_sends_realtime_messages_to_messages_handle_message(
        session):
    message = messages.Message(topic="foo", payload="bar")
    queue = [message]
    settings = {"foo": "bar"}

    streamer.process_work_queue(settings,
                                queue,
                                session_factory=lambda _: session)

    messages.handle_message.assert_called_once_with(message,
                                                    settings,
                                                    session,
                                                    topic_handlers=Any())
Example #24
0
def test_process_work_queue_uses_appropriate_topic_handlers_for_realtime_messages(
        session):
    message = messages.Message(topic='user', payload='bar')
    queue = [message]

    streamer.process_work_queue({}, queue, session_factory=lambda: session)

    topic_handlers = {
        'annotation': messages.handle_annotation_event,
        'user': messages.handle_user_event,
    }

    messages.handle_message.assert_called_once_with(
        mock.ANY, topic_handlers=topic_handlers)
Example #25
0
def test_process_work_queue_uses_appropriate_topic_handlers_for_realtime_messages(session):
    message = messages.Message(topic='user', payload='bar')
    queue = [message]

    streamer.process_work_queue({},
                                queue,
                                session_factory=lambda: session)

    topic_handlers = {
        'annotation': messages.handle_annotation_event,
        'user': messages.handle_user_event,
    }

    messages.handle_message.assert_called_once_with(mock.ANY,
                                                    topic_handlers=topic_handlers)
Example #26
0
def test_process_work_queue_uses_appropriate_topic_handlers_for_nsq_messages(session):
    message = nsq.Message(topic='foo', payload='bar')
    queue = [message]

    streamer.process_work_queue({'nsq.namespace': 'wibble'},
                                queue,
                                session_factory=lambda: session)

    topic_handlers = {
        'wibble-annotations': nsq.handle_annotation_event,
        'wibble-user': nsq.handle_user_event,
    }

    nsq.handle_message.assert_called_once_with(mock.ANY,
                                               topic_handlers=topic_handlers)
Example #27
0
def test_process_work_queue_uses_appropriate_topic_handlers_for_nsq_messages(
        session):
    message = nsq.Message(topic='foo', payload='bar')
    queue = [message]

    streamer.process_work_queue({'nsq.namespace': 'wibble'},
                                queue,
                                session_factory=lambda: session)

    topic_handlers = {
        'wibble-annotations': nsq.handle_annotation_event,
        'wibble-user': nsq.handle_user_event,
    }

    nsq.handle_message.assert_called_once_with(mock.ANY,
                                               topic_handlers=topic_handlers)
Example #28
0
def test_process_work_queue_uses_appropriate_topic_handlers_for_realtime_messages(
        session):
    message = messages.Message(topic="user", payload="bar")
    queue = [message]
    settings = {"foo": "bar"}

    streamer.process_work_queue(settings,
                                queue,
                                session_factory=lambda _: session)

    topic_handlers = {
        "annotation": messages.handle_annotation_event,
        "user": messages.handle_user_event,
    }

    messages.handle_message.assert_called_once_with(
        mock.ANY, settings, session, topic_handlers=topic_handlers)
Example #29
0
def test_process_work_queue_uses_appropriate_topic_handlers_for_realtime_messages(
    session
):
    message = messages.Message(topic="user", payload="bar")
    queue = [message]
    settings = {"foo": "bar"}

    streamer.process_work_queue(settings, queue, session_factory=lambda _: session)

    topic_handlers = {
        "annotation": messages.handle_annotation_event,
        "user": messages.handle_user_event,
    }

    messages.handle_message.assert_called_once_with(
        mock.ANY, settings, session, topic_handlers=topic_handlers
    )
Example #30
0
 def process_work_queue(queue=None):
     return streamer.process_work_queue(registry, queue or [message])