def test_publisher_failure(): messages = [] publisher = Publisher(messages.extend) with pytest.raises(NotImplementedError): with publisher.batch(batch_identifier, begin): raise NotImplementedError published_messages = map(reserialize, messages) assert get_operation(get_operation(published_messages[0])) == begin assert get_operation(get_operation(published_messages[1])) == rollback # Ensure it actually generates valid data. assert list(states.validate(published_messages)) assert list(sequences.validate(published_messages)) for i, message in enumerate(published_messages): assert message.header.publisher == publisher.id assert message.header.sequence == i # Write another message to ensure that the publisher can continue to be used. assert len(messages) == 2 publisher.publish() assert len(messages) == 3 assert messages[2].header.sequence == 2
def unwrap_transaction(events): operations = map(lambda event: get_operation(get_operation(event)), events) assert isinstance(operations[0], BeginOperation) assert isinstance(operations[-1], (CommitOperation, RollbackOperation)) assert events[0].batch_operation.batch_identifier == events[ -1].batch_operation.batch_identifier return operations[1:-1]
def assert_same_batch(events): # Protocol buffer messages aren't hashable, so we have to test against the # serialized immutable form. assert len( set([ get_operation(event).batch_identifier.SerializeToString() for event in events ])) == 1
def test_publisher(): messages = [] publisher = Publisher(messages.extend) with publisher.batch(batch_identifier, begin) as publish: publish(mutation) published_messages = map(reserialize, messages) assert get_operation(get_operation(published_messages[0])) == begin assert get_operation(get_operation(published_messages[1])) == mutation assert get_operation(get_operation(published_messages[2])) == commit for i, message in enumerate(published_messages): assert message.header.publisher == publisher.id assert message.header.sequence == i # Ensure it actually generates valid data. assert list(states.validate(published_messages)) assert list(sequences.validate(published_messages))
def unwrap_transaction(events): operations = map(lambda event: get_operation(get_operation(event)), events) assert isinstance(operations[0], BeginOperation) assert isinstance(operations[-1], (CommitOperation, RollbackOperation)) assert events[0].batch_operation.batch_identifier == events[-1].batch_operation.batch_identifier return operations[1:-1]
def assert_same_batch(events): # Protocol buffer messages aren't hashable, so we have to test against the # serialized immutable form. assert len(set([get_operation(event).batch_identifier.SerializeToString() for event in events])) == 1