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'))
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')))
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'}))
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))
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)))
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')))
def change_room(self, key, txid): qube.apply_op(self.qube, ('change', 'room', (self.room, key), txid))
def remove_occupant(self, occupant, txid): qube.apply_op(self.qube, ('rem', 'occupants', occupant, txid))
def add_occupant(self, occupant, txid): qube.apply_op(self.qube, ('add', 'occupants', occupant, txid))