本文整理汇总了Python中WMCore.Services.Service.Service.cacheFileName方法的典型用法代码示例。如果您正苦于以下问题:Python Service.cacheFileName方法的具体用法?Python Service.cacheFileName怎么用?Python Service.cacheFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WMCore.Services.Service.Service
的用法示例。
在下文中一共展示了Service.cacheFileName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testUsingStaleCache
# 需要导入模块: from WMCore.Services.Service import Service [as 别名]
# 或者: from WMCore.Services.Service.Service import cacheFileName [as 别名]
def testUsingStaleCache(self):
myConfig = {'logger': self.logger,
'endpoint': 'http://cmssw.cvs.cern.ch',
'cacheduration': 0.0005, # cache file lasts 1.8 secs
'timeout': 10,
'usestalecache': True,
# 'cachepath' : self.cache_path,
# 'req_cache_path': '%s/requests' % self.cache_path
}
service = Service(myConfig)
cache = 'stalecachetest'
# Start test from a clear cache
service.clearCache(cache)
cachefile = service.cacheFileName(cache)
self.logger.info('1st call to refreshCache - should fail, there is no cache file')
self.assertRaises(HTTPException, service.refreshCache, cache, '/lies')
cacheddata = 'this data is mouldy'
with open(cachefile, 'w') as f:
f.write(cacheddata)
self.logger.info('2nd call to refreshCache - should pass, data comes from the valid cache')
data = service.refreshCache(cache, '/lies').read()
self.assertEqual(cacheddata, data)
# power nap to avoid letting the cache expire
time.sleep(1)
self.logger.info('3rd call to refreshCache - should pass, cache is still valid')
data = service.refreshCache(cache, '/lies').read()
self.assertEqual(cacheddata, data)
# sleep a while longer so the cache dies out
time.sleep(2)
self.logger.info('4th call to refreshCache - should fail, cache is dead now')
self.assertRaises(HTTPException, service.refreshCache, cache, '/lies')
# touch/renew the file again
cacheddata = 'foo'
with open(cachefile, 'w') as f:
f.write(cacheddata)
# disable usage of stale cache, so doesn't call the endpoint if cache is valid
service['usestalecache'] = False
self.logger.info('5th call to refreshCache - should pass, cache is still valid')
data = service.refreshCache(cache, '/lies').read()
self.assertEqual(cacheddata, data)
# consider the cache dead
service['cacheduration'] = 0
time.sleep(1)
self.logger.info('6th call to refreshCache - should fail, cache is dead now')
self.assertRaises(HTTPException, service.refreshCache, cache, '/lies')
示例2: ServiceTest
# 需要导入模块: from WMCore.Services.Service import Service [as 别名]
# 或者: from WMCore.Services.Service.Service import cacheFileName [as 别名]
#.........这里部分代码省略.........
myConfig = {'logger': self.logger,
'endpoint': 'https://github.com/dmwm',
'cacheduration': None,
'timeout': 10,
}
service = Service(myConfig)
service.getData('%s/socketresettest' % self.testDir, '/WMCore/blob/master/setup.py#L11')
self.assertEqual(service['timeout'], myConfig['timeout'])
def testStaleCache(self):
myConfig = {'logger': self.logger,
'endpoint': 'https://github.com/dmwm',
'usestalecache': True,
}
service = Service(myConfig)
service.getData('%s/socketresettest' % self.testDir, '/WMCore/blob/master/setup.py#L11')
self.assertEqual(service['usestalecache'], myConfig['usestalecache'])
def testUsingStaleCache(self):
myConfig = {'logger': self.logger,
'endpoint': 'http://cmssw.cvs.cern.ch',
'cacheduration': 0.0005, # cache file lasts 1.8 secs
'timeout': 10,
'usestalecache': True,
# 'cachepath' : self.cache_path,
# 'req_cache_path': '%s/requests' % self.cache_path
}
service = Service(myConfig)
cache = 'stalecachetest'
# Start test from a clear cache
service.clearCache(cache)
cachefile = service.cacheFileName(cache)
self.logger.info('1st call to refreshCache - should fail, there is no cache file')
self.assertRaises(HTTPException, service.refreshCache, cache, '/lies')
cacheddata = 'this data is mouldy'
with open(cachefile, 'w') as f:
f.write(cacheddata)
self.logger.info('2nd call to refreshCache - should pass, data comes from the valid cache')
data = service.refreshCache(cache, '/lies').read()
self.assertEqual(cacheddata, data)
# power nap to avoid letting the cache expire
time.sleep(1)
self.logger.info('3rd call to refreshCache - should pass, cache is still valid')
data = service.refreshCache(cache, '/lies').read()
self.assertEqual(cacheddata, data)
# sleep a while longer so the cache dies out
time.sleep(2)
self.logger.info('4th call to refreshCache - should fail, cache is dead now')
self.assertRaises(HTTPException, service.refreshCache, cache, '/lies')
# touch/renew the file again
cacheddata = 'foo'
with open(cachefile, 'w') as f:
f.write(cacheddata)
# disable usage of stale cache, so doesn't call the endpoint if cache is valid
service['usestalecache'] = False
self.logger.info('5th call to refreshCache - should pass, cache is still valid')
data = service.refreshCache(cache, '/lies').read()