1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
15 import arvados.collection
18 from cwltool.pathmapper import MapperEnt
19 from .mock_discovery import get_rootDesc
21 from arvados_cwl.fsaccess import CollectionCache
23 class TestFsAccess(unittest.TestCase):
24 @mock.patch("arvados.collection.CollectionReader")
25 def test_collection_cache(self, cr):
26 cache = CollectionCache(mock.MagicMock(), mock.MagicMock(), 4)
27 c1 = cache.get("99999999999999999999999999999991+99")
28 c2 = cache.get("99999999999999999999999999999991+99")
30 self.assertEqual(1, cr.call_count)
31 c3 = cache.get("99999999999999999999999999999992+99")
32 self.assertEqual(2, cr.call_count)
34 @mock.patch("arvados.collection.CollectionReader")
35 def test_collection_cache_limit(self, cr):
36 cache = CollectionCache(mock.MagicMock(), mock.MagicMock(), 4)
37 cr().manifest_text.return_value = 'x' * 524289
38 self.assertEqual(0, cache.total)
39 c1 = cache.get("99999999999999999999999999999991+524289")
40 self.assertIn("99999999999999999999999999999991+524289", cache.collections)
41 self.assertNotIn("99999999999999999999999999999992+524289", cache.collections)
42 self.assertEqual((524289*128)*1, cache.total)
44 c2 = cache.get("99999999999999999999999999999992+524289")
45 self.assertIn("99999999999999999999999999999991+524289", cache.collections)
46 self.assertIn("99999999999999999999999999999992+524289", cache.collections)
47 self.assertEqual((524289*128)*2, cache.total)
49 c1 = cache.get("99999999999999999999999999999991+524289")
50 self.assertIn("99999999999999999999999999999991+524289", cache.collections)
51 self.assertIn("99999999999999999999999999999992+524289", cache.collections)
52 self.assertEqual((524289*128)*2, cache.total)
54 c3 = cache.get("99999999999999999999999999999993+524289")
55 self.assertIn("99999999999999999999999999999991+524289", cache.collections)
56 self.assertIn("99999999999999999999999999999992+524289", cache.collections)
57 self.assertEqual((524289*128)*3, cache.total)
59 c4 = cache.get("99999999999999999999999999999994+524289")
60 self.assertIn("99999999999999999999999999999991+524289", cache.collections)
61 self.assertNotIn("99999999999999999999999999999992+524289", cache.collections)
62 self.assertEqual((524289*128)*3, cache.total)
64 c5 = cache.get("99999999999999999999999999999995+524289")
65 self.assertNotIn("99999999999999999999999999999991+524289", cache.collections)
66 self.assertNotIn("99999999999999999999999999999992+524289", cache.collections)
67 self.assertEqual((524289*128)*3, cache.total)
70 @mock.patch("arvados.collection.CollectionReader")
71 def test_collection_cache_limit2(self, cr):
72 cache = CollectionCache(mock.MagicMock(), mock.MagicMock(), 4)
73 cr().manifest_text.return_value = 'x' * 524287
74 self.assertEqual(0, cache.total)
75 c1 = cache.get("99999999999999999999999999999991+524287")
76 self.assertIn("99999999999999999999999999999991+524287", cache.collections)
77 self.assertNotIn("99999999999999999999999999999992+524287", cache.collections)
78 self.assertEqual((524287*128)*1, cache.total)
80 c2 = cache.get("99999999999999999999999999999992+524287")
81 self.assertIn("99999999999999999999999999999991+524287", cache.collections)
82 self.assertIn("99999999999999999999999999999992+524287", cache.collections)
83 self.assertEqual((524287*128)*2, cache.total)
85 c1 = cache.get("99999999999999999999999999999991+524287")
86 self.assertIn("99999999999999999999999999999991+524287", cache.collections)
87 self.assertIn("99999999999999999999999999999992+524287", cache.collections)
88 self.assertEqual((524287*128)*2, cache.total)
90 c3 = cache.get("99999999999999999999999999999993+524287")
91 self.assertIn("99999999999999999999999999999991+524287", cache.collections)
92 self.assertIn("99999999999999999999999999999992+524287", cache.collections)
93 self.assertEqual((524287*128)*3, cache.total)
95 c4 = cache.get("99999999999999999999999999999994+524287")
96 self.assertIn("99999999999999999999999999999991+524287", cache.collections)
97 self.assertIn("99999999999999999999999999999992+524287", cache.collections)
98 self.assertEqual((524287*128)*4, cache.total)
100 c5 = cache.get("99999999999999999999999999999995+524287")
101 self.assertIn("99999999999999999999999999999991+524287", cache.collections)
102 self.assertNotIn("99999999999999999999999999999992+524287", cache.collections)
103 self.assertEqual((524287*128)*4, cache.total)
105 c6 = cache.get("99999999999999999999999999999996+524287")
106 self.assertNotIn("99999999999999999999999999999991+524287", cache.collections)
107 self.assertNotIn("99999999999999999999999999999992+524287", cache.collections)
108 self.assertEqual((524287*128)*4, cache.total)