2022-03-03 14:16:49 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2022-03-03 14:16:49 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/common"
|
2023-03-21 10:38:44 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/teststore"
|
2023-03-07 13:38:26 +00:00
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
2022-03-03 14:16:49 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExists(t *testing.T) {
|
|
|
|
const smallSizeLimit = 512
|
|
|
|
|
2023-05-05 07:38:59 +00:00
|
|
|
storages, _, largeFileStorage := defaultTestStorages(t.TempDir(), smallSizeLimit)
|
2023-03-21 10:38:44 +00:00
|
|
|
|
|
|
|
b := New(WithStorages(storages))
|
|
|
|
|
2022-06-28 13:42:50 +00:00
|
|
|
require.NoError(t, b.Open(false))
|
2022-03-03 14:16:49 +00:00
|
|
|
require.NoError(t, b.Init())
|
|
|
|
|
|
|
|
objects := []*objectSDK.Object{
|
|
|
|
testObject(smallSizeLimit / 2),
|
|
|
|
testObject(smallSizeLimit + 1),
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range objects {
|
2022-07-06 13:41:35 +00:00
|
|
|
var prm common.PutPrm
|
|
|
|
prm.Object = objects[i]
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := b.Put(context.Background(), prm)
|
2022-03-03 14:16:49 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
var prm common.ExistsPrm
|
2022-03-03 14:16:49 +00:00
|
|
|
for i := range objects {
|
2022-07-06 12:10:21 +00:00
|
|
|
prm.Address = objectCore.AddressOf(objects[i])
|
2022-03-03 14:16:49 +00:00
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := b.Exists(context.Background(), prm)
|
2022-03-03 14:16:49 +00:00
|
|
|
require.NoError(t, err)
|
2022-07-06 12:10:21 +00:00
|
|
|
require.True(t, res.Exists)
|
2022-03-03 14:16:49 +00:00
|
|
|
}
|
|
|
|
|
2022-07-06 12:10:21 +00:00
|
|
|
prm.Address = oidtest.Address()
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := b.Exists(context.Background(), prm)
|
2022-03-03 14:16:49 +00:00
|
|
|
require.NoError(t, err)
|
2022-07-06 12:10:21 +00:00
|
|
|
require.False(t, res.Exists)
|
2022-03-03 14:16:49 +00:00
|
|
|
|
2023-03-21 10:38:44 +00:00
|
|
|
t.Run("corrupt directory", func(t *testing.T) {
|
|
|
|
largeFileStorage.SetOption(teststore.WithExists(func(common.ExistsPrm) (common.ExistsRes, error) {
|
|
|
|
return common.ExistsRes{}, teststore.ErrDiskExploded
|
|
|
|
}))
|
2022-03-03 14:16:49 +00:00
|
|
|
|
|
|
|
// Object exists, first error is logged.
|
2022-07-06 12:10:21 +00:00
|
|
|
prm.Address = objectCore.AddressOf(objects[0])
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := b.Exists(context.Background(), prm)
|
2022-03-03 14:16:49 +00:00
|
|
|
require.NoError(t, err)
|
2022-07-06 12:10:21 +00:00
|
|
|
require.True(t, res.Exists)
|
2022-03-03 14:16:49 +00:00
|
|
|
|
|
|
|
// Object doesn't exist, first error is returned.
|
2022-07-06 12:10:21 +00:00
|
|
|
prm.Address = objectCore.AddressOf(objects[1])
|
2023-03-13 11:37:35 +00:00
|
|
|
_, err = b.Exists(context.Background(), prm)
|
2022-03-03 14:16:49 +00:00
|
|
|
require.Error(t, err)
|
2023-03-21 10:38:44 +00:00
|
|
|
require.ErrorIs(t, err, teststore.ErrDiskExploded)
|
2022-03-03 14:16:49 +00:00
|
|
|
})
|
|
|
|
}
|
2022-07-05 13:47:39 +00:00
|
|
|
|
|
|
|
func testObject(sz uint64) *objectSDK.Object {
|
|
|
|
raw := objectSDK.New()
|
|
|
|
|
|
|
|
raw.SetID(oidtest.ID())
|
|
|
|
raw.SetContainerID(cidtest.ID())
|
|
|
|
|
|
|
|
raw.SetPayload(make([]byte, sz))
|
|
|
|
|
|
|
|
// fit the binary size to the required
|
|
|
|
data, _ := raw.Marshal()
|
|
|
|
if ln := uint64(len(data)); ln > sz {
|
|
|
|
raw.SetPayload(raw.Payload()[:sz-(ln-sz)])
|
|
|
|
}
|
|
|
|
|
|
|
|
return raw
|
|
|
|
}
|