def test_batch_items_for_check(self): items = [ isolateserver.Item('foo', 12), isolateserver.Item('blow', 0), isolateserver.Item('bizz', 1222), isolateserver.Item('buzz', 1223), ] expected = [ [items[3], items[2], items[0], items[1]], ] batches = list(isolateserver.batch_items_for_check(items)) self.assertEqual(batches, expected)
def send_and_receive(random_pool, dry_run, zip_it, api, progress, size): """Sends a random file and gets it back. Returns (delay, size) """ # Create a file out of the pool. start = time.time() content = random_pool.gen(size) hash_value = hashlib.sha1(content).hexdigest() pack = zlib.compress if zip_it else lambda x: x unpack = zlib.decompress if zip_it else lambda x: x try: if not dry_run: logging.info('contains') item = isolateserver.Item(hash_value, len(content)) item = api.contains([item])[0] logging.info('upload') api.push(item, [pack(content)]) logging.info('download') start = time.time() assert content == unpack(''.join(api.fetch(hash_value))) else: time.sleep(size / 10.) duration = max(0, time.time() - start) except isolateserver.MappingError as e: duration = str(e) if isinstance(duration, float): progress.update_item('', index=1, data=size) else: progress.update_item('', index=1) return (duration, size)
def test_get_missing_items(self): items = [ isolateserver.Item('foo', 12), isolateserver.Item('blow', 0), isolateserver.Item('bizz', 1222), isolateserver.Item('buzz', 1223), ] missing = [ [items[2], items[3]], ] class MockedStorageApi(isolateserver.StorageApi): def contains(self, _items): return missing storage = isolateserver.Storage(MockedStorageApi(), use_zip=False) # 'get_missing_items' is a generator, materialize its result in a list. result = list(storage.get_missing_items(items)) self.assertEqual(missing, result)
def test_get_missing_items(self): items = [ isolateserver.Item('foo', 12), isolateserver.Item('blow', 0), isolateserver.Item('bizz', 1222), isolateserver.Item('buzz', 1223), ] missing = { items[2]: 123, items[3]: 456, } storage_api = MockedStorageApi( {item.digest: push_state for item, push_state in missing.iteritems()}) storage = isolateserver.Storage(storage_api) # 'get_missing_items' is a generator yielding pairs, materialize its # result in a dict. result = dict(storage.get_missing_items(items)) self.assertEqual(missing, result)