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)
|
|
|
|
parentAddr.SetObjectID(parent.ID())
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
child := generateObjectWithCID(t, cid)
|
|
|
|
child.SetParent(parent)
|
2021-04-14 08:50:21 +00:00
|
|
|
child.SetParentID(parent.ID())
|
|
|
|
child.SetSplitID(splitID)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
link := generateObjectWithCID(t, cid)
|
|
|
|
link.SetParent(parent)
|
2021-04-14 08:50:21 +00:00
|
|
|
link.SetParentID(parent.ID())
|
2022-03-15 12:11:35 +00:00
|
|
|
link.SetChildren(*child.ID())
|
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())
|
|
|
|
require.Equal(t, child.ID(), si.SplitInfo().LastPart())
|
|
|
|
require.Equal(t, link.ID(), si.SplitInfo().Link())
|
|
|
|
})
|
|
|
|
}
|