예제 #1
0
def test_batch_restarted():
    incomplete = make_batch_messages(batch_identifier, [
        {'begin_operation': begin},
        {'mutation_operation': mutation},
    ], publisher=uuid.uuid1().bytes)
    complete = make_batch_messages(batch_identifier, [
        {'begin_operation': begin},
        {'mutation_operation': mutation},
        {'commit_operation': commit},
    ], publisher=uuid.uuid1().bytes)
    messages = itertools.chain(incomplete, complete)

    batches = batched(states.validate(messages))

    # The first batch should be aborted, since it didn't end with a
    # commit/rollback before switching publishers.
    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    assert next(mutations) == mutation
    with pytest.raises(TransactionAborted):
        next(mutations)

    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    assert next(mutations) == mutation
    with pytest.raises(StopIteration):
        next(mutations)
예제 #2
0
def test_batch_no_mutations():
    messages = make_batch_messages(batch_identifier, [
        {'begin_operation': begin},
        {'commit_operation': commit},
    ])
    batches = batched(states.validate(messages))

    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    with pytest.raises(StopIteration):
        next(mutations)
예제 #3
0
def test_batch_iterator_early_exit():
    messages = make_batch_messages(batch_identifier, [
        {'begin_operation': begin},
        {'mutation_operation': mutation},
    ])
    batches = batched(states.validate(messages))

    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    assert next(mutations) == mutation
    with pytest.raises(TransactionAborted):
        next(mutations)
예제 #4
0
def test_batch_iterator_rolled_back():
    messages = make_batch_messages(batch_identifier, [
        {'begin_operation': begin},
        {'mutation_operation': mutation},
        {'rollback_operation': rollback},
    ])
    batches = batched(states.validate(messages))

    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    assert next(mutations) == mutation
    with pytest.raises(TransactionCancelled):
        next(mutations)
예제 #5
0
def test_batch_iterator():
    messages = make_batch_messages(batch_identifier, [
        {'begin_operation': begin},
        {'mutation_operation': mutation},
        {'mutation_operation': mutation},
        {'mutation_operation': mutation},
        {'commit_operation': commit},
    ])
    batches = batched(states.validate(messages))

    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    assert list(mutations) == [mutation] * 3
예제 #6
0
def test_batch_no_mutations():
    messages = make_batch_messages(batch_identifier, [
        {
            'begin_operation': begin
        },
        {
            'commit_operation': commit
        },
    ])
    batches = batched(states.validate(messages))

    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    with pytest.raises(StopIteration):
        next(mutations)
예제 #7
0
def test_batch_iterator_early_exit():
    messages = make_batch_messages(batch_identifier, [
        {
            'begin_operation': begin
        },
        {
            'mutation_operation': mutation
        },
    ])
    batches = batched(states.validate(messages))

    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    assert next(mutations) == mutation
    with pytest.raises(TransactionAborted):
        next(mutations)
예제 #8
0
def test_batch_iterator_rolled_back():
    messages = make_batch_messages(batch_identifier, [
        {
            'begin_operation': begin
        },
        {
            'mutation_operation': mutation
        },
        {
            'rollback_operation': rollback
        },
    ])
    batches = batched(states.validate(messages))

    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    assert next(mutations) == mutation
    with pytest.raises(TransactionCancelled):
        next(mutations)
예제 #9
0
def test_batch_restarted():
    incomplete = make_batch_messages(batch_identifier, [
        {
            'begin_operation': begin
        },
        {
            'mutation_operation': mutation
        },
    ],
                                     publisher=uuid.uuid1().bytes)
    complete = make_batch_messages(batch_identifier, [
        {
            'begin_operation': begin
        },
        {
            'mutation_operation': mutation
        },
        {
            'commit_operation': commit
        },
    ],
                                   publisher=uuid.uuid1().bytes)
    messages = itertools.chain(incomplete, complete)

    batches = batched(states.validate(messages))

    # The first batch should be aborted, since it didn't end with a
    # commit/rollback before switching publishers.
    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    assert next(mutations) == mutation
    with pytest.raises(TransactionAborted):
        next(mutations)

    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    assert next(mutations) == mutation
    with pytest.raises(StopIteration):
        next(mutations)
예제 #10
0
def test_batch_iterator():
    messages = make_batch_messages(batch_identifier, [
        {
            'begin_operation': begin
        },
        {
            'mutation_operation': mutation
        },
        {
            'mutation_operation': mutation
        },
        {
            'mutation_operation': mutation
        },
        {
            'commit_operation': commit
        },
    ])
    batches = batched(states.validate(messages))

    received_batch_identifier, mutations = next(batches)
    assert received_batch_identifier == batch_identifier
    assert list(mutations) == [mutation] * 3