当前位置: 首页>>代码示例>>Python>>正文


Python Service.cacheFileName方法代码示例

本文整理汇总了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')
开发者ID:vkuznet,项目名称:WMCore,代码行数:57,代码来源:Service_t.py

示例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()
开发者ID:vkuznet,项目名称:WMCore,代码行数:70,代码来源:Service_t.py


注:本文中的WMCore.Services.Service.Service.cacheFileName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。