MCPcopy Create free account
hub / github.com/dadgar/onecache / TestNode_GarbageCollection

Function TestNode_GarbageCollection

onecache/onecache_test.go:156–198  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

154}
155
156func 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}

Callers

nothing calls this directly

Calls 4

defaultTestNodeFunction · 0.85
newMockReplicatorFunction · 0.85
getGCKeysMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected