def test_collection_cache(self, cr): cache = CollectionCache(mock.MagicMock(), mock.MagicMock(), 4) c1 = cache.get("99999999999999999999999999999991+99") c2 = cache.get("99999999999999999999999999999991+99") self.assertIs(c1, c2) self.assertEqual(1, cr.call_count) c3 = cache.get("99999999999999999999999999999992+99") self.assertEqual(2, cr.call_count)
def test_collection_cache_limit(self, cr): cache = CollectionCache(mock.MagicMock(), mock.MagicMock(), 4) cr().manifest_text.return_value = 'x' * 524289 self.assertEqual(0, cache.total) c1 = cache.get("99999999999999999999999999999991+524289") self.assertIn("99999999999999999999999999999991+524289", cache.collections) self.assertNotIn("99999999999999999999999999999992+524289", cache.collections) self.assertEqual((524289*128)*1, cache.total) c2 = cache.get("99999999999999999999999999999992+524289") self.assertIn("99999999999999999999999999999991+524289", cache.collections) self.assertIn("99999999999999999999999999999992+524289", cache.collections) self.assertEqual((524289*128)*2, cache.total) c1 = cache.get("99999999999999999999999999999991+524289") self.assertIn("99999999999999999999999999999991+524289", cache.collections) self.assertIn("99999999999999999999999999999992+524289", cache.collections) self.assertEqual((524289*128)*2, cache.total) c3 = cache.get("99999999999999999999999999999993+524289") self.assertIn("99999999999999999999999999999991+524289", cache.collections) self.assertIn("99999999999999999999999999999992+524289", cache.collections) self.assertEqual((524289*128)*3, cache.total) c4 = cache.get("99999999999999999999999999999994+524289") self.assertIn("99999999999999999999999999999991+524289", cache.collections) self.assertNotIn("99999999999999999999999999999992+524289", cache.collections) self.assertEqual((524289*128)*3, cache.total) c5 = cache.get("99999999999999999999999999999995+524289") self.assertNotIn("99999999999999999999999999999991+524289", cache.collections) self.assertNotIn("99999999999999999999999999999992+524289", cache.collections) self.assertEqual((524289*128)*3, cache.total)