frostfs-node/pkg/local_object_storage/shard/range_test.go
Dmitrii Stepanov 8180a0664f
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 6m1s
Build / Build Components (1.21) (pull_request) Successful in 7m37s
Build / Build Components (1.20) (pull_request) Successful in 7m52s
Tests and linters / Staticcheck (pull_request) Successful in 8m56s
Tests and linters / Lint (pull_request) Successful in 9m26s
Tests and linters / Tests (1.21) (pull_request) Successful in 15m5s
Tests and linters / Tests with -race (pull_request) Successful in 15m7s
DCO action / DCO (pull_request) Successful in 1m1s
Tests and linters / Tests (1.20) (pull_request) Successful in 4m1s
[#887] node: Drop badger writecache implementation
Badger implementation isn't tested and works not well,
but requires human resources to maintain.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-12-22 13:00:54 +03:00

127 lines
3.8 KiB
Go

package shard
import (
"bytes"
"context"
"math"
"path/filepath"
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
"github.com/stretchr/testify/require"
)
func TestShard_GetRange(t *testing.T) {
t.Parallel()
t.Run("without write cache", func(t *testing.T) {
t.Parallel()
testShardGetRange(t, false)
})
t.Run("with write cache", func(t *testing.T) {
t.Parallel()
testShardGetRange(t, true)
})
}
func testShardGetRange(t *testing.T, hasWriteCache bool) {
type testCase struct {
hasErr bool
name string
payloadSize int
rng *objectSDK.Range
}
const (
writeCacheMaxSize = 1024
smallObjectSize = 2048
)
newRange := func(off, ln uint64) *objectSDK.Range {
rng := objectSDK.NewRange()
rng.SetOffset(off)
rng.SetLength(ln)
return rng
}
testCases := []testCase{
{false, "small object, good", 1024, newRange(11, 123)},
{true, "small object, out of range, big len", 1024, newRange(10, 1020)},
{true, "small object, out of range, big offset", 1024, newRange(1025, math.MaxUint64-10)},
{false, "big object, good", 2048, newRange(11, 123)},
{true, "big object, out of range, big len", 2048, newRange(100, 2000)},
{true, "big object, out of range, big offset", 2048, newRange(2048, math.MaxUint64-10)},
}
if hasWriteCache {
testCases = append(testCases,
testCase{false, "object in write-cache, good", 100, newRange(2, 18)},
testCase{true, "object in write-cache, out of range, big len", 100, newRange(4, 99)},
testCase{true, "object in write-cache, out of range, big offset", 100, newRange(101, math.MaxUint64-10)})
}
wcOpts := []writecache.Option{
writecache.WithMaxObjectSize(writeCacheMaxSize),
}
sh := newCustomShard(t, hasWriteCache, shardOptions{
wcOpts: wcOpts,
bsOpts: []blobstor.Option{
blobstor.WithStorages([]blobstor.SubStorage{
{
Storage: blobovniczatree.NewBlobovniczaTree(
blobovniczatree.WithLogger(test.NewLogger(t, true)),
blobovniczatree.WithRootPath(filepath.Join(t.TempDir(), "blob", "blobovnicza")),
blobovniczatree.WithBlobovniczaShallowDepth(1),
blobovniczatree.WithBlobovniczaShallowWidth(1)),
Policy: func(_ *objectSDK.Object, data []byte) bool {
return len(data) <= smallObjectSize
},
},
{
Storage: fstree.New(
fstree.WithPath(filepath.Join(t.TempDir(), "blob"))),
},
}),
},
})
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
obj := testutil.GenerateObject()
testutil.AddAttribute(obj, "foo", "bar")
testutil.AddPayload(obj, tc.payloadSize)
addr := object.AddressOf(obj)
payload := bytes.Clone(obj.Payload())
var putPrm PutPrm
putPrm.SetObject(obj)
_, err := sh.Put(context.Background(), putPrm)
require.NoError(t, err)
var rngPrm RngPrm
rngPrm.SetAddress(addr)
rngPrm.SetRange(tc.rng.GetOffset(), tc.rng.GetLength())
res, err := sh.GetRange(context.Background(), rngPrm)
if tc.hasErr {
var target *apistatus.ObjectOutOfRange
require.ErrorAs(t, err, &target)
} else {
require.Equal(t,
payload[tc.rng.GetOffset():tc.rng.GetOffset()+tc.rng.GetLength()],
res.Object().Payload())
}
})
}
}