2023-06-22 11:55:30 +00:00
|
|
|
package writecachebadger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"sync/atomic"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachetest"
|
2023-08-23 07:53:42 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
2023-06-22 11:55:30 +00:00
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
|
|
|
"github.com/dgraph-io/badger/v4"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFlush(t *testing.T) {
|
2023-08-09 12:54:08 +00:00
|
|
|
createCacheFn := func(t *testing.T, smallSize uint64, mb *meta.DB, bs writecache.MainStorage, opts ...Option) writecache.Cache {
|
2023-06-22 11:55:30 +00:00
|
|
|
return New(
|
|
|
|
append([]Option{
|
2023-08-23 07:53:42 +00:00
|
|
|
WithLogger(test.NewLogger(t, false)),
|
2023-06-22 11:55:30 +00:00
|
|
|
WithPath(filepath.Join(t.TempDir(), "writecache")),
|
|
|
|
WithMetabase(mb),
|
|
|
|
WithBlobstor(bs),
|
|
|
|
WithGCInterval(1 * time.Second),
|
|
|
|
}, opts...)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
errCountOpt := func() (Option, *atomic.Uint32) {
|
|
|
|
cnt := &atomic.Uint32{}
|
|
|
|
return WithReportErrorFunc(func(string, error) {
|
|
|
|
cnt.Add(1)
|
|
|
|
}), cnt
|
|
|
|
}
|
|
|
|
|
|
|
|
failures := []writecachetest.TestFailureInjector[Option]{
|
|
|
|
{
|
|
|
|
Desc: "db, invalid address",
|
|
|
|
InjectFn: func(t *testing.T, wc writecache.Cache) {
|
|
|
|
c := wc.(*cache)
|
|
|
|
obj := testutil.GenerateObject()
|
|
|
|
data, err := obj.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, c.db.Update(func(tx *badger.Txn) error {
|
|
|
|
return tx.Set([]byte{1, 2, 3}, data)
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Desc: "db, invalid object",
|
|
|
|
InjectFn: func(t *testing.T, wc writecache.Cache) {
|
|
|
|
c := wc.(*cache)
|
|
|
|
require.NoError(t, c.db.Update(func(tx *badger.Txn) error {
|
|
|
|
return tx.Set([]byte(oidtest.Address().EncodeToString()), []byte{1, 2, 3})
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
writecachetest.TestFlush(t, createCacheFn, errCountOpt, failures...)
|
|
|
|
}
|