def setUp(self): services = shared.get_services() if services["redis_host"] is not None: cache.ObjectCache.cache_class = cache.RedisCache cache.ObjectCache.cache_params = {'redis_host': 'localhost'} else: _log.warn("KB_REDIS_HOST not defined, using 'null' cache") cache.ObjectCache.cache_class = cache.NullCache cache.ObjectCache.cache_params = {} _log.debug('Fetching old object') self.old_object = ObjectAPI(services=services, ref=self.genome_old) _log.debug('Fetching new object') self.new_object = ObjectAPI(services=services, ref=self.genome_new)
def test_perf_stats(self): g = ObjectAPI(services=shared.get_services(), ref=self.genome_old) for method in ('get_schema', 'get_history', 'get_data', 'get_referrers', 'copy', 'get_provenance'): getattr(self.old_object, method)() assert method in g.stats.get_last().event _log.info('Old genome {:20s} {:.3f} seconds'.format( method, g.stats.get_last().duration)) getattr(self.new_object, method)() assert method in g.stats.get_last().event _log.info('New genome {:20s} {:.3f} seconds'.format( method, g.stats.get_last().duration))
def can_connect(ref=genome): """See if we can get a connection to the workspace and access the given reference. Args: ref (str): Workspace object reference Returns: (bool) if it can be accessed """ try: _ = ObjectAPI(services=get_services(), ref=ref) except Exception as err: _log.exception(err) _log.warn('Connect and fetch object failed: {}'.format(err)) return False return True
class TestCachedObjectAPI(unittest.TestCase): genome_new = "ReferenceGenomeAnnotations/kb|g.166819" genome_old = "OriginalReferenceGenomes/kb|g.166819" def setUp(self): services = shared.get_services() if services["redis_host"] is not None: cache.ObjectCache.cache_class = cache.RedisCache cache.ObjectCache.cache_params = {'redis_host': 'localhost'} else: _log.warn("KB_REDIS_HOST not defined, using 'null' cache") cache.ObjectCache.cache_class = cache.NullCache cache.ObjectCache.cache_params = {} _log.debug('Fetching old object') self.old_object = ObjectAPI(services=services, ref=self.genome_old) _log.debug('Fetching new object') self.new_object = ObjectAPI(services=services, ref=self.genome_new) # def test_extract_paths(self): # data = {'a1': {'b1': {'c1': 1, 'c2': 2}, 'b2': {'d1': 3}}} # paths = ['a1/b1', 'a1/b1/c2', 'a1/b2/d1', 'a1/b1/N', 'N', 'a1/N'] # r = cache.ObjectCache.extract_paths(data, paths) # assert len(r) == 3, 'Wrong number of results, got {:d} expected {:d}'.\ # format(len(r), 3) # msg = 'Invalid result "{r}" for path "{p}"' # assert r['a1/b1'] == {'a1': {'b1': {'c1': 1, 'c2': 2}}}, \ # msg.format(r=r[0], p=paths[0]) # assert r['a1/b1/c2'] == {'a1': {'b1': {'c2': 2}}}, msg.format(r=r[1], # p=paths[1]) # assert r['a1/b2/d1'] == {'a1': {'b2':{'d1': 3}}}, msg.format(r=r[2], # p=paths[2]) def test_get_new_data(self): self.new_object.get_data() event = self.new_object.cache_stats.get_last() _log.info('Get new genome #1: {:.3f}'.format(event.duration)) self.new_object.get_data() event = self.new_object.cache_stats.get_last() _log.info('Get new genome #2: {:.3f}'.format(event.duration)) def test_get_old_data(self): self.old_object.get_data() event = self.old_object.cache_stats.get_last() _log.info('Get old genome #1: {:.3f}'.format(event.duration)) self.old_object.get_data() event = self.old_object.cache_stats.get_last() _log.info('Get old genome #2: {:.3f}'.format(event.duration)) def test_perf_stats(self): g = ObjectAPI(services=shared.get_services(), ref=self.genome_old) for method in ('get_schema', 'get_history', 'get_data', 'get_referrers', 'copy', 'get_provenance'): getattr(self.old_object, method)() assert method in g.stats.get_last().event _log.info('Old genome {:20s} {:.3f} seconds'.format( method, g.stats.get_last().duration)) getattr(self.new_object, method)() assert method in g.stats.get_last().event _log.info('New genome {:20s} {:.3f} seconds'.format( method, g.stats.get_last().duration))
def setup(): shared.setup() global t t = ObjectAPI(shared.services, shared.token, t_ref)