4 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
5 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
9 func (s *UnitSuite) TestCache(c *check.C) {
10 arv, err := arvadosclient.MakeArvadosClient()
11 c.Assert(err, check.Equals, nil)
13 cache := DefaultConfig().Cache
15 // Hit the same collection 5 times using the same token. Only
16 // the first req should cause an API call; the next 4 should
18 arv.ApiToken = arvadostest.AdminToken
19 for i := 0; i < 5; i++ {
20 coll, err := cache.Get(arv, arvadostest.FooCollection, false)
21 c.Check(err, check.Equals, nil)
22 c.Assert(coll, check.NotNil)
23 c.Check(coll["portable_data_hash"], check.Equals, arvadostest.FooPdh)
24 c.Check(coll["manifest_text"].(string)[:2], check.Equals, ". ")
26 c.Check(cache.Stats().Requests, check.Equals, uint64(5))
27 c.Check(cache.Stats().CollectionHits, check.Equals, uint64(4))
28 c.Check(cache.Stats().PermissionHits, check.Equals, uint64(4))
29 c.Check(cache.Stats().PDHHits, check.Equals, uint64(4))
30 c.Check(cache.Stats().APICalls, check.Equals, uint64(1))
32 // Hit the same collection 2 more times, this time requesting
33 // it by PDH and using a different token. The first req should
34 // miss the permission cache. Both reqs should hit the
35 // Collection cache and skip the API lookup.
36 arv.ApiToken = arvadostest.ActiveToken
37 for i := 0; i < 2; i++ {
38 coll, err := cache.Get(arv, arvadostest.FooPdh, false)
39 c.Check(err, check.Equals, nil)
40 c.Assert(coll, check.NotNil)
41 c.Check(coll["portable_data_hash"], check.Equals, arvadostest.FooPdh)
42 c.Check(coll["manifest_text"].(string)[:2], check.Equals, ". ")
44 c.Check(cache.Stats().Requests, check.Equals, uint64(5+2))
45 c.Check(cache.Stats().CollectionHits, check.Equals, uint64(4+2))
46 c.Check(cache.Stats().PermissionHits, check.Equals, uint64(4+1))
47 c.Check(cache.Stats().PDHHits, check.Equals, uint64(4+0))
48 c.Check(cache.Stats().APICalls, check.Equals, uint64(1+1))
50 // Alternating between two collections N times should produce
51 // only 2 more API calls.
52 arv.ApiToken = arvadostest.AdminToken
53 for i := 0; i < 20; i++ {
56 target = arvadostest.HelloWorldCollection
58 target = arvadostest.FooBarDirCollection
60 _, err := cache.Get(arv, target, false)
61 c.Check(err, check.Equals, nil)
63 c.Check(cache.Stats().Requests, check.Equals, uint64(5+2+20))
64 c.Check(cache.Stats().CollectionHits, check.Equals, uint64(4+2+18))
65 c.Check(cache.Stats().PermissionHits, check.Equals, uint64(4+1+18))
66 c.Check(cache.Stats().PDHHits, check.Equals, uint64(4+0+18))
67 c.Check(cache.Stats().APICalls, check.Equals, uint64(1+1+2))
70 func (s *UnitSuite) TestCacheForceReloadByPDH(c *check.C) {
71 arv, err := arvadosclient.MakeArvadosClient()
72 c.Assert(err, check.Equals, nil)
74 cache := DefaultConfig().Cache
76 for _, forceReload := range []bool{false, true, false, true} {
77 _, err := cache.Get(arv, arvadostest.FooPdh, forceReload)
78 c.Check(err, check.Equals, nil)
81 c.Check(cache.Stats().Requests, check.Equals, uint64(4))
82 c.Check(cache.Stats().CollectionHits, check.Equals, uint64(3))
83 c.Check(cache.Stats().PermissionHits, check.Equals, uint64(1))
84 c.Check(cache.Stats().PDHHits, check.Equals, uint64(0))
85 c.Check(cache.Stats().APICalls, check.Equals, uint64(3))
88 func (s *UnitSuite) TestCacheForceReloadByUUID(c *check.C) {
89 arv, err := arvadosclient.MakeArvadosClient()
90 c.Assert(err, check.Equals, nil)
92 cache := DefaultConfig().Cache
94 for _, forceReload := range []bool{false, true, false, true} {
95 _, err := cache.Get(arv, arvadostest.FooCollection, forceReload)
96 c.Check(err, check.Equals, nil)
99 c.Check(cache.Stats().Requests, check.Equals, uint64(4))
100 c.Check(cache.Stats().CollectionHits, check.Equals, uint64(1))
101 c.Check(cache.Stats().PermissionHits, check.Equals, uint64(1))
102 c.Check(cache.Stats().PDHHits, check.Equals, uint64(1))
103 c.Check(cache.Stats().APICalls, check.Equals, uint64(3))