def merge_datafile(line): """ Add all the requests/responses from another data file to the current one """ def set_text_factory(conn): conn.text_factory = str line = line.strip() other_dbpool = adbapi.ConnectionPool("sqlite3", line, check_same_thread=False, cp_openfun=set_text_factory, cp_max=1) try: count = 0 other_cache = RequestCache(cust_dbpool=other_dbpool) yield other_cache.load_ids() for req_d in other_cache.req_it(): count += 1 req = yield req_d r = req.copy() yield r.async_deep_save() print 'Added %d requests' % count finally: other_dbpool.close()
def test_cache_inmem_simple(): cache = RequestCache(3) req = gen_reqs(1)[0] req.reqid = None cache.add(req) assert req.reqid[0] == 'm' g = yield cache.get(req.reqid) assert req == g
def test_cache_inmem_simple(): cache = RequestCache(3) req = gen_reqs(1)[0] req.reqid = None cache.add(req) assert req.reqid[0] == "m" g = yield cache.get(req.reqid) assert req == g
def test_req_ids_unmangled(): reqs = gen_reqs(5) cache = RequestCache(3) reqs[0].unmangled = reqs[4] cache.add(reqs[0]) cache.add(reqs[4]) cache.add(reqs[1]) cache.add(reqs[2]) cache.add(reqs[3]) assert cache.req_ids() == ['4', '3', '2', '1'] assert cache.req_ids(include_unmangled=True) == ['4', '3', '2', '5', '1']
def test_req_ids(): reqs = gen_reqs(5) cache = RequestCache(3) cache.add(reqs[0]) cache.add(reqs[1]) cache.add(reqs[2]) cache.add(reqs[3]) assert cache.req_ids() == ['4', '3', '2', '1']
def test_cache_evict(): reqs = gen_reqs(5) cache = RequestCache(3) cache.add(reqs[0]) cache.add(reqs[1]) cache.add(reqs[2]) cache.add(reqs[3]) assert not cache.check(reqs[0].reqid) assert cache.check(reqs[1].reqid) assert cache.check(reqs[2].reqid) assert cache.check(reqs[3].reqid) # Testing the implementation assert reqs[0].reqid not in cache._cached_reqs assert reqs[1].reqid in cache._cached_reqs assert reqs[2].reqid in cache._cached_reqs assert reqs[3].reqid in cache._cached_reqs
def test_cache_inmem_evict(): reqs = gen_reqs(5) cache = RequestCache(3) reqs[0].reqid = None reqs[1].reqid = None reqs[2].reqid = None reqs[3].reqid = None cache.add(reqs[0]) cache.add(reqs[1]) cache.add(reqs[2]) cache.add(reqs[3]) assert not cache.check(reqs[0].reqid) assert cache.check(reqs[1].reqid) assert cache.check(reqs[2].reqid) assert cache.check(reqs[3].reqid) # Testing the implementation assert reqs[0] in cache.inmem_reqs assert reqs[1] in cache.inmem_reqs assert reqs[2] in cache.inmem_reqs assert reqs[3] in cache.inmem_reqs
def test_cache_inmem_evict(): reqs = gen_reqs(5) cache = RequestCache(3) reqs[0].reqid = None reqs[1].reqid = None reqs[2].reqid = None reqs[3].reqid = None cache.add(reqs[0]) cache.add(reqs[1]) cache.add(reqs[2]) cache.add(reqs[3]) assert not cache.check(reqs[0].reqid) assert cache.check(reqs[1].reqid) assert cache.check(reqs[2].reqid) assert cache.check(reqs[3].reqid) # Testing the implementation assert reqs[0] in RequestCache.inmem_reqs assert reqs[1] in RequestCache.inmem_reqs assert reqs[2] in RequestCache.inmem_reqs assert reqs[3] in RequestCache.inmem_reqs
def test_cache_simple(): reqs = gen_reqs(5) cache = RequestCache(5) cache.add(reqs[0]) g = yield cache.get('1') assert g == reqs[0]
def test_cache_simple(): reqs = gen_reqs(5) cache = RequestCache(5) cache.add(reqs[0]) g = yield cache.get("1") assert g == reqs[0]