def save(self, db): logger.debug("saving %s/%s %s", self.bucket, self.key, self.vclock) data = qube.to_json(self.qube) yield from db.save(self.bucket, self.key, data, vclock=self.vclock, links=self.links)
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 doraise(a, b): raise riak.Conflict('the_vclock', 'x/zzz', [StubDbResult(qube.to_json(qa)), StubDbResult(qube.to_json(qb))])