mirror of
https://github.com/restic/restic.git
synced 2025-10-09 13:31:26 +00:00
Move Blobcache into dedicated internal package
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
//go:build darwin || freebsd || linux
|
||||
// +build darwin freebsd linux
|
||||
|
||||
package fuse
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/bloblru"
|
||||
"github.com/restic/restic/internal/repository"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
|
||||
@@ -19,48 +21,6 @@ import (
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
func TestCache(t *testing.T) {
|
||||
var id1, id2, id3 restic.ID
|
||||
id1[0] = 1
|
||||
id2[0] = 2
|
||||
id3[0] = 3
|
||||
|
||||
const (
|
||||
kiB = 1 << 10
|
||||
cacheSize = 64*kiB + 3*cacheOverhead
|
||||
)
|
||||
|
||||
c := newBlobCache(cacheSize)
|
||||
|
||||
addAndCheck := func(id restic.ID, exp []byte) {
|
||||
c.add(id, exp)
|
||||
blob, ok := c.get(id)
|
||||
rtest.Assert(t, ok, "blob %v added but not found in cache", id)
|
||||
rtest.Equals(t, &exp[0], &blob[0])
|
||||
rtest.Equals(t, exp, blob)
|
||||
}
|
||||
|
||||
addAndCheck(id1, make([]byte, 32*kiB))
|
||||
addAndCheck(id2, make([]byte, 30*kiB))
|
||||
addAndCheck(id3, make([]byte, 10*kiB))
|
||||
|
||||
_, ok := c.get(id2)
|
||||
rtest.Assert(t, ok, "blob %v not present", id2)
|
||||
_, ok = c.get(id1)
|
||||
rtest.Assert(t, !ok, "blob %v present, but should have been evicted", id1)
|
||||
|
||||
c.add(id1, make([]byte, 1+c.size))
|
||||
_, ok = c.get(id1)
|
||||
rtest.Assert(t, !ok, "blob %v too large but still added to cache")
|
||||
|
||||
c.c.Remove(id1)
|
||||
c.c.Remove(id3)
|
||||
c.c.Remove(id2)
|
||||
|
||||
rtest.Equals(t, cacheSize, c.size)
|
||||
rtest.Equals(t, cacheSize, c.free)
|
||||
}
|
||||
|
||||
func testRead(t testing.TB, f fs.Handle, offset, length int, data []byte) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@@ -156,7 +116,7 @@ func TestFuseFile(t *testing.T) {
|
||||
Size: filesize,
|
||||
Content: content,
|
||||
}
|
||||
root := &Root{repo: repo, blobCache: newBlobCache(blobCacheSize)}
|
||||
root := &Root{repo: repo, blobCache: bloblru.New(blobCacheSize)}
|
||||
|
||||
inode := fs.GenerateDynamicInode(1, "foo")
|
||||
f, err := newFile(context.TODO(), root, inode, node)
|
||||
@@ -191,7 +151,7 @@ func TestFuseDir(t *testing.T) {
|
||||
repo, cleanup := repository.TestRepository(t)
|
||||
defer cleanup()
|
||||
|
||||
root := &Root{repo: repo, blobCache: newBlobCache(blobCacheSize)}
|
||||
root := &Root{repo: repo, blobCache: bloblru.New(blobCacheSize)}
|
||||
|
||||
node := &restic.Node{
|
||||
Mode: 0755,
|
||||
|
Reference in New Issue
Block a user