def save_pkg(pkg): ''' Save the data for the given package ''' db = sorbic.db.DB(os.path.join(__opts__['cachedir'], 'sorbic')) key = '{}/{}'.format(pkg['distro'], pkg['name']) db.insert(key, pkg)
def test_compress_changes(self): ''' Compress a db with removed keys ''' entries = 100 w_dir = tempfile.mkdtemp() root = os.path.join(w_dir, 'db_root') db = sorbic.db.DB(root) rands = set() data = {1:1} for num in xrange(entries): key = str(num) db.insert(key, data) for _ in xrange(entries): rands.add(random.randint(0, entries - 1)) for key in rands: db.rm(str(key)) db.compress('', 0) for num in xrange(entries): key = str(num) pull_data = db.get(key) if num in rands: self.assertIsNone(pull_data) else: self.assertEqual(data, pull_data) shutil.rmtree(w_dir)
def _run_test(self, key_hash): w_dir = tempfile.mkdtemp() root = os.path.join(w_dir, 'db_root') db = sorbic.db.DB(root, key_hash=key_hash) data = {1:2} db.insert('foo', data) pull_data = db.get('foo') self.assertEqual(data, pull_data) shutil.rmtree(w_dir)
def _many(self, entries=100000, **kwargs): ''' run a scale db execution with the given db kwargs ''' w_dir = tempfile.mkdtemp() root = os.path.join(w_dir, 'db_root') db = sorbic.db.DB(root, **kwargs) data = {1:1} for num in xrange(entries): key = str(num) db.insert(key, data) for num in xrange(entries): key = str(num) pull_data = db.get(key) self.assertEqual(data, pull_data) shutil.rmtree(w_dir)
def test_compress_no_changes_depth(self): ''' Run a scale db execution with the given db kwargs ''' entries = 100 w_dir = tempfile.mkdtemp() root = os.path.join(w_dir, 'db_root') db = sorbic.db.DB(root) data = {1:1} key = 'foo/bar' for num in xrange(entries): db.insert(key, data) db.compress('foo', 0) for num in xrange(entries): pull_data = db.get(key) self.assertEqual(data, pull_data) shutil.rmtree(w_dir)
def _deep(self, entries=1000, **kwargs): ''' Run a scale db test based on the depth of the id keys ''' w_dir = tempfile.mkdtemp() root = os.path.join(w_dir, 'db_root') db = sorbic.db.DB(root, **kwargs) key = 'foo' ids = [] for num in xrange(entries): e_data = db.insert(key, {1: num}) ids.append(e_data) for num in xrange(entries): pull_data = db.get(key, ids[num]['id'], True) self.assertEqual({1: num}, pull_data['data']) self.assertEqual(ids[num]['rev'], pull_data['meta']['table']['rev']) every = db.get(key, count=entries) for num in xrange(entries): self.assertEqual({1: entries - (num + 1)}, every[num]['data']) shutil.rmtree(w_dir)
def test_compress_changes_depth(self): ''' Run a scale db execution with the given db kwargs ''' entries = 100 w_dir = tempfile.mkdtemp() root = os.path.join(w_dir, 'db_root') db = sorbic.db.DB(root) data = {1:1} key = 'foo/bar' ids = [] rm_ids = set() for num in xrange(entries): ids.append(db.insert(key, data)['id']) for _ in xrange(entries): rm_ids.add(ids[random.randint(0, entries - 1)]) for rm_id in rm_ids: db.rm(key, rm_id) db.compress('foo', 0) for num in xrange(entries): pull_data = db.get(key) self.assertEqual(data, pull_data) shutil.rmtree(w_dir)