コード例 #1
0
    async def ack(self, event):
        payload = proto.PersistentSubscriptionAckEvents()
        payload.subscription_id = self.name
        payload.processed_event_ids.append(event.original_event_id.bytes_le)
        message = OutboundMessage(
            self.conversation_id,
            TcpCommand.PersistentSubscriptionAckEvents,
            payload.SerializeToString(),
        )

        await self.out_queue.put(message)
コード例 #2
0
async def test_when_running_a_persistent_subscription():
    """
    We ought to be able to connect a persistent subscription, and receive
    some events.
    """
    dispatcher = MessageDispatcher()
    out_queue = TeeQueue()
    conversation = ConnectPersistentSubscription("my-sub", "my-stream")
    first_msg = persistent_subscription_confirmed(conversation.conversation_id,
                                                  "my-sub")

    # The subscription confirmed message should result in our having a
    # PersistentSubscription to play with.

    future = await dispatcher.start_conversation(conversation)
    await dispatcher.dispatch(first_msg, out_queue)
    subscription = await asyncio.wait_for(future, 1)

    # A subsequent PersistentSubscriptionStreamEventAppeared message should
    # enqueue the event onto our iterator
    await dispatcher.dispatch(
        subscription_event_appeared(conversation.conversation_id,
                                    NewEvent("event", data={"x": 2})),
        out_queue,
    )

    event = await anext(subscription.events)
    assert event.json()["x"] == 2

    # Acknowledging the event should place an Ack message on the out_queue

    await subscription.ack(event)

    expected_payload = proto.PersistentSubscriptionAckEvents()
    expected_payload.subscription_id = "my-sub"
    expected_payload.processed_event_ids.append(event.event.id.bytes_le)
    expected_message = OutboundMessage(
        conversation.conversation_id,
        TcpCommand.PersistentSubscriptionAckEvents,
        expected_payload.SerializeToString(),
    )

    ack = await out_queue.get()

    assert ack == expected_message
コード例 #3
0
async def test_acknowledge_event():
    output = TeeQueue()

    convo = ConnectPersistentSubscription("my-subscription",
                                          "my-stream",
                                          max_in_flight=57)

    await confirm_subscription(convo, subscription_id=convo.name, queue=output)
    event_id = uuid4()

    subscription = await convo.result
    await subscription.ack(stub_event(event_id))

    ack = await output.get()

    assert ack.command == TcpCommand.PersistentSubscriptionAckEvents
    assert ack.conversation_id == convo.conversation_id

    expected_payload = proto.PersistentSubscriptionAckEvents()
    expected_payload.subscription_id = convo.name
    expected_payload.processed_event_ids.append(event_id.bytes_le)

    assert expected_payload.SerializeToString() == ack.payload