Пример #1
0
def test_read_queues_rollback():
    db = StubDb()
    rollback = StubRollback()

    qa = qube.init({'test': set()})
    qb = qube.init({'test': set()})

    qube.apply_op(qa, ('add', 'test', 'abc', 'tx0'))
    qube.apply_op(qb, ('add', 'test', 'abc', 'tx0'))

    qube.apply_op(qa, ('rem', 'test', 'abc', 'tx123'))
    qube.apply_op(qa, ('add', 'test', 'def', 'tx456'))

    qube.apply_op(qb, ('rem', 'test', 'abc', 'tx789'))

    def doraise(a, b):
        raise riak.Conflict('the_vclock',
                            'x/zzz',
                            [StubDbResult(qube.to_json(qa)),
                             StubDbResult(qube.to_json(qb))])

    db.get.side_effect = doraise

    m = yield from FooModel.read(db, rollback, 'zzz')

    assert_that(rollback.queue, called_once_with('bar', 'abc', 'tx789'))
Пример #2
0
def test_read_performs_rollback_with_siblings():
    db = StubDb()
    rollback = StubRollback()
    rollback.txs = ('tx123', 'tx456')

    qa = qube.init({'test': set()})
    qb = qube.init({'test': set()})

    qube.apply_op(qa, ('add', 'test', 'abc', 'tx0'))
    qube.apply_op(qa, ('add', 'test', 'ghi', 'tx456'))

    qube.apply_op(qb, ('add', 'test', 'abc', 'tx0'))
    qube.apply_op(qb, ('add', 'test', 'def', 'tx123'))
    qube.apply_op(qb, ('add', 'test', 'jkl', 'tx789'))

    def doraise(a, b):
        raise riak.Conflict('the_vclock',
                            'x/zzz',
                            [StubDbResult(qube.to_json(qa)),
                             StubDbResult(qube.to_json(qb))])

    db.get.side_effect = doraise

    m = yield from FooModel.read(db, rollback, 'zzz')

    assert_that(m.qube['journal'], has_length(2))
    assert_that(m.qube['data'], has_entry('test', {'abc', 'jkl'}))

    assert_that(db.save, called_once_with('foo_bucket',
                                          'zzz',
                                          has_key('data')))
Пример #3
0
def test_read_merges_siblings():
    db = StubDb()
    rollback = StubRollback()

    qa = qube.init({'test': set()})
    qb = qube.init({'test': set()})

    qube.apply_op(qa, ('add', 'test', 'abc', 'tx0'))
    qube.apply_op(qb, ('add', 'test', 'abc', 'tx0'))

    qube.apply_op(qa, ('add', 'test', 'def', 'tx123'))
    qube.apply_op(qb, ('add', 'test', 'ghi', 'tx456'))

    def doraise(a, b):
        raise riak.Conflict('the_vclock',
                            'x/zzz',
                            [StubDbResult(qube.to_json(qa)),
                             StubDbResult(qube.to_json(qb))])

    db.get.side_effect = doraise

    m = yield from FooModel.read(db, rollback, 'zzz')

    assert_that(m, instance_of(FooModel))
    assert_that(m.qube['data'], has_entry('test', {'abc', 'def', 'ghi'}))
Пример #4
0
def test_threeway_merge():
    qa = qube.init({'name': 'zoidberg', 'number': 5, 'value': 10})
    qube.apply_op(qa, ('change', 'number', (5, 6), 'tx001'))

    qb = qube.from_json(qube.to_json(qa))
    qc = qube.from_json(qube.to_json(qa))

    qube.apply_op(qa, ('change', 'name', ('zoidberg', 'bob'), 'tx002'))
    qube.apply_op(qb, ('change', 'number', (6, 7), 'tx003'))
    qube.apply_op(qc, ('change', 'value', (10, 9), 'tx004'))

    error, watch = track_error()

    m = qube.merge(qa, qb, qc, error=watch)
    assert_that(m, has_entry('sequence', 4))
    assert_that(m, has_entry('data', has_entry('name', 'bob')))
    assert_that(m, has_entry('data', has_entry('number', 7)))
    assert_that(m, has_entry('data', has_entry('value', 9)))

    assert_that(error, has_length(0))
Пример #5
0
def test_step_merge_bside():
    qa = qube.init({'name': 'zoidberg', 'number': 5, 'value': 10})
    qube.apply_op(qa, ('change', 'number', (5, 6), 'tx001'))

    qb = qube.from_json(qube.to_json(qa))

    qube.apply_op(qa, ('change', 'name', ('zoidberg', 'bob'), 'tx002'))
    qube.apply_op(qb, ('change', 'number', (6, 7), 'tx004'))

    qc = qube.from_json(qube.to_json(qb))
    qube.apply_op(qc, ('change', 'value', (10, 9), 'tx004'))

    pprint(qa)
    pprint(qb)
    pprint(qc)

    error, watch = track_error()
    ma = qube.merge(qa, qb, error=watch)

    assert_that(error, has_length(0))
    assert_that(ma, has_entry('sequence', 3))
    assert_that(ma, has_entry('data', has_entry('name', 'bob')))
    assert_that(ma, has_entry('data', has_entry('number', 7)))
    assert_that(ma, has_entry('data', has_entry('value', 10)))

    print('---')
    pprint(ma)
    pprint(qc)

    error, watch = track_error()
    mb = qube.merge(ma, qc, error=watch)
    assert_that(error, has_length(0))
    assert_that(mb, has_entry('sequence', 4))
    assert_that(mb, has_entry('data', has_entry('name', 'bob')))
    assert_that(mb, has_entry('data', has_entry('number', 7)))
    assert_that(mb, has_entry('data', has_entry('value', 9)))
Пример #6
0
def test_read_performs_rollback():
    db = StubDb()
    rollback = StubRollback()
    rollback.txs = ('tx123',)

    qa = qube.init({'test': set()})
    qube.apply_op(qa, ('add', 'test', 'abc', 'tx0'))
    qube.apply_op(qa, ('add', 'test', 'def', 'tx123'))
    qube.apply_op(qa, ('add', 'test', 'ghi', 'tx456'))

    db.get.return_value = StubDbResult(qube.to_json(qa), key='zzz')

    m = yield from FooModel.read(db, rollback, 'zzz')

    assert_that(m.qube['journal'], has_length(2))
    assert_that(m.qube['data'], has_entry('test', {'abc', 'ghi'}))

    assert_that(db.save, called_once_with('foo_bucket',
                                          'zzz',
                                          has_key('data')))
Пример #7
0
Файл: model.py Проект: keis/lera
 def change_room(self, key, txid):
     qube.apply_op(self.qube, ('change', 'room', (self.room, key), txid))
Пример #8
0
Файл: model.py Проект: keis/lera
 def remove_occupant(self, occupant, txid):
     qube.apply_op(self.qube, ('rem', 'occupants', occupant, txid))
Пример #9
0
Файл: model.py Проект: keis/lera
 def add_occupant(self, occupant, txid):
     qube.apply_op(self.qube, ('add', 'occupants', occupant, txid))