2021-04-14 08:50:21 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
2021-11-10 07:08:33 +00:00
|
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2021-04-14 08:50:21 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeadRaw(t *testing.T) {
|
|
|
|
defer os.RemoveAll(t.Name())
|
|
|
|
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2022-03-03 14:19:05 +00:00
|
|
|
splitID := object.NewSplitID()
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
parent := generateObjectWithCID(t, cid)
|
2021-04-14 08:50:21 +00:00
|
|
|
addAttribute(parent, "foo", "bar")
|
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
parentAddr := addressSDK.NewAddress()
|
2021-04-14 08:50:21 +00:00
|
|
|
parentAddr.SetContainerID(cid)
|
2022-05-12 16:37:46 +00:00
|
|
|
|
|
|
|
idParent, _ := parent.ID()
|
|
|
|
parentAddr.SetObjectID(idParent)
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
child := generateObjectWithCID(t, cid)
|
|
|
|
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)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
link := generateObjectWithCID(t, cid)
|
|
|
|
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)
|
|
|
|
|
|
|
|
e := testNewEngineWithShards(s1, s2)
|
|
|
|
defer e.Close()
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
putPrmLeft := new(shard.PutPrm).WithObject(child)
|
|
|
|
putPrmLink := new(shard.PutPrm).WithObject(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
|
|
|
|
headPrm := new(HeadPrm).WithAddress(parentAddr).WithRaw(true)
|
|
|
|
_, err = e.Head(headPrm)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
si, ok := err.(*object.SplitInfoError)
|
2021-04-14 08:50:21 +00:00
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
// 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
|
|
|
})
|
|
|
|
}
|