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(7))
45 c.Check(cache.Stats().CollectionHits, check.Equals, uint64(6))
46 c.Check(cache.Stats().PermissionHits, check.Equals, uint64(5))
47 c.Check(cache.Stats().PDHHits, check.Equals, uint64(4))
48 c.Check(cache.Stats().APICalls, check.Equals, uint64(2))