555211fe0275e9a42b49625557f8d505999b9c2d
[arvados.git] / services / datamanager / summary / trash_list_test.go
1 package summary
2
3 import (
4         "git.curoverse.com/arvados.git/sdk/go/blockdigest"
5         "git.curoverse.com/arvados.git/services/datamanager/keep"
6         . "gopkg.in/check.v1"
7         "testing"
8 )
9
10 // Gocheck boilerplate
11 func TestTrash(t *testing.T) {
12         TestingT(t)
13 }
14
15 type TrashSuite struct{}
16
17 var _ = Suite(&TrashSuite{})
18
19 func (s *TrashSuite) TestBuildTrashLists(c *C) {
20         var sv0 = keep.ServerAddress{Host: "keep0.example.com", Port: 80}
21         var sv1 = keep.ServerAddress{Host: "keep1.example.com", Port: 80}
22
23         var block0 = blockdigest.MakeTestDigestWithSize(0xdeadbeef)
24         var block1 = blockdigest.MakeTestDigestWithSize(0xfedbeef)
25
26         var keepServerInfo = keep.ReadServers{
27                 KeepServerIndexToAddress: []keep.ServerAddress{sv0, sv1},
28                 BlockToServers: map[blockdigest.DigestWithSize][]keep.BlockServerInfo{
29                         block0: []keep.BlockServerInfo{
30                                 keep.BlockServerInfo{0, 99},
31                                 keep.BlockServerInfo{1, 101}},
32                         block1: []keep.BlockServerInfo{
33                                 keep.BlockServerInfo{0, 99},
34                                 keep.BlockServerInfo{1, 101}}}}
35
36         // only block0 is in delete set
37         var bs = make(BlockSet)
38         bs[block0] = struct{}{}
39
40         // Test trash list where only sv0 is on writable list.
41         c.Check(buildTrashListsInternal(
42                 map[string]struct{}{
43                         sv0.URL(): struct{}{}},
44                 &keepServerInfo,
45                 110,
46                 bs),
47                 DeepEquals,
48                 map[string]keep.TrashList{
49                         "http://keep0.example.com:80": keep.TrashList{keep.TrashRequest{"000000000000000000000000deadbeef", 99}}})
50
51         // Test trash list where both sv0 and sv1 are on writable list.
52         c.Check(buildTrashListsInternal(
53                 map[string]struct{}{
54                         sv0.URL(): struct{}{},
55                         sv1.URL(): struct{}{}},
56                 &keepServerInfo,
57                 110,
58                 bs),
59                 DeepEquals,
60                 map[string]keep.TrashList{
61                         "http://keep0.example.com:80": keep.TrashList{keep.TrashRequest{"000000000000000000000000deadbeef", 99}},
62                         "http://keep1.example.com:80": keep.TrashList{keep.TrashRequest{"000000000000000000000000deadbeef", 101}}})
63
64         // Test trash list where only block on sv0 is expired
65         c.Check(buildTrashListsInternal(
66                 map[string]struct{}{
67                         sv0.URL(): struct{}{},
68                         sv1.URL(): struct{}{}},
69                 &keepServerInfo,
70                 100,
71                 bs),
72                 DeepEquals,
73                 map[string]keep.TrashList{
74                         "http://keep0.example.com:80": keep.TrashList{keep.TrashRequest{"000000000000000000000000deadbeef", 99}}})
75
76 }