Lines Matching full:cache
19 """Get the cache line with the hosts that match given labels.
23 be more than one, since we use acls in the cache key.
26 @cache_lines: A list of cache lines to look through.
28 @return: A list of the cache lines with the requested labels.
36 raise AssertionError('Mismatch in deps within a cache line')
61 # r1 should cache h2 and use h1; r2 should cach [] and use h2
62 # at the end the cache should contain one stale line, with
76 if not (self.cache.hits == 0 and self.cache.misses == 2):
78 'cache, but both should have inserted into it.')
82 self.cache._cache_backend._cache.values())
120 # behind in the cache. The first job will take one host and cache 3,
121 # the second will take one and cache 2, while the last will take one.
122 # The remaining host in the cache should not be stale.
135 if not (self.cache.hits == 2 and self.cache.misses ==1):
137 'the cache for the others.')
142 self.cache._cache_backend._cache.values())
144 raise AssertionError('Should only be one cache line left.')
168 """Test that the 'no available hosts' condition isn't a cache miss."""
179 if not (self.cache.misses == 1 and self.cache.hits == 2):
181 'while the other 2 should have hit the cache.')
185 key = self.cache.get_key(deps=request.deps, acls=request.acls)
186 if self.cache._cache_backend.get(key) != []:
198 """Test that a stale cache line doesn't satisfy a request."""
201 # will cache the only remaining host after taking one, the second
202 # will also take a host, but not cache anything, while the third
225 # Confirm that even though the third job hit the cache, it wasn't
227 # that it doesn't add it back to the cache.
228 assert(self.cache.misses == 2 and self.cache.hits == 1)
231 self.cache._cache_backend._cache.values())
233 assert(int(self.cache.mean_staleness()) == 100)
245 """Test the cache managers api."""
246 cache = rdb_cache_manager.RDBHostCacheManager()
247 key = cache.get_key(
250 # Cannot set None, it's reserved for cache expiration.
251 self.assertRaises(rdb_utils.RDBException, cache.set_line, *(key, None))
254 cache.set_line(key, [])
255 self.assertTrue(cache.get_line(key) == [])
259 self.assertRaises(rdb_utils.CacheMiss, cache.get_line, *(key,))
261 # Caching a leased host is just a waste of cache space.
265 cache.set_line(key, [host])
267 rdb_utils.CacheMiss, cache.get_line, *(key,))
272 cache.set_line(cache.get_key(host.labels, host.acls), [host])
274 cache.get_line(cache.get_key(host.labels, host.acls)) == [host])
280 cache.set_line(key, [host, different_host])
282 rdb_utils.CacheMiss, cache.get_line, *(key,))
289 cache.set_line(key, [host, different_host])
290 self.assertTrue(set(cache.get_line(key)) == set([host, different_host]))
293 cache.misses = 0
294 cache.hits = 0
295 self.assertTrue(cache.hit_ratio() == 0)
296 cache.hits = 1
297 hit_ratio = cache.hit_ratio()
302 """Test that the dummy cache doesn't save hosts."""
304 # Create 2 jobs and 3 hosts. Both the jobs should not hit the cache,
305 # nor should they cache anything, but both jobs should acquire hosts.
320 if not (self.cache.hits == 0 and self.cache.misses == 2):
322 'cache, but both should have inserted into it.')
335 assert(hasattr(self.cache._cache_backend, '_cache') == False)