Exemplo n.º 1
0
    async def test_slurp(self, *, agent, app):
        aref = agent(index=None, active_partitions=None)
        stream = aref.stream.get_active_stream()
        agent._delegate_to_sinks = AsyncMock(name="_delegate_to_sinks")
        agent._reply = AsyncMock(name="_reply")

        def on_delegate(value):
            raise StopAsyncIteration()

        word = Word("word")
        word_req = ReqRepRequest(word, "reply_to", "correlation_id")
        message1 = Mock(name="message1", autospec=Message)
        message2 = Mock(name="message2", autospec=Message)
        event1 = Event(app, None, word_req, {}, message1)
        event2 = Event(app, "key", "bar", {}, message2)
        values = [
            (event1, word),
            (event2, "bar"),
        ]

        class AIT:
            async def __aiter__(self):
                for event, value in values:
                    stream.current_event = event
                    yield value

        it = aiter(AIT())
        await agent._slurp(aref, it)

        agent._reply.assert_called_once_with(None, word, word_req.reply_to,
                                             word_req.correlation_id)
        agent._delegate_to_sinks.coro.assert_has_calls([
            call(word),
            call("bar"),
        ])
Exemplo n.º 2
0
    async def test_slurp(self, *, agent, app):
        aref = agent(index=None, active_partitions=None)
        stream = aref.stream.get_active_stream()
        agent._delegate_to_sinks = AsyncMock(name='_delegate_to_sinks')
        agent._reply = AsyncMock(name='_reply')

        def on_delegate(value):
            raise StopAsyncIteration()

        word = Word('word')
        word_req = ReqRepRequest(word, 'reply_to', 'correlation_id')
        message1 = Mock(name='message1', autospec=Message)
        message2 = Mock(name='message2', autospec=Message)
        event1 = Event(app, None, word_req, message1)
        event2 = Event(app, 'key', 'bar', message2)
        values = [
            (event1, word),
            (event2, 'bar'),
        ]

        class AIT:
            async def __aiter__(self):
                for event, value in values:
                    stream.current_event = event
                    yield value

        it = aiter(AIT())
        await agent._slurp(aref, it)

        agent._reply.assert_called_once_with(None, word, word_req)
        agent._delegate_to_sinks.coro.assert_has_calls([
            call(word),
            call('bar'),
        ])
Exemplo n.º 3
0
 def test_delitem__event(self, *, app, wset):
     e = Event(app,
               key='KK',
               value='VV',
               message=Mock(name='message', autospec=Message))
     with pytest.raises(NotImplementedError):
         del (wset[e])
Exemplo n.º 4
0
 def test_setitem__event(self, *, app, wset):
     e = Event(app,
               key='KK',
               value='VV',
               headers={},
               message=Mock(name='message', autospec=Message))
     with pytest.raises(NotImplementedError):
         wset[e] = 'val'
Exemplo n.º 5
0
def new_event(app, key=None, value=None, *, headers=None, **kwargs):
    return Event(
        app,
        key,
        value,
        headers,
        message(key=key, value=value, headers=headers, **kwargs),
    )
Exemplo n.º 6
0
    async def test_slurp__headers(self, *, agent, app):
        agent.use_reply_headers = True
        aref = agent(index=None, active_partitions=None)
        stream = aref.stream.get_active_stream()
        agent._delegate_to_sinks = AsyncMock(name='_delegate_to_sinks')
        agent._reply = AsyncMock(name='_reply')

        def on_delegate(value):
            raise StopAsyncIteration()

        word = Word('word')
        message1 = Mock(name='message1', autospec=Message)
        headers1 = message1.headers = {
            'Faust-Ag-ReplyTo': 'reply_to',
            'Faust-Ag-CorrelationId': 'correlation_id',
        }
        message2 = Mock(name='message2', autospec=Message)
        headers2 = message2.headers = {}
        event1 = Event(app, None, word, headers1, message1)
        event2 = Event(app, 'key', 'bar', headers2, message2)
        values = [
            (event1, word, True),
            (event1, word, False),
            (event2, 'bar', True),
        ]

        class AIT:
            async def __aiter__(self):
                for event, value, set_cur_event in values:
                    if set_cur_event:
                        stream.current_event = event
                    else:
                        stream.current_event = None
                    yield value

        it = aiter(AIT())
        await agent._slurp(aref, it)

        agent._reply.assert_called_once_with(None, word, 'reply_to',
                                             'correlation_id')
        agent._delegate_to_sinks.coro.assert_has_calls([
            call(word),
            call('bar'),
        ])
Exemplo n.º 7
0
    async def test_slurp__headers(self, *, agent, app):
        agent.use_reply_headers = True
        aref = agent(index=None, active_partitions=None)
        stream = aref.stream.get_active_stream()
        agent._delegate_to_sinks = AsyncMock(name="_delegate_to_sinks")
        agent._reply = AsyncMock(name="_reply")

        def on_delegate(value):
            raise StopAsyncIteration()

        word = Word("word")
        message1 = Mock(name="message1", autospec=Message)
        headers1 = message1.headers = {
            "Faust-Ag-ReplyTo": "reply_to",
            "Faust-Ag-CorrelationId": "correlation_id",
        }
        message2 = Mock(name="message2", autospec=Message)
        headers2 = message2.headers = {}
        event1 = Event(app, None, word, headers1, message1)
        event2 = Event(app, "key", "bar", headers2, message2)
        values = [
            (event1, word, True),
            (event1, word, False),
            (event2, "bar", True),
        ]

        class AIT:
            async def __aiter__(self):
                for event, value, set_cur_event in values:
                    if set_cur_event:
                        stream.current_event = event
                    else:
                        stream.current_event = None
                    yield value

        it = aiter(AIT())
        await agent._slurp(aref, it)

        agent._reply.assert_called_once_with(None, word, "reply_to",
                                             "correlation_id")
        agent._delegate_to_sinks.coro.assert_has_calls([
            call(word),
            call("bar"),
        ])
Exemplo n.º 8
0
def event():
    message = Message(topic='test-topic',
                      key='key',
                      value='value',
                      partition=3,
                      offset=0,
                      checksum=None,
                      timestamp=datetime.datetime.now().timestamp(),
                      timestamp_type=0)
    return Event(app='test-app', key='key', value='value', message=message)
Exemplo n.º 9
0
 def test_delitem__event(self, *, app, wset):
     e = Event(
         app,
         key="KK",
         value="VV",
         headers={},
         message=Mock(name="message", autospec=Message),
     )
     with pytest.raises(NotImplementedError):
         del wset[e]
Exemplo n.º 10
0
 def test_getitem__event(self, *, app, wset):
     e = Event(app,
               key='KK',
               value='VV',
               message=Mock(name='message', autospec=Message))
     ret = wset[e]
     assert isinstance(ret, WindowSet)
     assert ret.key == wset.key
     assert ret.table is wset.table
     assert ret.wrapper is wset.wrapper
     assert ret.event is e
Exemplo n.º 11
0
 def test_getitem__event(self, *, app, wset):
     e = Event(
         app,
         key="KK",
         value="VV",
         headers={},
         message=Mock(name="message", autospec=Message),
     )
     ret = wset[e]
     assert isinstance(ret, WindowSet)
     assert ret.key == wset.key
     assert ret.table is wset.table
     assert ret.wrapper is wset.wrapper
     assert ret.event is e
Exemplo n.º 12
0
def event():
    message = Message(
        topic="test-topic",
        key="key",
        value="value",
        partition=3,
        offset=0,
        checksum=None,
        timestamp=datetime.datetime.now().timestamp(),
        timestamp_type=0,
        headers={},
    )
    return Event(
        app="test-app",
        key="key",
        value="value",
        headers={},
        message=message,
    )