2022-11-17 06:29:35 +00:00
|
|
|
package blobovniczatree
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2022-11-17 06:29:35 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/internal/blobstortest"
|
2023-08-23 07:53:42 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
2022-11-17 06:29:35 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExistsInvalidStorageID(t *testing.T) {
|
|
|
|
dir := t.TempDir()
|
|
|
|
b := NewBlobovniczaTree(
|
2023-08-23 07:53:42 +00:00
|
|
|
WithLogger(test.NewLogger(t, false)),
|
2022-11-17 06:29:35 +00:00
|
|
|
WithObjectSizeLimit(1024),
|
|
|
|
WithBlobovniczaShallowWidth(2),
|
|
|
|
WithBlobovniczaShallowDepth(2),
|
|
|
|
WithRootPath(dir),
|
|
|
|
WithBlobovniczaSize(1<<20))
|
|
|
|
require.NoError(t, b.Open(false))
|
|
|
|
require.NoError(t, b.Init())
|
|
|
|
t.Cleanup(func() { _ = b.Close() })
|
|
|
|
|
|
|
|
obj := blobstortest.NewObject(1024)
|
|
|
|
addr := object.AddressOf(obj)
|
|
|
|
d, err := obj.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
putRes, err := b.Put(context.Background(), common.PutPrm{Address: addr, RawData: d, DontCompress: true})
|
2022-11-17 06:29:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("valid but wrong storage id", func(t *testing.T) {
|
|
|
|
// "0/X/Y" <-> "1/X/Y"
|
|
|
|
storageID := slice.Copy(putRes.StorageID)
|
|
|
|
if storageID[0] == '0' {
|
|
|
|
storageID[0]++
|
|
|
|
} else {
|
|
|
|
storageID[0]--
|
|
|
|
}
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := b.Exists(context.Background(), common.ExistsPrm{Address: addr, StorageID: storageID})
|
2022-11-17 06:29:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, res.Exists)
|
|
|
|
})
|
|
|
|
|
2023-04-14 13:42:20 +00:00
|
|
|
t.Run("valid id but corrupted file", func(t *testing.T) {
|
|
|
|
relBadFileDir := filepath.Join("9", "0")
|
|
|
|
badFileName := "0"
|
2023-04-14 09:16:14 +00:00
|
|
|
|
|
|
|
// An invalid boltdb file is created so that it returns an error when opened
|
2023-04-14 13:42:20 +00:00
|
|
|
require.NoError(t, os.MkdirAll(filepath.Join(dir, relBadFileDir), os.ModePerm))
|
|
|
|
require.NoError(t, os.WriteFile(filepath.Join(dir, relBadFileDir, badFileName), []byte("not a boltdb file content"), 0777))
|
2022-11-17 06:29:35 +00:00
|
|
|
|
2023-04-14 13:42:20 +00:00
|
|
|
res, err := b.Exists(context.Background(), common.ExistsPrm{Address: addr, StorageID: []byte(filepath.Join(relBadFileDir, badFileName))})
|
2022-11-17 06:29:35 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
require.False(t, res.Exists)
|
|
|
|
})
|
|
|
|
}
|