(t *testing.T)
| 154 | } |
| 155 | |
| 156 | func TestNode_GarbageCollection(t *testing.T) { |
| 157 | n, err := defaultTestNode() |
| 158 | if err != nil { |
| 159 | t.Fatalf("defaultTestNode() failed: %v", err) |
| 160 | } |
| 161 | |
| 162 | // Inject a key that should be GC'd, shouldn't be and those that are |
| 163 | // replicating. |
| 164 | keys := []string{"foo", "bar", "baz"} |
| 165 | for _, k := range keys { |
| 166 | if err := n.data.Set(k, []byte(k), 0, 0); err != nil { |
| 167 | t.Fatalf("Set() failed: %v", err) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // Mock the replicator such that the first key is being replicated. |
| 172 | n.replicator = newMockReplicator(func(key string) bool { |
| 173 | if key == keys[0] { |
| 174 | return true |
| 175 | } |
| 176 | return false |
| 177 | }) |
| 178 | |
| 179 | // Mock the ring such that the second key shouldn't be replicated. |
| 180 | n.ring = &mockRing{ |
| 181 | replicaPeersImpl: func(key string) []string { |
| 182 | if key == keys[1] { |
| 183 | return nil |
| 184 | } |
| 185 | |
| 186 | return []string{n.name} |
| 187 | }, |
| 188 | } |
| 189 | |
| 190 | gc, replicating := n.getGCKeys() |
| 191 | if !replicating { |
| 192 | t.Fatal("getGCKeys() should indicate that a follow up gc is needed") |
| 193 | } |
| 194 | |
| 195 | if len(gc) != 1 || gc[0] != keys[2] { |
| 196 | t.Fatalf("getGCKeys() returned wrong key") |
| 197 | } |
| 198 | } |
nothing calls this directly
no test coverage detected