def testRefresh(self): self.tearDown() table = { "localhost": ["127.0.0.1", "10.0.0.1"], "flumotion.com": ["1.1.1.1"] } self.ss = server_selection.ServerSelector(None, DummySocketDNS(table)) self.ss.setup() d = self.ss.addServer("localhost", 80) d.addCallback(lambda _: self.ss.getServers()) d.addCallback(lambda s: setattr(self, "s", s)) d.addCallback(lambda _: self.s.next()) d.addCallback(lambda server: self.failUnless( server.ip in ["127.0.0.1", "10.0.0.1"])) d.addCallback(lambda _: self.s.next()) d.addCallback(lambda server: self.failUnless( server.ip in ["127.0.0.1", "10.0.0.1"])) table = {"localhost": ["127.0.0.1"]} d.addCallback(lambda _: setattr(self.ss._resolver, "socket", DummySocketDNS(table))) d.addCallback(lambda _: self.ss.refreshServers()) d.addCallback(self._testHas, ["127.0.0.1"]) table2 = {"localhost": ["127.0.0.1", "10.0.0.2"]} d.addCallback(lambda x: setattr(self.ss._resolver, "socket", DummySocketDNS(table2))) d.addCallback(lambda _: self.ss.refreshServers()) d.addCallback(self._testHas, ["127.0.0.1", "10.0.0.2"]) return d
def __init__(self, args): props = args['properties'] cacheDir = props.get('cache-dir') cacheSizeInMB = props.get('cache-size') if cacheSizeInMB is not None: cacheSize = cacheSizeInMB * 10**6 # in bytes else: cacheSize = None cleanupEnabled = props.get('cleanup-enabled') cleanupHighWatermark = props.get('cleanup-high-watermark') cleanupLowWatermark = props.get('cleanup-low-watermark') self.virtualHost = props.get('virtual-hostname') self.virtualPort = props.get('virtual-port', DEFAULT_VIRTUAL_PORT) self.virtualPath = props.get('virtual-path', DEFAULT_VIRTUAL_PATH) dnsRefresh = props.get('dns-refresh-period', DEFAULT_DNS_REFRESH) servers = props.get('http-server') compat_servers = props.get('http-server-old') self.stats = cachestats.CacheStatistics() self.cachemgr = cachemanager.CacheManager(self.stats, cacheDir, cacheSize, cleanupEnabled, cleanupHighWatermark, cleanupLowWatermark, self.virtualHost) selector = server_selection.ServerSelector(dnsRefresh) if not (servers or compat_servers): selector.addServer(self.virtualHost, self.virtualPort) else: if compat_servers: # Add the servers specified by name for hostname in compat_servers: if '#' in hostname: hostname, priostr = hostname.split('#', 1) priority = int(priostr) else: priority = DEFAULT_PROXY_PRIORITY if ':' in hostname: hostname, portstr = hostname.split(':', 1) port = int(portstr) else: port = DEFAULT_SERVER_PORT selector.addServer(hostname, port, priority) if servers: # Add the servers specified by compound properties for serverProps in servers: hostname = serverProps.get('hostname') port = serverProps.get('port', DEFAULT_SERVER_PORT) priority = serverProps.get('priority', DEFAULT_PROXY_PRIORITY) selector.addServer(hostname, port, priority) connTimeout = props.get('connection-timeout', DEFAULT_CONN_TIMEOUT) idleTimeout = props.get('idle-timeout', DEFAULT_IDLE_TIMEOUT) client = http_client.StreamRequester(connTimeout, idleTimeout) reqmgr = request_manager.RequestManager(selector, client) cacheTTL = props.get('cache-ttl', DEFAULT_CACHE_TTL) self.strategy = strategy_basic.CachingStrategy(self.cachemgr, reqmgr, cacheTTL) self.resmgr = resource_manager.ResourceManager(self.strategy, self.stats)
def setUp(self): self.ss = server_selection.ServerSelector() self.ss.setup() self.s = None
def _testTimeout(self): self.tearDown() self.ss = server_selection.ServerSelector(None, TimeoutSocketDNS()) self.ss.setup() d = self.ss.addServer("localhost", 80) return d