本文整理汇总了Python中WMCore.Services.Service.Service.refreshCache方法的典型用法代码示例。如果您正苦于以下问题:Python Service.refreshCache方法的具体用法?Python Service.refreshCache怎么用?Python Service.refreshCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WMCore.Services.Service.Service
的用法示例。
在下文中一共展示了Service.refreshCache方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testZ_InterruptedConnection
# 需要导入模块: from WMCore.Services.Service import Service [as 别名]
# 或者: from WMCore.Services.Service.Service import refreshCache [as 别名]
def testZ_InterruptedConnection(self):
"""
_InterruptedConnection_
What happens if we shut down the server while
the connection is still active?
Confirm that the cache works as expected
"""
cherrypy.tree.mount(RegularServer(), "/reg1")
cherrypy.engine.start()
FORMAT = '%(message)s'
logging.basicConfig(format=FORMAT)
logger = logging.getLogger('john')
test_dict = {'logger': self.logger,'endpoint':'http://localhost:%i/reg1/regular' % self.port,
'usestalecache': False, "cacheduration": 0.005}
myService = Service(test_dict)
self.assertRaises(HTTPException, myService.getData, 'foo', 'THISISABADURL')
data = myService.refreshCache('foo', '')
dataString = data.read()
self.assertEqual(dataString, "This is silly.")
data.close()
# Now stop the server and confirm that it is down
cherrypy.server.stop()
self.assertRaises(socket.error, myService.forceRefresh, 'foo', '')
# Make sure we can still read from the cache
data = myService.refreshCache('foo', '')
dataString = data.read()
self.assertEqual(dataString, "This is silly.")
data.close()
# Mount a backup server
del cherrypy.tree.apps['/reg1']
cherrypy.tree.mount(BackupServer(), "/reg1")
# Expire cache
time.sleep(30)
self.assertRaises(socket.error, myService.forceRefresh, 'foo', '')
# Restart server
cherrypy.server.start()
# Confirm new server is in place
data = myService.refreshCache('foo', '')
dataString = data.read()
self.assertEqual(dataString, "This is nuts.")
data.close()
cherrypy.engine.exit()
cherrypy.engine.stop()
return
示例2: testUsingStaleCache
# 需要导入模块: from WMCore.Services.Service import Service [as 别名]
# 或者: from WMCore.Services.Service.Service import refreshCache [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')
示例3: testNoCache
# 需要导入模块: from WMCore.Services.Service import Service [as 别名]
# 或者: from WMCore.Services.Service.Service import refreshCache [as 别名]
def testNoCache(self):
"""Cache disabled"""
dict = {'logger': self.logger,
'endpoint': 'https://github.com/dmwm',
'cachepath': None,
}
service = Service(dict)
self.assertEqual(service['cachepath'], dict['cachepath'])
self.assertEqual(service['requests']['cachepath'], dict['cachepath'])
self.assertEqual(service['requests']['req_cache_path'], dict['cachepath'])
out = service.refreshCache('shouldntbeused', '/').read()
self.assertTrue('html' in out)
示例4: RegSvcTrustStore
# 需要导入模块: from WMCore.Services.Service import Service [as 别名]
# 或者: from WMCore.Services.Service.Service import refreshCache [as 别名]
class RegSvcTrustStore(TrustStore):
def __init__(self, config):
TrustStore.__init__(self, config)
defaultdict = {'endpoint': self.store,
'cacheduration': config.duration,
'cachepath': config.path,
'method': 'GET'}
logging.basicConfig(level = logging.DEBUG,
format = '%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt = '%m-%d %H:%M',
filename = defaultdict['cachepath'] + '/regsvc.log',
filemode = 'w')
defaultdict['logger'] = logging.getLogger('OIDRegSvcTrustStore')
self.svc = Service(defaultdict)
def allow(self, trust_root):
data = json.load(self.svc.refreshCache('oid-trust'))
trusted = [x['value'] for x in data['rows']]
return (trust_root in trusted)
示例5: refreshCache
# 需要导入模块: from WMCore.Services.Service import Service [as 别名]
# 或者: from WMCore.Services.Service.Service import refreshCache [as 别名]
def refreshCache(self):
self['inputdata']['timestamp'] = str(datetime.datetime.now())
return Service.refreshCache(self,
'regsvc',
self['inputdata']['url'].__hash__())
示例6: downloadConfig
# 需要导入模块: from WMCore.Services.Service import Service [as 别名]
# 或者: from WMCore.Services.Service.Service import refreshCache [as 别名]
def downloadConfig(self, cacheFile, type = "txt/csv",openf=True, useVerb='GET'):
self.wmcorecache['type'] = type
common.logger.debug("Downloading file [%s] to [%s]." %(str(self.wmcorecache['endpoint']),(str(self.wmcorecache['cachepath'])+"/"+cacheFile)))
servo = Service( self.wmcorecache )
servo['usestalecache'] = True
return servo.refreshCache( cacheFile, cacheFile, openfile=openf, verb=useVerb )
示例7: ServiceTest
# 需要导入模块: from WMCore.Services.Service import Service [as 别名]
# 或者: from WMCore.Services.Service.Service import refreshCache [as 别名]
class ServiceTest(unittest.TestCase):
def setUp(self):
"""
Setup for unit tests
"""
self.testInit = TestInit(__file__)
self.testDir = self.testInit.generateWorkDir()
testname = self.id().split('.')[-1]
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename='service_unittests.log',
filemode='w')
logger_name = 'Service%s' % testname.replace('test', '', 1)
self.logger = logging.getLogger(logger_name)
# self.cache_path = tempfile.mkdtemp()
test_dict = {'logger': self.logger,
'endpoint': 'https://github.com/dmwm'}
self.myService = Service(test_dict)
test_dict['endpoint'] = 'http://cmssw-test.cvs.cern.ch/cgi-bin/cmssw.cgi'
self.myService2 = Service(test_dict)
self.testUrl = 'http://cern.ch'
self.port = 8888
cherrypy.config.update({'server.socket_port': self.port})
def tearDown(self):
self.testInit.delWorkDir()
# There was old code here to see if the test passed and send a message to
# self.logger.info It broke in 2.7, so if needed find a supported way to do it
return
def testIsFile(self):
"""
Test the `isfile` utilitarian function
"""
f = tempfile.NamedTemporaryFile(prefix="testIsFile", delete=True)
self.assertTrue(isfile(f))
f.close()
self.assertTrue(isfile(f))
strio = StringIO.StringIO()
self.assertTrue(isfile(strio))
strio.close()
self.assertTrue(isfile(strio))
self.assertFalse(isfile("/data/srv/alan.txt"))
self.assertFalse(isfile(1))
self.assertFalse(isfile(None))
def testCacheExpired(self):
"""
Test the `cache_expired` utilitarian function. Delta is in hours
"""
# file-like object is always considered expired
fcache = tempfile.NamedTemporaryFile(prefix="testIsFile", delete=True)
self.assertTrue(cache_expired(fcache, delta=0))
self.assertTrue(cache_expired(fcache, delta=100))
fcache.close()
self.assertTrue(cache_expired(fcache, delta=0))
self.assertTrue(cache_expired(fcache, delta=100))
# path to a file that does not exist, always expired
newfile = fcache.name + 'testCacheExpired'
self.assertTrue(cache_expired(newfile, delta=0))
self.assertTrue(cache_expired(newfile, delta=100))
# now create and write something to it
with open(newfile, 'w') as f:
f.write("whatever")
self.assertFalse(cache_expired(newfile, delta=1))
time.sleep(1)
self.assertTrue(cache_expired(newfile, delta=0))
self.assertFalse(cache_expired(newfile, delta=1))
def testClear(self):
"""
Populate the cache, and then check that it's deleted
"""
f = self.myService.refreshCache('testClear', '/WMCore/blob/master/setup.py#L11')
self.assertTrue(os.path.exists(f.name))
f.close()
self.myService.clearCache('testClear')
self.assertFalse(os.path.exists(f.name))
def testClearAndRepopulate(self):
"""
Populate the cache, and then check that it's deleted
"""
f = self.myService.refreshCache('testClear', '/WMCore/blob/master/setup.py#L11')
self.assertTrue(os.path.exists(f.name))
f.close()
#.........这里部分代码省略.........