bfs:实现maxOpenFiles

This commit is contained in:
刘祥超
2024-04-27 17:29:12 +08:00
parent 04007bf8f1
commit 801f5d4525
9 changed files with 318 additions and 54 deletions

View File

@@ -5,10 +5,14 @@ package bfs_test
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/bfs"
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
"github.com/TeaOSLab/EdgeNode/internal/utils/linkedlist"
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"github.com/iwind/TeaGo/Tea"
_ "github.com/iwind/TeaGo/bootstrap"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/types"
"io"
"os"
"testing"
)
@@ -118,3 +122,72 @@ func TestFS_RemoveFile(t *testing.T) {
}
t.Log("exist:", exist)
}
func TestFS_OpenFileWriter_Close(t *testing.T) {
if !testutils.IsSingleTesting() {
return
}
fs, openErr := bfs.OpenFS(Tea.Root+"/data/bfs/test", &bfs.FSOptions{
MaxOpenFiles: 4 << 10,
})
if openErr != nil {
t.Fatal(openErr)
}
defer func() {
_ = fs.Close()
}()
var count = 10
if testutils.IsSingleTesting() {
count = 1000
}
for i := 0; i < count; i++ {
//t.Log("open", i)
writer, err := fs.OpenFileWriter(bfs.Hash(types.String(i)), -1, false)
if err != nil {
t.Fatal(err)
}
_ = writer.Close()
}
t.Log(len(fs.TestBMap()), "block files, pid:", os.Getpid())
var p = func() {
var bNames []string
fs.TestBList().Range(func(item *linkedlist.Item[string]) (goNext bool) {
bNames = append(bNames, item.Value)
return true
})
if len(bNames) != len(fs.TestBMap()) {
t.Fatal("len(bNames)!=len(bMap)")
}
t.Log("["+types.String(len(bNames))+"]", bNames)
}
p()
{
writer, err := fs.OpenFileWriter(bfs.Hash(types.String(10)), -1, false)
if err != nil {
t.Fatal(err)
}
_ = writer.Close()
}
p()
// testing closing
for i := 0; i < 3; i++ {
writer, err := fs.OpenFileWriter(bfs.Hash(types.String(0)), -1, false)
if err != nil {
t.Fatal(err)
}
_ = writer.Close()
}
p()
}