2021-04-14 08:50:21 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2021-04-14 08:50:21 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeadRaw(t *testing.T) {
|
|
|
|
defer os.RemoveAll(t.Name())
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2022-03-03 14:19:05 +00:00
|
|
|
splitID := object.NewSplitID()
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
parent := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(parent, "foo", "bar")
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var parentAddr oid.Address
|
|
|
|
parentAddr.SetContainer(cnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
|
|
|
|
idParent, _ := parent.ID()
|
2022-05-31 17:00:41 +00:00
|
|
|
parentAddr.SetObject(idParent)
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
child := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
child.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
child.SetParentID(idParent)
|
2021-04-14 08:50:21 +00:00
|
|
|
child.SetSplitID(splitID)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
link := testutil.GenerateObjectWithCID(cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
link.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
link.SetParentID(idParent)
|
|
|
|
|
|
|
|
idChild, _ := child.ID()
|
|
|
|
link.SetChildren(idChild)
|
2021-04-14 08:50:21 +00:00
|
|
|
link.SetSplitID(splitID)
|
|
|
|
|
|
|
|
t.Run("virtual object split in different shards", func(t *testing.T) {
|
|
|
|
s1 := testNewShard(t, 1)
|
|
|
|
s2 := testNewShard(t, 2)
|
|
|
|
|
2023-03-30 11:58:20 +00:00
|
|
|
e := testNewEngine(t).setInitializedShards(t, s1, s2).engine
|
2021-04-14 08:50:21 +00:00
|
|
|
defer e.Close()
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var putPrmLeft shard.PutPrm
|
2022-07-13 12:43:04 +00:00
|
|
|
putPrmLeft.SetObject(child)
|
2022-05-20 18:08:59 +00:00
|
|
|
|
|
|
|
var putPrmLink shard.PutPrm
|
2022-07-13 12:43:04 +00:00
|
|
|
putPrmLink.SetObject(link)
|
2021-04-14 08:50:21 +00:00
|
|
|
|
|
|
|
// put most left object in one shard
|
|
|
|
_, err := s1.Put(putPrmLeft)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// put link object in another shard
|
|
|
|
_, err = s2.Put(putPrmLink)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// head with raw flag should return SplitInfoError
|
2022-05-23 13:12:32 +00:00
|
|
|
var headPrm HeadPrm
|
|
|
|
headPrm.WithAddress(parentAddr)
|
|
|
|
headPrm.WithRaw(true)
|
|
|
|
|
2021-04-14 08:50:21 +00:00
|
|
|
_, err = e.Head(headPrm)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-10-26 12:23:12 +00:00
|
|
|
var si *object.SplitInfoError
|
|
|
|
require.ErrorAs(t, err, &si)
|
2021-04-14 08:50:21 +00:00
|
|
|
|
|
|
|
// SplitInfoError should contain info from both shards
|
|
|
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
2022-05-12 16:37:46 +00:00
|
|
|
|
|
|
|
id1, _ := child.ID()
|
|
|
|
id2, _ := si.SplitInfo().LastPart()
|
|
|
|
require.Equal(t, id1, id2)
|
|
|
|
|
|
|
|
id1, _ = link.ID()
|
|
|
|
id2, _ = si.SplitInfo().Link()
|
|
|
|
require.Equal(t, id1, id2)
|
2021-04-14 08:50:21 +00:00
|
|
|
})
|
|
|
|
}
|