1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 "git.arvados.org/arvados.git/sdk/go/arvados"
12 check "gopkg.in/check.v1"
15 var _ = check.Suite(&confirmedReplicationSuite{})
17 type confirmedReplicationSuite struct {
18 blockStateMap *BlockStateMap
22 func (s *confirmedReplicationSuite) SetUpTest(c *check.C) {
23 t, _ := time.Parse(time.RFC3339Nano, time.RFC3339Nano)
24 s.mtime = t.UnixNano()
25 s.blockStateMap = NewBlockStateMap()
26 s.blockStateMap.AddReplicas(&KeepMount{KeepMount: arvados.KeepMount{
28 StorageClasses: map[string]bool{"default": true},
29 }}, []arvados.KeepServiceIndexEntry{
30 {SizedDigest: knownBlkid(10), Mtime: s.mtime},
32 s.blockStateMap.AddReplicas(&KeepMount{KeepMount: arvados.KeepMount{
34 StorageClasses: map[string]bool{"default": true},
35 }}, []arvados.KeepServiceIndexEntry{
36 {SizedDigest: knownBlkid(20), Mtime: s.mtime},
40 func (s *confirmedReplicationSuite) TestZeroReplication(c *check.C) {
41 n := s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(404), knownBlkid(409)}, []string{"default"})
42 c.Check(n, check.Equals, 0)
43 n = s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(10), knownBlkid(404)}, []string{"default"})
44 c.Check(n, check.Equals, 0)
45 n = s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(10), knownBlkid(404)}, nil)
46 c.Check(n, check.Equals, 0)
49 func (s *confirmedReplicationSuite) TestBlocksWithDifferentReplication(c *check.C) {
50 n := s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(10), knownBlkid(20)}, []string{"default"})
51 c.Check(n, check.Equals, 1)
54 func (s *confirmedReplicationSuite) TestBlocksInDifferentClasses(c *check.C) {
55 s.blockStateMap.AddReplicas(&KeepMount{KeepMount: arvados.KeepMount{
57 StorageClasses: map[string]bool{"three": true},
58 }}, []arvados.KeepServiceIndexEntry{
59 {SizedDigest: knownBlkid(30), Mtime: s.mtime},
62 n := s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(30)}, []string{"three"})
63 c.Check(n, check.Equals, 3)
64 n = s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(20), knownBlkid(30)}, []string{"default"})
65 c.Check(n, check.Equals, 0) // block 30 has repl 0 @ "default"
66 n = s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(20), knownBlkid(30)}, []string{"three"})
67 c.Check(n, check.Equals, 0) // block 20 has repl 0 @ "three"
68 n = s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(20), knownBlkid(30)}, nil)
69 c.Check(n, check.Equals, 2)
72 func (s *confirmedReplicationSuite) TestBlocksOnMultipleMounts(c *check.C) {
73 s.blockStateMap.AddReplicas(&KeepMount{KeepMount: arvados.KeepMount{
75 StorageClasses: map[string]bool{"default": true, "four": true},
76 }}, []arvados.KeepServiceIndexEntry{
77 {SizedDigest: knownBlkid(40), Mtime: s.mtime},
78 {SizedDigest: knownBlkid(41), Mtime: s.mtime},
80 s.blockStateMap.AddReplicas(&KeepMount{KeepMount: arvados.KeepMount{
82 StorageClasses: map[string]bool{"four": true},
83 }}, []arvados.KeepServiceIndexEntry{
84 {SizedDigest: knownBlkid(40), Mtime: s.mtime},
85 {SizedDigest: knownBlkid(41), Mtime: s.mtime},
87 n := s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(40), knownBlkid(41)}, []string{"default"})
88 c.Check(n, check.Equals, 2)
89 n = s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(40), knownBlkid(41)}, []string{"four"})
90 c.Check(n, check.Equals, 4)
91 n = s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(40), knownBlkid(41)}, []string{"default", "four"})
92 c.Check(n, check.Equals, 2)
93 n = s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(40), knownBlkid(41)}, nil)
94 c.Check(n, check.Equals, 4)
97 func (s *confirmedReplicationSuite) TestConcurrency(c *check.C) {
99 for i := 1000; i < 1256; i++ {
104 n := s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(i), knownBlkid(i)}, []string{"default"})
105 c.Check(n, check.Equals, 0)
110 n := s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(10)}, []string{"default"})
111 c.Check(n, check.Equals, 1)
112 n = s.blockStateMap.GetConfirmedReplication([]arvados.SizedDigest{knownBlkid(20)}, []string{"default"})
113 c.Check(n, check.Equals, 2)