|
4 | 4 | "math" |
5 | 5 | "net/http" |
6 | 6 | "reflect" |
| 7 | + "strconv" |
7 | 8 | "testing" |
8 | 9 |
|
9 | 10 | testutils "github.com/buchgr/bazel-remote/v2/utils" |
@@ -63,33 +64,33 @@ func TestBasics(t *testing.T) { |
63 | 64 |
|
64 | 65 | func TestEviction(t *testing.T) { |
65 | 66 | // Keep track of evictions using the callback |
66 | | - var evictions []int |
67 | | - onEvict := func(key Key, value lruItem) { |
68 | | - evictions = append(evictions, key.(int)) |
| 67 | + var evictions []string |
| 68 | + onEvict := func(key string, value lruItem) { |
| 69 | + evictions = append(evictions, key) |
69 | 70 | } |
70 | 71 |
|
71 | 72 | lru := NewSizedLRU(10*BlockSize, onEvict, 0) |
72 | 73 |
|
73 | 74 | expectedSizesNumItems := []struct { |
74 | 75 | expBlocks int64 |
75 | 76 | expNumItems int |
76 | | - expEvicted []int |
| 77 | + expEvicted []string |
77 | 78 | }{ |
78 | | - {0, 1, []int{}}, // 0 |
79 | | - {1, 2, []int{}}, // 0, 1 |
80 | | - {3, 3, []int{}}, // 0, 1, 2 |
81 | | - {6, 4, []int{}}, // 0, 1, 2, 3 |
82 | | - {10, 5, []int{}}, // 0, 1, 2, 3, 4 |
83 | | - {9, 2, []int{0, 1, 2, 3}}, // 4, 5 |
84 | | - {6, 1, []int{4, 5}}, // 6 |
85 | | - {7, 1, []int{6}}, // 7 |
| 79 | + {0, 1, []string{}}, // 0 |
| 80 | + {1, 2, []string{}}, // 0, 1 |
| 81 | + {3, 3, []string{}}, // 0, 1, 2 |
| 82 | + {6, 4, []string{}}, // 0, 1, 2, 3 |
| 83 | + {10, 5, []string{}}, // 0, 1, 2, 3, 4 |
| 84 | + {9, 2, []string{"0", "1", "2", "3"}}, // 4, 5 |
| 85 | + {6, 1, []string{"4", "5"}}, // 6 |
| 86 | + {7, 1, []string{"6"}}, // 7 |
86 | 87 | } |
87 | 88 |
|
88 | | - var expectedEvictions []int |
| 89 | + var expectedEvictions []string |
89 | 90 |
|
90 | 91 | for i, thisExpected := range expectedSizesNumItems { |
91 | 92 | item := lruItem{size: int64(i) * BlockSize, sizeOnDisk: int64(i) * BlockSize} |
92 | | - ok := lru.Add(i, item) |
| 93 | + ok := lru.Add(strconv.Itoa(i), item) |
93 | 94 | if !ok { |
94 | 95 | t.Fatalf("Add: failed adding %d", i) |
95 | 96 | } |
@@ -163,13 +164,13 @@ func TestReserveAtCapacity(t *testing.T) { |
163 | 164 |
|
164 | 165 | func TestReserveAtEvictionQueueLimit(t *testing.T) { |
165 | 166 |
|
166 | | - lru := NewSizedLRU(BlockSize*2, func(Key, lruItem) {}, 0) |
| 167 | + lru := NewSizedLRU(BlockSize*2, func(string, lruItem) {}, 0) |
167 | 168 | lru.maxSizeHardLimit = BlockSize * 3 |
168 | 169 |
|
169 | | - blockSize1Key := 7777 |
| 170 | + blockSize1Key := "7777" |
170 | 171 | blockSize1Item := lruItem{size: BlockSize * 1, sizeOnDisk: BlockSize * 1} |
171 | 172 |
|
172 | | - blockSize2Key := 8888 |
| 173 | + blockSize2Key := "8888" |
173 | 174 | blockSize2Item := lruItem{size: BlockSize * 2, sizeOnDisk: BlockSize * 2} |
174 | 175 |
|
175 | 176 | // Add large item. |
|
0 commit comments