def __init__(self): self.result = msg.ReadAllResult.Success self.next_position = msg.Position(10, 10) self.position = msg.Position(9, 9) self.is_end_of_stream = False self.last_commit_position = 8 self.events = []
async def test_start_read_phase(): """ A "catchup" subscription starts by iterating the events in the stream until it reaches the most recent event. This is the "Read" phase. """ output = TeeQueue() conversation_id = uuid.uuid4() convo = CatchupAllSubscription( start_from=msg.Position(0, 0), conversation_id=conversation_id ) await convo.start(output) [request] = output.items body = proto.ReadAllEvents() body.ParseFromString(request.payload) assert request.command is msg.TcpCommand.ReadAllEventsForward assert body.commit_position == 0 assert body.prepare_position == 0 assert body.resolve_link_tos is True assert body.require_master is False assert body.max_count == 100
async def test_restart_from_historical(): """ If we ask the conversation to start again while we're reading historical events we should re-send the most recent page request. In this scenario, we start reading the stream at event 10, we receive a page with 2 events, we request the next page starting at 12. When we restart the conversation, we should again request the page starting at 12. """ conversation_id = uuid.uuid4() output = TeeQueue() convo = CatchupAllSubscription(start_from=msg.Position(10, 10), conversation_id=conversation_id) await convo.start(output) await reply_to( convo, (ReadAllEventsResponseBuilder().with_event(event_number=10).with_event( event_number=11).with_next_position(12, 12).build()), output, ) await convo.start(output) [first_page, second_page, second_page_again ] = [read_as(proto.ReadStreamEvents, m) for m in output.items] assert second_page.from_event_number == second_page_again.from_event_number
async def test_read_request(): output = TeeQueue() convo = IterAllEvents(msg.Position(0, 0)) await convo.start(output) request = await output.get() body = proto.ReadAllEvents() body.ParseFromString(request.payload) assert request.command is msg.TcpCommand.ReadAllEventsForward assert body.commit_position == 0 assert body.prepare_position == 0 assert body.resolve_link_tos is True assert body.require_master is False assert body.max_count == 100
async def test_read_all_backward(): output = Queue() convo = ReadAllEvents( from_position=msg.Position(10, 11), direction=msg.StreamDirection.Backward, max_count=20, ) await convo.start(output) request = await output.get() body = proto.ReadAllEvents() body.ParseFromString(request.payload) assert request.command is msg.TcpCommand.ReadAllEventsBackward assert body.commit_position == 10 assert body.prepare_position == 11 assert body.resolve_link_tos is True assert body.require_master is False assert body.max_count == 20
def with_position(self, commit=0, prepare=0): self.position = msg.Position(commit, prepare) return self