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


Python Service.refreshCache方法代码示例

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

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

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

示例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)
开发者ID:geneguvo,项目名称:testrepo,代码行数:24,代码来源:RegSvcTrustStore.py

示例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__())
开发者ID:PerilousApricot,项目名称:CRAB2,代码行数:7,代码来源:Registration.py

示例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 )
开发者ID:PerilousApricot,项目名称:CRAB2,代码行数:8,代码来源:Downloader.py

示例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()
#.........这里部分代码省略.........
开发者ID:vkuznet,项目名称:WMCore,代码行数:103,代码来源:Service_t.py


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