Skip to content

Commit

Permalink
arc: add test cases for refCount increment
Browse files Browse the repository at this point in the history
  • Loading branch information
toru committed Nov 25, 2024
1 parent ce275a5 commit b9b5560
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,48 @@ func TestBlobThreshold(t *testing.T) {
}
}

func TestBlobRefCountAfterPut(t *testing.T) {
testCases := []struct {
name string
keys [][]byte
value []byte
want int
}{
{
name: "with identical keys",
keys: [][]byte{[]byte("a"), []byte("a"), []byte("a"), []byte("a")},
value: blobValueX(),
want: 1,
},
{
name: "with mixed keys",
keys: [][]byte{[]byte("a"), []byte("b"), []byte("c"), []byte("d")},
value: blobValueX(),
want: 4,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
arc := New()

for _, key := range tc.keys {
arc.Put(key, tc.value)
}

blob := arc.blobs[makeBlobID(tc.value)]

if !bytes.Equal(blob.value, tc.value) {
t.Fatalf("unexpected blob value: got:%q, want:%q", blob.value, tc.value)
}

if blob.refCount != tc.want {
t.Errorf("unexpected refCount: got:%d, want:%d", blob.refCount, tc.want)
}
})
}
}

func TestBlobStoreRelease(t *testing.T) {
store := blobStore{}
value := []byte("pineapple")
Expand Down

0 comments on commit b9b5560

Please sign in to comment.