Пример #1
0
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
Пример #2
0
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]
Пример #3
0
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
Пример #4
0
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))
Пример #5
0
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]
Пример #6
0
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